// == browser info ===============================

if(navigator)
{
	user = navigator
	IS_NETSCAPE = (user.appName.toLowerCase().indexOf("netscape") != -1);
	IS_IE = (user.appName.toLowerCase().indexOf("internet") != -1);
	IS_SAFARI = (user.userAgent.toLowerCase().indexOf("safari") != -1);
	
	IS_OPERA = (user.appName.toLowerCase() == "opera");
	
	if(user.userAgent.indexOf("Opera")>-1)
	{
		IS_IE = false;
		IS_OPERA = true;
	}
	// browser version
	if (user.appVersion)
	{  // don't try to parseInt a string (NA = "")
		VERSION_IS = parseInt(user.appVersion);
		if (IS_IE)
		{  // fix for IE 5.0 appVersion bug (returns 4.0 version number)
			if (navigator.userAgent.indexOf("5.0") != -1) VERSION_IS = parseInt(user.appVersion);
		}
	}
	// user OS/platform
	if (user.userAgent && user.appVersion)
	{
		agt = user.userAgent.toLowerCase();  // abbreviation
		IS_WIN = ((agt.indexOf("win") != -1) || (agt.indexOf("16bit") != -1));
		IS_MAC = (agt.indexOf("mac") != -1);
		
		IS_OSX = IS_MAC && (agt.indexOf("os x") != -1);
	}
}	


// == CAROUSEL =====================================

var delay = 3000;	// timeout in msec 3000 = 3 seconds
function writeAanbieding()
{
	var carouselObj = document.getElementById("carousel");
	var textObj = carouselObj.getElementsByTagName("span")[0];
	var imgObj = carouselObj.getElementsByTagName("img")[0];
	var aObj = carouselObj.getElementsByTagName("a")[0];
	
	var aanbieding = getAanbieding();
	
	aObj.href = aanbieding.href;
	imgObj.src = aanbieding.src;
	textObj.innerHTML = aanbieding.text;
	
	setTimeout("writeAanbieding()",delay);
}

// -------------------------------------------------

var listIndex = 0;
var randomList;

function getAanbieding()
{
	if(listIndex>=aanbiedingList.length)
	{
		listIndex=0;
	}
	return aanbiedingList[randomList[listIndex++]]
}

function createRandomList(lBannerList)
{
	var lRandomList = new Array()
	var checkList = new Array();
	while(lRandomList.length<lBannerList.length)
	{
		rndNr = Math.floor(Math.random()*lBannerList.length);
		while(checkList[rndNr])
		{
			if(++rndNr>=lBannerList.length) rndNr=0;
		}
		checkList[rndNr] = true;
		lRandomList[lRandomList.length] = rndNr;
	}
	return lRandomList;
}

function initAanbieding()
{
	randomList = createRandomList(aanbiedingList);
	writeAanbieding();
}

// ==================================================
// give the image and text some air by adding margins

function initHTMLeditContent()
{
	editObj = document.getElementById("HTMLedit");
	imageElmList = editObj.getElementsByTagName("img");
	for(var i=0;i<imageElmList.length;i++)
	{
		if(imageElmList[i].align.toLowerCase()=="right")
		{
			imageElmList[i].className="imgRight";
		}
		else if(imageElmList[i].align.toLowerCase()=="left")
		{
			imageElmList[i].className="imgLeft";
		}
	}
}
	
	
	
	
// ==================================================

function navOver(aObj)
{
	var imgObj = aObj.getElementsByTagName("img")[0];
	imgObj.src = imgObj.src.replace(".gif","_over.gif");
	aObj.onmouseout = function()
	{
		imgObj.src = imgObj.src.replace("_over.gif",".gif");
	}
}

function initNav()
{
	var subNavObj = document.getElementById("nav");
	var aElmList = subNavObj.getElementsByTagName("a");
	for(var i=0;i<aElmList.length;i++)
	{
		if(aElmList[i].id!="active")
		{
			aElmList[i].onmouseover = function()
			{
				navOver(this);
			}
			// preload images
			imgSrc = aElmList[i].getElementsByTagName("img")[0].src;
			preloadImage([imgSrc,imgSrc.replace(".gif","_over.gif")]);
		}
	}
}

// ----------------------------------

function subNavOver(aObj)
{
	var imgObj = aObj.getElementsByTagName("img")[0];
	imgObj.src = imgObj.src.replace(".gif","_over.gif");
	aObj.onmouseout = function()
	{
		imgObj.src = imgObj.src.replace("_over.gif",".gif");
	}
}

function initSubNav()
{
	var subNavObj = document.getElementById("subNav");
	var aElmList = subNavObj.getElementsByTagName("a");
	for(var i=0;i<aElmList.length;i++)
	{
		aElmList[i].onmouseover = function()
		{
			subNavOver(this);
		}
		// preload images
		imgSrc = aElmList[i].getElementsByTagName("img")[0].src;
		preloadImage([imgSrc,imgSrc.replace(".gif","_over.gif")]);
	}
}

// ----------------------------------

var preloadList = new Array();

function preloadImage(src)
{
	if(typeof(src)=="sting")
	{
		var listIndex = preloadList.length;
		preloadList[listIndex] = new Image();
		preloadList[listIndex].src = src
	}
	else if(typeof(src)=="object")
	{
		for(var i=0;i<src.length;i++)
		{
			var listIndex = preloadList.length;
			preloadList[listIndex] = new Image();
			preloadList[listIndex].src = src[i];
		}
	}
}

// ----------------------------------

function initAanbod()
{
	var divObjList = document.getElementById("aanbod").getElementsByTagName("div");
	for(var i=0;i<divObjList.length;i++)
	{
		if(divObjList[i].className=="item")
		{
			divObjList[i].onmouseover=function()
			{
				this.className="itemOver";
				this.onmouseout = function()
				{
					this.className="item";
				}
			}
			divObjList[i].onclick=function()
			{
				openAanbieding(this.getElementsByTagName("a")[0])
			}
			
		}
	}
}

// ----------------------------------

var aanbiedingsPopup = null;

function openAanbieding(aObj)
{
    url = aObj.href;
	target = aObj.target;
	if(aanbiedingsPopup)
	{
		if(!aanbiedingsPopup.closed)
		{
			aanbiedingsPopup.location.href=url;
			aanbiedingsPopup.focus();
			return false;
		}
	}
	
	w = 520;
	h = 300;
	if(IS_SAFARI)
	{
		h+=16;	
	}
	if(IS_MAC && IS_IE)
	{
		h-=15;
	}
	
	//van af of het gaat om pdf (resizable)
	if (url.match(/\.pdf/i))
	{
	    aanbiedingsPopup = window.open(url, target, "left=30,top=30,status=1,resizable=1");
	}
	else
	{
	    aanbiedingsPopup = window.open(url, target, "width=" + w + ",height=" + h + ",left=30,top=30,status=1");
	}
	
	return false;
}