//------------------------------------
//	HOME.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.4.2
//				sec1.js
//------------------------------------

$(function(){
//BEGIN jQuery

	// SET SOME INITIALS

	mooseBan = false;
	c = 0;


	// CLICK A NAV ITEM

	$('#pp_nav li a').click(function(){
		if(mooseBan == false && !$(this).hasClass('on')){
			mooseBan = true;
			$(this).addClass('on').theHop('li').removeClass('on');
			slideTo($(this).attr('href'));
			
			var c = $(this).parent().prevAll().length;
		}
		return false;
	});


	//GENERIC SLIDE FUNCTION
	
	function slideTo(id){
		newX = '-' + $(id).index() * 930 + 'px';
		
		sheild('out',function(){
			$('#pp_slider').animate({left:newX},1000,'easeInOutExpo',function(){
				$(id).kidnapClass('active');
				sheild('in',function(){
					mooseBan = false;
				});
			});
		});
	}


	// BOUNCY SHEILD STUFF
	
	function sheild(act,cBack){
		
		s = 550;
		e = 'easeInOutBack';
		if ($.browser.msie && $.browser.version <= 6 ){
			animOptsIn = {top: 4};
			animOptsOut = {top: 30};
		}else{
			animOptsIn = {right: 150, top: 4, width: 202};
			animOptsOut = {right: 180, top: 50, width: 140};
		}

		if(act == 'in'){
			$('#pp_slider .active div.sheild').animate(animOptsIn,s,e,function(){
				if(cBack) cBack.call();
			});
		}else if(act == 'out'){
			$('#pp_slider .active div.sheild').animate(animOptsOut,s,e,function(){
				if(cBack) cBack.call();
			});
		}
	}
	
	sheild('in');


	// AUTOMATE IT!
	
	$('#promo_panel').hover(function(){
		$.clearTimer(promoTimer);
	},function(){
		autoMagical();
	});
	
	var promoTimer = {};
	
	function autoMagical(){
		promoTimer = $.timer(6000,function(){
			$.clearTimer(promoTimer);

			c++;
			if(c>2) c=0;

			$('#pp_nav li:eq('+ c +') a').click();
			autoMagical();
		});
	}
	
	autoMagical();


	//TWITTER
	
	cT = 0;
	tT = 8;
	pT = tT - 1;
	tTime = 0;
	
	$("#twitter").getTwitter({
		userName: "sec1ltd",
		numTweets: tT,
		loaded: function(){
			$('#twitter p.loading').fadeOut(function(){
				tweetCycle();
			});
		}
	});
	
	// AUTOMATE IT!
	
	$("#twitter").hover(function(){
		$.clearTimer(tweetTimer);
	},function(){
		tweetCycle();
	});
	
	var tweetTimer = {};
	
	function tweetCycle(){
		tweetTimer = $.timer(tTime,function(){
			$.clearTimer(tweetTimer);
			$('#twitter_update_list li:eq('+ cT +')')
				.css({top:29})
				.animate({top:0},800,'easeInOutExpo');
			$('#twitter_update_list li:eq('+ pT +')')
				.animate({top:-29},800,'easeInOutExpo');
				
			cT++;
			if(cT == tT) cT = 0;
			
			pT++;
			if(pT == tT) pT = 0;
			
			tTime = 6000;
			
			tweetCycle();
		});
	}


//END jQuery
});
