// body.onload loaders
addLoadEvent(imgMouseHovers);

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 width=\"604\" height=\"124\" src=\""+ blockItem.img + "\" alt=\""+ blockItem.title +"\" border=0>";
	if ( blockItem.url )
	{
	   html += "</a>";
	}
	tickerObj.innerHTML = html;
	if ( blockTikkerIndexList.length > 1 )
	{
	   setTimeout("writeBlockItem(\""+id+"\")",blockTikkerDelay);
	}
}

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;
}

// show / hide myTab div's
function showSideMyTab(showId){	
	// the links of the tabs: li > a's
	var tabLink = new Array();
	tabLink[0] = "links-tablink-1";
	tabLink[1] = "links-tablink-2";
	tabLink[2] = "links-tablink-3";
	
	// the div's to swap
	var tabId = new Array();
	tabId[0] = document.getElementById("links-tab-1");
	tabId[1] = document.getElementById("links-tab-2");
	tabId[2] = document.getElementById("links-tab-3");
	
	if((tabId[0] != null) && (tabId[1] != null) && (tabId[2] != null)){
		for(i=0; i<tabId.length; i++) {
			var aTab = document.getElementById(tabLink[i]);
			appendClass("remove", aTab, "current"); // remove current tab
			if(i == showId){
				tabId[i].style.display = "block"; // show the tab
				if (aTab) appendClass("add", aTab, "current"); // set current tabLink class
			} else {
				tabId[i].style.display = "none"; // hide the div
			}
		}		
	}
	return false;
}

// load the tabs on pages after the login
// don't forget the addLoadEvent(loadMyTab) on the page-head itself;
function loadMyTab() {	
	var urlQuerySting = getQueryString(); // get URL query string to check for preset shown tab
	if(urlQuerySting['showSideTab'] <= 2) { // there are only 3 tabs
		showSideMyTab(urlQuerySting['showSideTab']); // show tab from URL query string
	} else {
		showSideMyTab(0); // if omitted, show the first tab
	}	
}

// add a classname to an element
function addClass(element, value) {
	if(!element.className){
		element.className = value;
	} else {
		element.className += " "+value;
	}
}

// add, remove or check a class

// javascript:appendClass("add", this, false, "gewenste-classnaam") voegt class toe
// javascript:appendClass("remove", this, false, "gewenste-classnaam") haalt class weg

function appendClass(append, obj, addClass){
	switch (append){
		case "add":
		  if(!appendClass("check",obj,addClass)){obj.className+=obj.className?" "+addClass:addClass;}
		break;
		case "remove":
		  var rep=obj.className.match(" "+addClass)?" "+addClass:addClass;
		  obj.className=obj.className.replace(rep,"");
		break;
		case "check":
		  return new RegExp("\\b"+addClass+"\\b").test(obj.className);
		break;
 	}
}

function playQuiz(src){
	var popup = $("#popup-quiz");
	if (popup.length == 1){ 
		var html = '<div>'
			+ '<iframe src="' + src + '" width="800" height="600" name="cjpiframe" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" noresize></iframe>'
			+ '<a href="javascript:;" onclick="$(\'#popup-quiz\').hide()" class="close"></a>'
			+ '</div>';
		popup.html(html);
	}
	popup.show();
}

function CapsLockChecker() { }
CapsLockChecker.onKeyPress = function(event, message)
{
	var key = event.which;
	if (((key >= 65 && key <= 90) && !event.shiftKey) ||
        ((key >= 97 && key <= 122) && event.shiftKey))
		$(message).text("Let op: Je Caps-Lock staat aan!");
	else
		$(message).text("");
}
CapsLockChecker.setup = function()
{
	var inputs = $("#membernumber,#password");
	var message = document.getElementById("login-error");
	if (message && inputs.length != 0)
		$(inputs).bind("keypress", function(e) { CapsLockChecker.onKeyPress(e, message); });
}

$(document).ready(CapsLockChecker.setup);