var currentProductIndex = 0;
var currentBrandIndex = 0;
var currentShowcaseIndex = 0;

function playSlideshow(direction)
{
	if(direction == 1)  { clearTimeout(slideshowTimeoutId); }
	if(direction == -1) { currentProductIndex -= 2; clearTimeout(slideshowTimeoutId); }
	
	if(productIds.length > 0)
	{
		if(currentProductIndex >= productIds.length) currentProductIndex = 0;
		if(currentProductIndex < 0) currentProductIndex = 0;
		
		xajax_getSlideshowProductInfo(productIds[currentProductIndex]);
		slideshowTimeoutId = setTimeout("playSlideshow(0)", 5000);
		currentProductIndex++;
	}
	else
	{
		document.getElementById("slide_table").style.visibility = "hidden";
		document.getElementById("noSlideshow").style.visibility = "visible";
	}
}

function playBrands(direction)
{
	if(direction == -2)
	{
		clearTimeout(brandsTimeoutId);
		return true;
	}
	
	if(direction == 1 && brandImages[currentBrandIndex+1] != undefined)
	{
		if(brandImages[currentBrandIndex+4] != undefined) currentBrandIndex += 1;
		else currentBrandIndex = 0;
	}
	if(direction == -1)
	{
		if(brandImages[currentBrandIndex-1] != undefined) currentBrandIndex -= 1;
	}
	
	if(brandIds.length > 0)
	{
		for(i=0; i<4; i++)
		{
			document.getElementById("brandImage"+(i+1)).src = "images/brands/"+brandImages[currentBrandIndex+i];
			document.getElementById("brandLink"+(i+1)).href = "brand.php?brand_id="+brandIds[currentBrandIndex+i];
			document.getElementById("brandLink"+(i+1)).title = "View all products by "+brandNames[currentBrandIndex+i];
		}
		
		if(brandsTimeoutId)
		{
			clearTimeout(brandsTimeoutId);
		}

		brandsTimeoutId = setTimeout("playBrands("+direction+")", 2000);
	}
	
	if(direction == 0)
	{
		clearTimeout(brandsTimeoutId);
	}
}

function playShowcase(direction)
{
	if(direction == -2)
	{
		clearTimeout(showcaseTimeoutId);
		return true;
	}
	
	if(direction == 1 && brandImages[currentShowcaseIndex+1] != undefined)
	{
		if(brandImages[currentShowcaseIndex+4] != undefined) currentShowcaseIndex += 1;
		else currentShowcaseIndex = 0;
	}
	if(direction == -1)
	{
		if(brandImages[currentShowcaseIndex-1] != undefined) currentShowcaseIndex -= 1;
	}
	
	if(brandIds.length > 0)
	{
		for(i=0; i<4; i++)
		{
			document.getElementById("brandImage"+(i+1)).src = "images/showcase/"+brandImages[currentBrandIndex+i];
			document.getElementById("brandLink"+(i+1)).href = "#";
			document.getElementById("brandLink"+(i+1)).title = "View all products by "+brandNames[currentBrandIndex+i];
		}
		
		if(showcaseTimeoutId)
		{
			clearTimeout(showcaseTimeoutId);
		}

		showcaseTimeoutId = setTimeout("playShowcase("+direction+")", 2000);
	}
	
	if(direction == 0)
	{
		clearTimeout(showcaseTimeoutId);
	}
}

xajax.loadingFunction = function()
{
	//document.getElementById("loadingPanel").style.visibility = "visible";
}

xajax.doneLoadingFunction  = function()
{
	//document.getElementById("loadingPanel").style.visibility = "hidden";
}

var brandsTimeoutId;
var showcaseTimeoutId;