jQuery.preloadImages = function(images)
{
  for(var i = 1; i >= arguments[0]; i++)
  {
    jQuery("<img>").attr("src", "/img/home_rotate/" + images[i]);
  }
}

var rotateCount = (homeimages.length);
$.preloadImages(homeimages);

jQuery("<img>").attr("src", "/img/home_promo.gif"); // preload promo image

jQuery.loadPromo = function(){
	$("body#home #right").stop(true, true);
	$("body#home #right").stopTime('prerolltimer');
	$("body#home #home_promo").hide("fast", function(){
		$("body#home #right").css({"background-image": "url(/img/home_promo.gif)", "background-color": "#EA495D"}).animate({opacity: 1}, 1000);
	});
	
	$("body#home #right").css({opacity: 1});
	
	$("body#home #right").hover(
				function(){
					$(this).css('cursor', 'pointer'); 
				},
				function(){ 
					$(this).css('cursor', 'auto');
					}
			).click(function(){document.location="/shop";});
	
}

$(function(){	// shorthand for $(document).ready()	
	var rotateCount = (homeimages.length);
	
	$.preloadImages(homeimages);
	
	var rotate = Math.floor(Math.random() * (rotateCount));
	//alert(rotate);
	if($.browser.msie){
		
		$("body#home #right").css("background-image", "url(/img/home_rotate/" + homeimages[rotate] + ")");
		$("body#home #home_promo").css({opacity: 1});
		
		$("body#home #right").everyTime(3000, 'prerolltimer', function() {
			rotate++;
			if (rotate > rotateCount) rotate = 1;
				
				$(this).hide();
				$(this).css({"background-image":"url(/img/home_rotate/" + homeimages[rotate - 1] + ")"});
				$(this).show();
						
			});
			
	} else {
		
		$("body#home #right").animate({opacity: 0}, 1).css("background-image", "url(/img/home_rotate/" + homeimages[rotate] + ")");
		$("body#home #home_promo").animate({opacity: 0}, 1);
		//$("body#home #home_promo").show("slide",  { direction: "right" }, "slow");
		
		$("body#home #home_promo").animate({opacity: 1}, 1000);
		$("body#home #right").animate({opacity: 1}, 1000);
		
		$("body#home #right").everyTime(5000, 'prerolltimer', function() {
			rotate++;
			if (rotate > rotateCount) rotate = 1;
				
				//$("body#home #home_promo").hide("slide",  { direction: "right" }, "slow", function(){ $("body#home #home_promo").show("slide",  { direction: "right" }, "slow"); });
				
				$(this).animate({opacity: 0}, 2000, function(){
					$(this).css({"background-image":"url(/img/home_rotate/" + homeimages[rotate - 1] + ")"});
					$(this).animate({opacity: 1}, 2000);
				});
						
			});
	}
	
	$('#home_promo').click(function(){
		$.loadPromo();
	}).hover(
		function(){
			$(this).css('cursor', 'pointer');
		},
		function(){ 
			$(this).css('cursor', 'auto');
			}
	);
	
	$('#home_promo p').center({vertical: true, horizontal: false});

});	