//Begin Carrousel aanbiedingen:
var portletDivs = new Array();
var currentPortletIndex = 0;
var currentPortletIndexSpan = null;

function viewPortletLink()
{
	var aHref = document.getElementById('portletlink'+(currentPortletIndex+1));
	document.location.href = aHref;
	return false;
}

function enumeratePortlets()
{
	var aContainer = document.getElementById('portletlist');
	currentPortletIndexSpan = document.getElementById('currentPortletIndex');
	if (aContainer)
	{
		for(var i=0,aNode;aNode=aContainer.childNodes[i];i++)
		{
			if ((aNode.nodeName == "DIV") && (aNode.className == "portlet1"))
			{
				if (portletDivs.length == 0)
				{
					aNode.style.display = "block";
				}
				portletDivs[portletDivs.length] = aNode;
			}
		}
		var PrevNextDiv = document.getElementById('portletprevnext');
		if (PrevNextDiv)
		{
			PrevNextDiv.style.display = (portletDivs.length > 1) ? "block" : "none";
		}
	}
	return false;
}
addLoadEvent(enumeratePortlets);

function portletCycle(aDirection)
{
	var PrevIndex = ((currentPortletIndex-1) < 0) ? (portletDivs.length-1) : (currentPortletIndex-1);
	var NextIndex = ((currentPortletIndex+1) == portletDivs.length) ? 0 : (currentPortletIndex+1);
	portletDivs[currentPortletIndex].style.display = "none";
	if (aDirection == 0)
	{
		portletDivs[PrevIndex].style.display = "block";
		currentPortletIndex = PrevIndex;
	}
	else
	{
		portletDivs[NextIndex].style.display = "block";
		currentPortletIndex = NextIndex;
	}
	if( document.getElementById('portletlink'+(currentPortletIndex+1)))
	{
		document.getElementById('buttonSetCollection').style.display = "block";
	}
	else
	{
		document.getElementById('buttonSetCollection').style.display = "none";	
	}
	currentPortletIndexSpan.innerHTML = (currentPortletIndex+1);
}
//End Carrousel aanbiedingen:


function initSpecialOffers()
{
	var specialOffersElm = document.getElementById("specialOffers");
	if(specialOffersElm)
	{
		var divList = specialOffersElm.getElementsByTagName("div");
		for(var i=0;i<divList.length;i++)
		{
			divElm = divList[i];
			if(divElm.className=="offer")
			{
				setHover(divElm);
			}
		}
	}
}

addLoadEvent(initSpecialOffers);


var themeResult = {
	productsPerPage:4,
	activePageIndex:0,
	totalPages:0,
	idList:[],
	init : function()
	{
		var tR = themeResult;
		var themeDataElm = document.getElementById("themeData")
		var themeDisplayElm = document.getElementById("themeDisplay");
		var themeNavElm = document.getElementById("themeNav")
		var childList =  themeDataElm.childNodes;
		for(var i=0,childElm;childElm=childList[i];i++)
		{
			if(childElm.nodeType==1 && childElm.id.length)
			{
				tR.idList.push(childElm.id);
			}
		}
		if(tR.idList.length>tR.productsPerPage)
		{
			tR.totalPages=Math.ceil(tR.idList.length/tR.productsPerPage);
			themeNavElm.style.visibility="visible";
		}
		tR.display();
		themeDisplayElm.style.height = themeDisplayElm.offsetHeight+12+"px";
	},
	get : function(next)
	{
		var tR = themeResult;
		if(next)
		{
			if(++tR.activePageIndex>=tR.totalPages)
			{
				tR.activePageIndex=0;
			}
		}
		else
		{
			if(--tR.activePageIndex<0)
			{
				tR.activePageIndex=tR.totalPages-1;
			}
		}
		tR.display();
		return false;
	},
	display : function()
	{
		var tR = themeResult;
		var themeDisplayElm = document.getElementById("themeDisplay");
		var html = [];
		begin = tR.activePageIndex*tR.productsPerPage;
		end = (begin+tR.productsPerPage<tR.idList.length) ? begin+tR.productsPerPage : tR.idList.length ;
		for(var i=begin;i<end;i++)
		{
			html.push(document.getElementById(tR.idList[i]).innerHTML);
		}
		themeDisplayElm.innerHTML = html.join("");
		document.getElementById("themeTotal").innerHTML = tR.totalPages;
		document.getElementById("themeCount").innerHTML = (tR.activePageIndex+1);
		tR.initThemes();
	},
	showAll : function()
	{
		var tR = themeResult;
		var themeDisplayElm = document.getElementById("themeDisplay");
		var html = [];
		for(var i=0;i<tR.idList.length;i++)
		{
			html.push(document.getElementById(tR.idList[i]).innerHTML);
		}
		themeDisplayElm.innerHTML = html.join("");
		document.getElementById("themeNav").style.display = "none";
		document.getElementById("themeAll").style.display = "none";
		
		tR.initThemes();
	},	
	
	initThemes : function()
	{
		var themeDisplayElm = document.getElementById("themeDisplay");
		var childList =  themeDisplayElm.childNodes;
		for(var i=0,childElm;childElm=childList[i];i++)
		{
			if(childElm.nodeType==1)
			{
				if(childElm.className=="theme")
				{
					setHover(childElm);
				}
				else
				{
					setHover(childElm.getElementsByTagName("div")[0]);
				}
			}
		}
	}
}

//addLoadEvent(themeResult.init);