/* sIFR  */

var meta = { src: 'http://cog.nitiondesign.com/wp-content/themes/nition/js/sifr/meta-bookroman.swf' };

sIFR.activate(meta);
/*
sIFR.replace(meta, {
  selector: 'h2',
  wmode: 'transparent',
  css: '.sIFR-root {color: #FF7517;}'
});

sIFR.replace(meta, {
  selector: 'h3',
  wmode: 'transparent',
  css: [ 
	'.sIFR-root {color: #005985;}',
	'a {color:#282828;}',
	'a:hover { color: #000;text-decoration: underline; }'
	]
});

sIFR.replace(meta, {
  selector: 'h4',
  wmode: 'transparent',
  css: '.sIFR-root {color: #ffffff;}'
});

sIFR.replace(meta, {
  selector: '.twitted li',
  wmode: 'transparent',
  css: 
	[
	'.sIFR-root {color: #000000;text-align:center;}',
	'a {text-decoration: none; color:#282828;}',
	'a:hover { color: #000;text-decoration: underline; }'
	]
});
*/
/* Global Navigation Cycle  */
$(document).ready(function(){
$("#main-nav li a span").css({ opacity: "0.0", display: "block" });
$("#main-nav li a span").hover(function(){$(this).fadeTo(100, 1.0);}, function(){$(this).fadeTo(300, 0.0);} );
$("#main-nav li a.current span").hide();
});

$(document).ready(function() {
	$("#tweet").getTwitter({
		userName: "nition",
		numTweets: 1,
		loaderText: "Loading tweets...",
		slideIn: false,
		slideDuration: 750,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: false,
		showTimestamp: true
	});
});

$(document).ready(function(){
    $('div#lastfm').lastFM({
        username: 'jcalabro',
        apikey: '731ca598bdab1c1161a26d3ebf33c5d2',
        number: 1,
        artSize: 'medium',
        noart: 'http://cog.nitiondesign.com/wp-content/themes/nition/images/noartwork.gif',
        onComplete: function(){
            //Done
        }
    });
});

/* RollOver */
$(document).ready(function(){
/* main nav drop down */
	var timers = new Array();
	
	$('#main-nav ul li.dropdown').each(function (i) {
		$(this).hover(
			function() {
				clearTimeout(timers[i*2]);
				clearTimeout(timers[i*2+1]);
				var elem = $(this);
				elem.addClass('current');
				if (elem.find('.container').is(':visible')) return;
				timers[i*2] = setTimeout(function() {
					elem.find('.container').show();
				}, 0);
			},
			function() {
				clearTimeout(timers[i*2]);
				clearTimeout(timers[i*2+1]);
				var elem = $(this);
				elem.removeClass('current');
				if (elem.find('.container').is(':hidden')) return;
				timers[i*2+1] = setTimeout(function() {
					elem.find('.container').fadeOut("def");
				}, 200);
			}
		);
	})
});


/* THEME SWITCHER - CREDIT ANIDEA */
function hideDrawer() {
	$("#theme-drawer #theme-container").slideToggle("normal", function () {
		if ($("#theme-drawer #theme-container").is(':visible')) {
			$("#join-us").css("margin-bottom", "150px");
		} else {
		$("#join-us").css("margin-bottom", "20px");
		}
	});
}

/******** easing call ********/
jQuery.easing.def = 'easeOutQuint';

var currentPosition = 0;
var slowScrollSpeed = 0;
var timer;
var totalWidth = 2000;
var outerWidth = 1000;
var leftLimit = outerWidth - totalWidth;

function updateLimits()
{				
	totalWidth = document.getElementById("theme-carousel").clientWidth;
	outerWidth = document.getElementById("theme-housing").clientWidth;
	
	leftLimit = outerWidth - totalWidth + 160;
}


function themeScroll(number)
{
	updateLimits();

	currentPosition += number;

	// Clamp
	if(currentPosition > 0)
	{
		currentPosition = 0;
	}
	
	//alert("currentPosition: " + currentPosition + ", leftLimit: " + leftLimit + ", totalWidth: " + totalWidth + ", outerWidth: " + outerWidth);
	
	$("#theme-carousel").animate({left: currentPosition + "pt"}, 500)
	
	updateButtons();
	
	return;
}

function scrollPrevious()
{
	themeScroll(133);
	
	return;
}


function scrollNext()
{
	themeScroll(-133);
	
	return;
}


function setSlowScroll(amount)
{
	//updateLimits();

	//slowScrollSpeed = amount;
}


function slowScroll()
{
	if(slowScrollSpeed)
	{
		currentPosition += slowScrollSpeed;

		document.getElementById("theme-carousel").style.left = currentPosition + "pt";
		
		updateButtons();
	}
}


function updateButtons()
{				
	if(currentPosition < 0)
	{
		document.getElementById("theme-previous").style.visibility = "visible";
	}
	else
	{
		document.getElementById("theme-previous").style.visibility = "hidden";
	}
						
	if(currentPosition > leftLimit)
	{
		document.getElementById("theme-next").style.visibility = "visible";
	}
	else
	{
		document.getElementById("theme-next").style.visibility = "hidden";
	}
	
	return;
}


window.onresize = function()
{
	updateLimits();
	updateButtons();
}

$(document).ready(function () {

    $('#theme-drawer #theme-container').hide();
    $('.new-window').attr({ target: '_blank' }); 
    $("a.theme-thumb").click(function () {
        var themename = $(this).attr("rel");
        $("#new-theme").attr({ href: "http://cog.nitiondesign.com/wp-content/themes/" + themename + "/css/style.css" });
        hideDrawer();
        $.cookie('user_theme', themename, { path: '/', expires: 10 });
        return false;
    });
    tooltip();

    $(".theme-toggle").click(function () {
        hideDrawer();
    });
});


$(document).ready(function () {
    //$(".join-convo").hover(function () {
        $(".join-convo").css({ opacity: "0.0", display: "none" });
 //})

});
