/////////////////////////////////////////////////////
//DISPLAY DESCRIPTION FOR SLIDESHOW ADS ON HOMEPAGE//
/////////////////////////////////////////////////////
var adSlideshowDescC;
var adSlideshowDescP;
function displayAdDesc(desc, caller, e)
{
	switch(caller)
	{
		case "theCycle":
		adSlideshowDescC = desc;
		$("#adSlideshowDesc").html(adSlideshowDescC);
		break;
		
		case "thePager":
		adSlideshowDescP = desc;
		switch(e)
		{
			case "mouseover":
			$("#adSlideshowDesc").html(adSlideshowDescP);
			break;
			
			case "mouseout":
			$("#adSlideshowDesc").html(adSlideshowDescC);
			break;
		}
		break;
	}
}

//////////////////////////////
//SELF EXPLANATORY FUNCTIONS//
//////////////////////////////
function createPagers(index, slide)
{
	var desc = slide.firstChild.alt;
	return "<a href=\"javascript:void(0)\" onmouseover=\"displayAdDesc('"+desc+"', 'thePager', 'mouseover')\" onmouseout=\"displayAdDesc('"+desc+"', 'thePager', 'mouseout')\">"+(index+1)+"</a>";
}

function pauseSlideshow()
{
	$("#adSlideshow").cycle("pause");
	$("#adSlideshowPlayPause > a").html("Play");
}

function resumeSlideshow()
{
	$("#adSlideshow").cycle("resume");
	$("#adSlideshowPlayPause > a").html("Pause");
}

//////////////////////////////////////////////
//HANDLE PRODUCT CATEGORY PREVIEWS BELOW ADS//
//////////////////////////////////////////////

function movePPSelector(caller)
{
	var j = 0;
	var locTop = 0;
	var ppLinks = $("#ppLinks > ul");	
	
	for(i=0;i<4;i++)
	{
		if($("#ppLinks > ul > li:eq("+i+") > a").html() == caller.innerHTML)
		{
			locTop = 32 * i + locTop;
			j = j + i;
		}
	}
	
	$("#ppSelector").stop(true);
	
	$("#ppSelector").animate({top:locTop+"px"}, 500, "easeOutSine", function()
	{
		$("#pp > div:not(:eq("+j+"))").hide();
		$("#pp > div:eq("+j+")").fadeIn(2000);
		
		if(navigator.appVersion.indexOf("MSIE 6.0") > -1)
		{
			//$("#footerC").css("margin-top", "-38px");	
		}
		
	});
}

////////////////////////////////////////////////////////

$(document).ready(function()
{
	////////////////////////////////
	//RUN AD SLIDESHOW ON HOMEPAGE//
	////////////////////////////////
	$("#adSlideshow").cycle(
	{
        fx: "cover",
		timeout: 7000,
        easing: "easeOutBounce",
		pager: "#adSlideshowController > div:eq(0)",
		pagerAnchorBuilder: function(index, slide){return createPagers(index, slide)},
		before: function(){displayAdDesc(this.firstChild.alt, "theCycle")},
		pause: true
	});

	var adSlideshowNumbers = $("#adSlideshow > a").length;
	if(adSlideshowNumbers>1)
	{
		$("#adSlideshowPlayPause").html("<a href=\"javascript:void(0)\">Pause</a>");	

		$("#adSlideshowPlayPause > a").toggle(pauseSlideshow, resumeSlideshow);
	}
	
	$("#ppLinks a").mouseover(function(){movePPSelector(this)});
});