$(document).ready(function(){
	$('#home-products-slider').jcarousel();
	
	$("#top-search #query").focus(function(){
		if($(this).val() == "what are you looking for?")
		{
			$(this).val("");
		}
	});
	
	$("#top-search #query").blur(function(){
		if($(this).val() == "")
		{
			$(this).val("what are you looking for?");
		}
	});
	
	$("#top-inside li").hover(function(){
		$(this).animate({
			fontSize: "18px"
		}, 100);
	}, function(){
		$(this).animate({
			fontSize: "14px"
		}, 100);
	});
	
	$("#nav li").animate({
		marginTop: '2px'
	}, 0);
	
	$("#nav li").hover(function(){
		$(this).animate({
			marginTop: 0,
			fontSize: "18px"
		}, 100);
	}, function(){
		$(this).animate({
			marginTop: '2px',
			fontSize: "16px"
		}, 100);
	});

	theRotator();
});

var stoprotate = false;
var count = 1;
var zindex = 1;

function theRotator()
{
	var togo;
	
	$("#home-slider .slide").each(function(){
		++zindex;
	});
	
	$("#home-slider .slide").each(function(){
		if(count > 1)
		{
			togo = zindex;
			--zindex;
			$(this).css("z-index", zindex);
		}
		else
		{
			--zindex;
			$(this).css("z-index", zindex).hide();
		}
		++count;
	});
	
	$("#home-slider .slide:first").addClass("show");
	
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',8000);
}

function rotate() {
	if(stoprotate == false)
	{
		//Get the first image
		var current = ($('#home-slider .show') ?  $('#home-slider .show') : $('#home-slider div:first'));
		
		// Current z-index
		var current_zindex = current.css("z-index");

		//Get next image, when it reaches the end, rotate it back to the first image
		var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#home-slider div:first') :current.next()) : $('#home-slider div:first'));	

		current.fadeOut();
		next.fadeIn();
	
		//Set the fade in effect for the next image, the show class has higher z-index
		next.addClass('show');

		//Hide the current image
		current.removeClass('show');
	}
};
