var product = new Array();
var productClick = new Array();
var selectedProduct = -1;
var focusProduct = -1;

var IE  = false;
if( navigator.appName=="Microsoft Internet Explorer")
	IE = true;

function imgClick(i)
{

	if( product[productClick[i]]["FolderId"] )
	{
		parent.location.href = "/show/activeSITE.asp?sid=" + ac_sid + "&p=%3CRubrikName%3E" + product[productClick[i]]["RubrikName"] + "%3C%2FRubrikName%3E%3Cfolder%20id%3D%22" + product[productClick[i]]["FolderId"] + "%22%20%2F%3E%3Cslot%20name%3D%22content%22%3E%3Cco%20id%3D%22" + milieu_co_id + "%22%20%2F%3E%3C%2Fslot%3E%3Cat%3E%3Cmillieu%3E" + product[productClick[i]]["CampaignPageId"] + "%3C%2Fmillieu%3E%3Cpage%3E1%3C%2Fpage%3E%3C%2Fat%3E%3CRubrikID%3E" + product[productClick[i]]["CampaignCategoryId"] + "%3C%2FRubrikID%3E";
	}
	else
	{
		parent.location.href = "/show/activeSITE.asp?sid=" + ac_sid + "&p=%3CRubrikName%3E" + RubrikName + "%3C%2FRubrikName%3E%3Cfolder%20id%3D%22" + FolderId + "%22%20%2F%3E%3Cslot%20name%3D%22content%22%3E%3Cco%20id%3D%22" + milieu_co_id + "%22%20%2F%3E%3C%2Fslot%3E%3Cat%3E%3Cmillieu%3E" + product[productClick[i]]["CampaignPageId"] + "%3C%2Fmillieu%3E%3Cpage%3E1%3C%2Fpage%3E%3C%2Fat%3E%3CRubrikID%3E" + RubrikId + "%3C%2FRubrikID%3E";
	}
}

function moveProd(dir)
{
	if (dir=="links")
	{
		focusProduct = focusProduct - 4;
	}
	if (dir=="rechts")
	{
		focusProduct = focusProduct + 4;
	}
	if (focusProduct < 1)
		focusProduct = 1;
	if (focusProduct > product.length-3)
		focusProduct = product.length-3;
	displayProducts(dir);
}

function initProducts()
{

	for (var i = 0; i < product.length; i++)
	{
		if (product[i]["CampaignPageId"] == CampaignPageId)
		{
			selectedProduct = i;
			focusProduct = selectedProduct;
			if (focusProduct < 1)
				focusProduct = 1;
			if (focusProduct > (product.length-3))
				focusProduct = product.length-3;
		}
	}
	if (focusProduct == -1)
		focusProduct = 2;
	if (product.length == 1)
		focusProduct = 0;
	if (product.length == 2)
		focusProduct = 0;
	if (product.length == 3)
		focusProduct = 1;
	if (product.length == 4)
		focusProduct = 1;
}

function displayProducts(dir)
{
	displayButtons(dir);

	for (var i = -1; i <= 2; i++)
	{
		var j = focusProduct + i;
		var k = i + 2;
		if (j >= 0 && j < product.length)
		{

			document.getElementById("img" + k).src = "/bilderpool/activeTrade/images/products/" + product[j]["Thumbnail"];
			$("#text" + k).text ( product[j]["PageName"]);
			$("#price" + k).text ( product[j]["AbPreis"]);
			$("#PriceMode" + k).text ( product[j]["PriceMode"]);
			$("#more" + k).text ( product[j]["more"]);
			if(product[j]["MinimalPriceQuantity"] > 1 ){
				$("#MinimalPriceQuantity" + k).text ( product[j]["MinimalPriceQuantity"]);
				$('#MinimalPriceQuantityParent' +k).css("display", "block");
			}else
			{
				$('#MinimalPriceQuantityParent' +k).css("display", "none");
			}

			if (selectedProduct == j)
			{
				document.getElementById("img" + k).className = "prodSelected";

			}
			else
			{
				document.getElementById("img" + k).className = "prodImg";
			}

			if(document.getElementById("pictureGallery"))
			{
				if (selectedProduct == j)
				{
					if (product[j]["Zoom"] != "")
					{
						document.getElementById("zoomWindow").style.display = "block";
						document.getElementById("zoomer").style.cursor = "move";
					}
					else
					{
						document.getElementById("zoomWindow").style.display = "none";
						document.getElementById("zoomer").style.cursor = "default";
					}
					document.getElementById("zoomimageback").src = "/bilderpool/activeTrade/images/products/" +product[j]["PictureFile"];
					document.getElementById("zoomimageback").style.display = "inline";
					document.getElementById("zoomimagetop").src = "/bilderpool/activeTrade/images/products/" +product[j]["PictureFile"];
					document.getElementById("zoomimagetop").style.display = "inline";
					if (product[j]["Zoom"] != "")
						document.getElementById("zoomimage").src = "/bilderpool/activeTrade/images/products/" +product[j]["Zoom"];
					else
						document.getElementById("zoomimage").src = "";
					document.getElementById("zoomimage").style.display = "inline";
					document.getElementById("img" + k).className = "prodSelected";
				}
				else
				{
					document.getElementById("img" + k).className = "prodImg";
					document.getElementById("img" + k).style.display = "inline";
				}
			}
			document.getElementById("img" + k).style.display = "inline";
			productClick[k] = j;
		}
	}

	for(x = 1; x < 5; x++)
	{
		imgsrc = document.getElementById("img"+ x).src;
		document.getElementById("div" + x).style.display = "block";
		if(imgsrc.indexOf("jpg") < 0)
		{
			document.getElementById("div" + x).style.display = "none";
		}

	}

}

