var currentProductIndex = 0;
var currentBrandIndex = 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];
		}
		
		brandsTimeoutId = setTimeout("playBrands("+direction+")", 2000);
	}
	
	if(direction == 0)
	{
		clearTimeout(brandsTimeoutId);
	}
}

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

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