//------------------------------------
//	HOMEPAGE.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.3.2
//				global.js
//				cufon.js
//				gazz.js
//------------------------------------

//CUFON
Cufon.replace('#twitter p.loading');
Cufon.replace('#twitter_update_list li');
Cufon.replace('#news dd a', {
	hover: true
});


//BEGIN jQuery
$(function(){

	
	//TWITTER
	
	totalT = 0;
	
	$("#twitter").getTwitter({
		userName: "hardybrake",
		numTweets: 3,
		loaded: function(){
			
			totalT = $('#twitter_update_list li').size();
			
			$('#twitter_update_list li:first').clone().appendTo('#twitter_update_list');
			
			//Apply cufon
			Cufon.refresh('#twitter_update_list li');
			
			//Do the animating!
			$('#twitter p.loading').animate({opacity:0},400,'easeInOutExpo',function(){
				$(this).remove();
				$('#twitter_update_list').animate({top:0},400,'easeInOutExpo',function(){
					tweetCycle();
				});
			});
		}
	});
	
	currentY = 0;
	currentT = 1;
	
	var tweetTimer = {};
	
	$('#twitter').hover(function(){
		$.clearTimer(tweetTimer);
	},function(){
		tweetCycle();
	});
	
	function tweetCycle(){
		tweetTimer = $.timer(3800,function(){
			$.clearTimer(tweetTimer);
			if(currentT==totalT+1){
				$('#twitter_update_list').css({top:0});
				currentY = 0;
				currentT = 1;
			}
			currentY = currentY - 38;
			$('#twitter_update_list').animate({top:currentY},400,'easeInOutExpo');
			currentT = currentT + 1;
			tweetCycle();
		});
	}
	
	
	//PRELOAD IMAGES
	
	/*$('img.preload').each(function(){
		imgLoad($(this));
	});
	
	function imgLoad(img){
		url = $(img).attr('href').substring(1);
		alert(url);
	}*/
	
//END jQuery
});