function displayButtons(dir)
{
	if (focusProduct >= 2)
	{
		if (dir=="links")
		{
			document.getElementById("links").src = arrowLinksHover;
			//			"/images/templates/rubrik-links-h.png";
		}
		else
		{
			document.getElementById("links").src = arrowLinksEnable;
			//"/images/templates/rubrik-links-1.png";
		}
		document.getElementById("links").alt = "";
		document.getElementById("links").title = "";
		document.getElementById("links").style.cursor = "pointer";
		document.getElementById("links").style.display = "inline";
	}
	else
	{
		document.getElementById("links").src = arrowLinksDisable;
		//"/images/templates/rubrik-links-0.png";
		document.getElementById("links").alt = "";
		document.getElementById("links").title = "";
		document.getElementById("links").style.cursor = "default";
		document.getElementById("links").style.display = "inline";
	}

	if (focusProduct-product.length < -3)
	{
		if (dir=="rechts")
		{
			document.getElementById("rechts").src = arrowRechtsHover;
			//"/images/templates/rubrik-rechts-h.png";
		}
		else
		{
			document.getElementById("rechts").src = arrowRechtsEnable;
			// "/images/templates/rubrik-rechts-1.png";
		}
		document.getElementById("rechts").alt = "";
		document.getElementById("rechts").title = "";
		document.getElementById("rechts").style.cursor = "pointer";
		document.getElementById("rechts").style.display = "inline";
	}
	else
	{
		document.getElementById("rechts").src = arrowRechtsDisable;
		//"/images/templates/rubrik-rechts-0.png";
		document.getElementById("rechts").alt = "";
		document.getElementById("rechts").title = "";
		document.getElementById("rechts").style.cursor = "default";
		document.getElementById("rechts").style.display = "inline";
	}
}

function mouseClick(el)
{
	if (el.id=="links")
	{
		if (focusProduct >= 2)
		{
			moveProd("links");
		}
	}
	if (el.id=="rechts")
	{
		if (focusProduct-product.length < -3)
		{
			moveProd("rechts");
		}
	}
}

function mouseOver(el)
{
	if (el.id=="links")
	{
		if (focusProduct >= 2)
		{
			document.getElementById("links").src = arrowLinksHover;
			//"/images/templates/rubrik-links-h.png";
		}
	}
	if (el.id=="rechts")
	{
		if (focusProduct-product.length < -3)
		{

			document.getElementById("rechts").src = arrowRechtsHover;
			// "/images/templates/rubrik-rechts-h.png";
		}
	}
}

function mouseOut(el)
{
	if (el.id=="links")
	{
		if (focusProduct >= 2)
		{
			document.getElementById("links").src = arrowLinksEnable;
			//"/images/templates/rubrik-links-1.png";
		}
	}
	if (el.id=="rechts")
	{
		if (focusProduct-product.length < -3)
		{
			document.getElementById("rechts").src = arrowRechtsEnable;
			//"/images/templates/rubrik-rechts-1.png";
		}
	}
}

function activate(id)
{
	document.getElementById("div"+id).className = "activate"
}

function deactivate(id)
{
	document.getElementById("div"+id).className = "deactivate"
}

function changeImg(id)
{
	displayid = id-2+focusProduct;

	if (product[displayid]["Zoom"] != "")
	{
		document.getElementById("zoomWindow").style.display = "block";
		document.getElementById("zoomer").style.cursor = "move";
	}
	else
	{
		document.getElementById("zoomWindow").style.display = "none";
		document.getElementById("zoomer").style.cursor = "default";
	}

	document.getElementById("zoomimagetop").src = "/bilderpool/activeTrade/images/products/" +product[displayid]["PictureFile"];
	document.getElementById("zoomimagetop").style.display = "inline";
	document.getElementById("zoomimageback").src = "/bilderpool/activeTrade/images/products/" +product[displayid]["PictureFile"];
	document.getElementById("zoomimageback").style.display = "inline";
	if (product[displayid]["Zoom"] != "")
		document.getElementById("zoomimage").src = "/bilderpool/activeTrade/images/products/" +product[displayid]["Zoom"];
	else
		document.getElementById("zoomimage").src = "";
	document.getElementById("zoomimage").style.display = "inline";

	for(x = 1; x < 5; x++)
	{
		document.getElementById("img"+ x).className = "prodImg";
		if(x == id)
		{
			document.getElementById("img"+ x).className = "prodSelected";
		}
	}
}

