// --- Common JavaScripts



// qued function loader for window.onload
function addLoadEvent(func) {
	var oldOnLoad = window.onload;
	if(typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}



// nav-main - suckerfish for that crappy browser IE6 :(
sfHover = function()
{
    if (document.getElementById("nav-main"))
    {
        var sfEls = document.getElementById("nav-main").getElementsByTagName("li");
        for (var i = 0; i < sfEls.length; i++)
        {
            sfEls[i].onmouseover = function()
            {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function()
            {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



// clear default text onClick - restore if nothing entered
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}



// click menu
/*
clickMenu = function(customSelectBox) {
	var rootItem = document.getElementById(customSelectBox)
	var getEls = document.getElementById(customSelectBox).getElementsByTagName("li");
	var getAgn = getEls;

	for (var i=0; i<getEls.length; i++) {
			getEls[i].onclick=function() {
				for (var x=0; x<getAgn.length; x++) {
				getAgn[x].className=getAgn[x].className.replace("unclick", "");
				getAgn[x].className=getAgn[x].className.replace("click", "unclick");
				}
			if ((this.className.indexOf('unclick'))!=-1) {
				this.className=this.className.replace("unclick", "");;
				}
				else {
				this.className+=" click";
				}
			}
			getEls[i].onmouseover=function() {
				this.className+=" hover";
			}
			getEls[i].onmouseout=function() {
				this.className=this.className.replace("hover", "");
			}
		
		}
	
	}

addLoadEvent(function(){clickMenu('select-auteur');});
addLoadEvent(function(){clickMenu('select-maand');});
addLoadEvent(function(){clickMenu('select-rubriek');});
addLoadEvent(function(){clickMenu('select-genre');});
addLoadEvent(function(){clickMenu('select-wanneer');});
*/

function createRandomIndexList(list)
{
	var lRandomList = new Array()
	var checkList = new Array();
	while(lRandomList.length<list.length)
	{
		rndNr = Math.floor(Math.random()*list.length);
		while(checkList[rndNr])
		{
			if(++rndNr>=list.length) rndNr=0;
		}
		checkList[rndNr] = true;
		lRandomList[lRandomList.length] = rndNr;
	}
	return lRandomList;
}

/* ===================================== */

function initBlockTicker(id)
{
	if(document.getElementById(id))
	{
		blockTikkerIndexList = createRandomIndexList(blockTikkerList);
		writeBlockItem(id);
	}
}

var blockIndex = 0;
var blockTikkerDelay = 6000;

function writeBlockItem(id)
{
	var tickerObj = document.getElementById(id);
	if(blockTikkerIndexList && blockIndex>=blockTikkerIndexList.length)
	{
		blockIndex=0;
	}
	i = blockTikkerIndexList[blockIndex++];
	blockItem = blockTikkerList[i];
	var html = "";
	if ( blockItem.url )
	{
	   html += "<a href=\""+ blockItem.url + "\">";
	}
	html += "<img src=\""+ blockItem.img + "\" alt=\""+ blockItem.title +"\" width=\"664\" height=\"120\" border=0>";
	tickerObj.innerHTML = html;
	if ( blockItem.url )
	{
	   tickerObj.innerHTML += "</a>";
	}
	if ( blockTikkerIndexList.length > 1 )
	{
	   setTimeout("writeBlockItem(\""+id+"\")",blockTikkerDelay);
	}
}