var menuTimerOn = false;
var menuTimerCount = 500;
var aantalHoofd = 6;

function showDiv(whichID){
	hideSubMenuAll();
	if(document.getElementById('popLink'+whichID)!=null){
		document.getElementById('popLink'+whichID).style.display="block";
	}
}


// startMenuTimer: wanneer de <A> van het niveau 1 item of het submenu zelf wordt verlaten start er een timer die vervolgens de submenus verbergt
function startMenuTimer() {
	if (menuTimerOn == false) {
		menuTimerID = setTimeout("hideSubMenuAll()" , menuTimerCount);
		menuTimerOn = true;
	}
}

// stopMenuTimer: wanneer onmouseout van de niveau 1 <A> wordt getriggerd, begint de teller te lopen om het submenu te verbergen. Als de bezoeker nu echter OP
// submenu gaat staan of op de <A> zelf blijft hangen, dan stopt de timer en blijft het submenu in beeld
function stopMenuTimer() {
	if (menuTimerOn) {
		clearTimeout(menuTimerID);
		menuTimerOn = false;
	}
}

function hideSubMenuAll(){
	for(i=0;i<aantalHoofd+1;i++){
		if(document.getElementById("popLink"+i)!=null){
			document.getElementById("popLink"+i).style.display="none";
		}
	}
}

function setLang(langID, redir) {
   document.location = 'index.php?lang=' + langID + '&redir=' + redir;
}

function jsUpdateOnzin() {
   document.getElementById('txtOnzin').value = "123checked";
}





// init (ENKEL ASH)
window.onload = function(){	
	if(is_front() && undefined != window['iFBMax']){
		
		
		if(window.iFBMax>0)
			hs.init();
	}
};

function is_front(){ return (document.location.href.toString().indexOf('/wba/') === -1);}
function $(sVar){ return document.getElementById(sVar);}
function rand(iV,iT,iO){
	var i = Math.floor(Math.random() * (iT - iV + 1)) + iV;

	if(undefined === iO || i !== iO)
		return i;
	return rand(iV,iT,iO);
}

var hs = {
	
	// Settings
	 iActive: 10 // aantal active sec
	,fAniOpaStep: 0.011 // tussen 0 en 1 (per 10ms)
	
	,oContainer: null
	,oCImg1: null
	,oCImg2: null
	,bCImg1: true
	
	,iImage: 0
	,iImageMax: 0
	
	,rTimerImage: null
	,rTimerAni: null
	
	,init: function(){
		hs.oContainer = $('fb');
		hs.oCImg1     = $('fb1');
		hs.oCImg2     = $('fb2');
		hs.iImageMax  = window.iFBMax;
		
		hs.oCImg1.onload = hs.image_onload;
		hs.oCImg2.onload = hs.image_onload;
		
		//hs.load_image(rand(1, hs.iImageMax));
		
		hs.rTimerImage = setTimeout(function(){
			hs.load_image(rand(1, hs.iImageMax));
		}, hs.iActive*1000);
	}
	
	,load_image: function(iImage){
		hs.iImage = iImage;
		
		if(hs.rTimerImage)
			clearTimeout(hs.rTimerImage);
			
		hs.inactive_image().src = window.HTTP_PATH+'/images/fb/ash_fb'+iImage+'.jpg';
		
		hs.rTimerImage = setTimeout(function(){
			hs.load_image(rand(1, hs.iImageMax,hs.iImage));
		}, hs.iActive*1000);
	}
	
	,image_onload: function(){
		hs.toggle_active_image();
		hs.image_slide();
	}
	
	,image_slide: function(){
		var oInActive = hs.active_image();
		var oActive = hs.inactive_image();
		/*
		oInActive.style['opacity'] = 0;
		oActive.style['opacity']   = 1;*/
		
		setOpacity(oInActive, 0);
		setOpacity(oActive, 1);
		
		oInActive.style['z-index'] = 3;
		oInActive.style['zIndex'] = 3;
		oActive.style['z-index'] = 2;
		oActive.style['zIndex'] = 2;
		
		hs.ani_next(oInActive, oActive);
	},
	
	ani_next: function(oInActive, oActive){
		if(hs.rTimerAni)
			clearTimeout(hs.rTimerAni);
			
		iOpa = getOpacity(oInActive) + hs.fAniOpaStep;
		setOpacity(oInActive, iOpa);
		setOpacity(oActive, 1-iOpa);
		
		if(iOpa<1)
			hs.rTimerAni = setTimeout(function(){
				hs.ani_next(oInActive, oActive);
			},10);
	}
	
	,active_image: function(){
		return hs.bCImg1 ?hs.oCImg1 :hs.oCImg2;
	}
	
	,inactive_image: function(){
		return !hs.bCImg1 ?hs.oCImg1 :hs.oCImg2;
	}
	
	,toggle_active_image: function(){
		hs.bCImg1 = !hs.bCImg1;
	}
};

function getOpacity(oObj){
	if(navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) <= 4){
		return parseFloat(parseFloat(oObj.style['filter'].toString().replace('alpha(opacity=','').replace(')',''))/100);
	} else {
		return parseFloat(oObj.style['opacity']);
	}
}
function setOpacity(oObj, iOpa){
	if(navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) <= 4){
		oObj.style['filter'] = 'alpha(opacity='+(iOpa*100)+')';
	} else {
		oObj.style['opacity'] = iOpa;
	}
/*	
	if(iOpa <0.1)
		oObj.style['visibility'] = 'hidden';
	else oObj.style['visibility'] = 'visible';*/
}
