var currentPortlet;
var intervalID;

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function mouseOver(inputObj) {
	if (inputObj.parentNode.className.indexOf("Active") != -1) return;
	if (inputObj.tagName.toLowerCase() == "img" || inputObj.tagName.toLowerCase() == "input") {
		inputObj.src = inputObj.src.replace("_n.gif","_s.gif");
	} else {
		var img = inputObj.getElementsByTagName("img")[0];
		if (img) {
			img.src = img.src.replace("_n.gif","_s.gif");
		}
	}
}

function mouseOut(inputObj) {
	if (inputObj.parentNode.className.indexOf("Active") != -1) return;
	if (inputObj.tagName.toLowerCase() == "img" || inputObj.tagName.toLowerCase() == "input") {
		inputObj.src = inputObj.src.replace("_s.gif","_n.gif");
	} else {
		var img = inputObj.getElementsByTagName("img")[0];
		if (img) {
			img.src = img.src.replace("_s.gif","_n.gif");
		}
	}
}

function Popup(url, window_name, window_width, window_height) {
    settings=
    "toolbar=no,location=no,directories=no,"+
    "status=no,menubar=no,scrollbars=no,"+
    "resizable=yes,width="+window_width+",height="+window_height;


    NewWindow=window.open(url,window_name,settings);
}

function init() {
	currentPortlet = 0;
	intervalID = setInterval(paginator, 7000);
}


function toggle(id) {
	// standaard toggle script
	var my_ids = id.split(",");
	for (i=0;i<my_ids.length;i++){
	   	el = document.getElementById(my_ids[i]);
     	var display = '';
    	if  (!el.style.display) {
          	display = 'none';
    	}
     	el.style.display = display;
	}
}

// de volgende drie functies zijn voor het bladeren door de divs
// deze functies maken ook gebruik van de standaard toggle functie
// de div id's moeten eindigen met _nummer: dus bv id="tl_bl_0"

function getVisibleDiv(d,c){
	// bekijk welke van de set zichtbaar is en return het nummertje
	var activeID;
	for (i=0;i<=c;i++){
		var thisDiv = d+"_"+i;
		if (document.getElementById(thisDiv)) {
			var el = document.getElementById(thisDiv);
			if  ( (!el.style.display) || (el.style.display =="inline") ) {
				activeID = i;
	    	}
		}
	}
	return activeID;
}
function getDivCount(d){
	// tel het aantal divs met een bepaalde id
	var dcount = -1; // omdat de div's beginnen bij 0 en dcount het aantal gevonden divs is.... 
	var divArray = document.getElementsByTagName('div');
	for (var i = 0; i < divArray.length; i++) {
	   var e = divArray[i].getAttribute('id')+"";
	   	e = e.replace(/\d/g, '');
		if (e.length > 1) {
			if (e.lastIndexOf("_") == (e.length-1)){
				e = e.substring(0,e.length-1);
			}
	  		if (e == d ){
				dcount++;
			}
		}
	}
	return dcount ; 
}
function paginator(d,p){
	if (d == 'portlet_shorty_topright') {
		clearInterval(intervalID);
	}
	if (!d){
		d='portlet_shorty_topright';
	}
	if (!p) {
		p = 1;
	}
	
	// blader door de divs....
	var maxD = getDivCount(d);
	var activeID = getVisibleDiv(d,maxD);
	var nextID = activeID + p;
	var activeDiv = d +"_"+activeID;
	var nextDiv =  d +"_"+(nextID); 
	// aan het begin of eind? gewoon doorgaan....
	if ((activeID == maxD) && (p == 1) ){
		var nextDiv =  d +"_"+0;
	}
	if ((activeID == 0) && (p == -1) ){
		var nextDiv =  d +"_"+maxD;
	}
	// zet de zichtbare div uit en de andere aan
	
		var current = document.getElementById(activeDiv);
		var next = document.getElementById(nextDiv);
		
		if (activeDiv.indexOf("discussie_bottom") > -1){
			current.style.margin= "0px 8px 0px 0px";
			next.style.margin= "0px 8px 0px 0px";
		}
		else if (activeDiv.indexOf("shorty_bottom") > -1){
			current.style.margin= "0px 8px 0px 0px";
			next.style.margin= "0px 8px 0px 0px";
		} else {
			current.style.margin= "0px 14px 0px 0px";
			next.style.margin= "0px 14px 0px 0px";
		}
		
		current.style.display = "none";
		next.style.display = "inline";
		
	
}
//eind blader divs...

// voor STOAS cursussen
function StartWBT(theURL){
	newWindow=window.open(theURL+location.search,"TeamCursusWindow","left=0, top=0, width=788, height=550, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=no, status=yes, titlebar=yes, toolbar=no",true)
	return null;
}
function StartWBT2(theURL){
	newWindow=window.open(theURL+location.search,"TeamCursusWindow","left=0, top=0, width=1000, height=650, directories=no, fullscreen=no, location=no, menubar=no, resizable=no, scrollbars=no, status=yes, titlebar=yes, toolbar=no",true)
	return null;
}

function ExitWBT(){
	//if (window.opener) window.close();
}

