// KRT2008 Global JavaScript Functions

//if (self != top) top.location.href = window.location.href;

function fwindow() {self.focus();}

//menuRoll
function menuRoll(eMenu)
{
	//Declare variables
	var sImgSuffix, eImg, srcURL, sExtention, sName, sPath;
	
	//Get the image inside the link using the firstChild method of the link element.
	//firstChild is a DOM level 1 function and is compatible with all relevant browsers.
	eImg = eMenu.getElementsByTagName('img')[0];

	//Retrieve current image source and split it up in relevant sections
	//Path
	//Name
	//Extention
	srcURL = new String(eImg.src);
	sPath = srcURL.substring(0,srcURL.lastIndexOf("/") + 1);
	sName = srcURL.substring(srcURL.lastIndexOf("/") + 1,srcURL.lastIndexOf("."));
	sExtention = srcURL.substring(srcURL.lastIndexOf("."),srcURL.length);

	//The assumption is made that the name of an active image ends with "_up"
	//Using the assumption it is checked wether a mouseover or mouseout action is performed;
	sImgSuffix = "_up";
	
	if (srcURL.indexOf(sImgSuffix) == -1){
		//Assign mouseover file, add the suffix
		eImg.src = sPath + sName + sImgSuffix + sExtention;
	}
	else{
		//Assugb mouseout file, remove the suffix
		eImg.src = sPath + sName.replace(sImgSuffix , "") + sExtention;
	}
}

function swapBg(eSwap){
	var colLinks;
	colLinks = eSwap.getElementsByTagName('a');
	if(eSwap.active == true){
		eSwap.active = false;
		eSwap.style.backgroundColor = "#FFFFFF";
		eSwap.style.color = "#676767";
		for (var i=0; i<colLinks.length; i++){
			colLinks[i].style.color = "#676767";
		}
	}
	else{
		eSwap.active = true;
		eSwap.style.backgroundColor = "#91E476";
		eSwap.style.color = "#000000";
		for (var i=0; i<colLinks.length; i++){
			colLinks[i].style.color = "#000000";
		}
	}
}

function classCLMS_Rotator(){
	this["bEngineRunning"] = false;
	this["colPictures"] = new Object();
	this["colRotators"] = new Object();
	this["eRotate"] = null;
	this["nIndexTotalImage"] = 0;
	this["nIndexTotal"] = 0;
	this["nIndexCurrent"] = 0;
	this["nIntervalEngine"] = 0;
	this["nIntervalPause"] = 25;
	this["nIntervalPauseCounter"] = 25;
	this["bFade"] = false;
	this["bFadeIn"] = false;
	this["nFadeInterval"] = 10;
	this["nFadeIntervalCounter"] = 10;
	this["nOpacity"] = 100;
	
	this.addImage = addImage;
	this.addRotator = addRotator;
	this.engineLoop = engineLoop;
	this.setRotateImage = setRotateImage;
	this.startEngine = startEngine;
	this.stopEngine = stopEngine;
	this.fadeImg = fadeImg;
	
	function addImage(src){
		this.colPictures[this.nIndexTotalImage] = new Image();
		this.colPictures[this.nIndexTotalImage].src = src;
		this.nIndexTotalImage = this.nIndexTotalImage + 1;
	}
	
	function addRotator(eRotate){
		var oRotator = new classCLMS_Rotator()
		oRotator.eRotate = eRotate;
		oRotator.nIntervalPauseCounter = oRotator.nIntervalPauseCounter + ((Math.floor(this.nIndexTotal * (oRotator.nIntervalPause / 25))) * 6);
		this.colRotators[this.nIndexTotal] = oRotator;
		this.nIndexTotal = this.nIndexTotal + 1;
		return oRotator;
	}
	
	function engineLoop(){
		var oRotator;
		for (var i in this.colRotators){
			oRotator = this.colRotators[i];
			if (oRotator.nIntervalPauseCounter == 0){
				if (oRotator.bFade){
				    oRotator.nFadeIntervalCounter -= 1;
				    oRotator.fadeImg(oRotator.eRotate);
				    if (oRotator.nFadeIntervalCounter == 0){
				        if (oRotator.bFadeIn){
				            oRotator.nIndexCurrent = oRotator.nIndexCurrent + 1;
				            if (oRotator.nIndexCurrent >=oRotator.nIndexTotalImage) {
					            oRotator.nIndexCurrent = 0;
				            }
				            oRotator.eRotate.src = oRotator.colPictures[oRotator.nIndexCurrent].src;
				            oRotator.nFadeIntervalCounter = oRotator.nFadeInterval;
				        }
				        else{
				            oRotator.nFadeIntervalCounter = oRotator.nFadeInterval;
				            oRotator.nIntervalPauseCounter = oRotator.nIntervalPause;    
				        }
				    }
				}
				else{
				    oRotator.nIndexCurrent = oRotator.nIndexCurrent + 1;
				    if (oRotator.nIndexCurrent >=oRotator.nIndexTotalImage) {
					    oRotator.nIndexCurrent = 0;
				    }
				    oRotator.eRotate.src = oRotator.colPictures[oRotator.nIndexCurrent].src;
				    oRotator.nIntervalPauseCounter = oRotator.nIntervalPause;
                }
			}
			else{
				oRotator.nIntervalPauseCounter = oRotator.nIntervalPauseCounter - 1;
				//if (oRotator.nIntervalPauseCounter == 8) this.stopEngine();
			}
		}
		//this.stopEngine();
	}
	
	function setRotateImage(eRotate){
		this.eRotate = eRotate;
	}
	
	function startEngine(sRotatorName){
		if (this.bEngineRunning != true){
			this.bEngineRunning = true;
			this.nIntervalEngine = window.setInterval(sRotatorName + '.engineLoop()', 1000/25)
		}
		else{
			this.stopEngine();
		}
		return false;
	}
	
	function stopEngine(){
		window.clearInterval(this.nIntervalEngine);
		this.bEngineRunning = false;
		return false;
	}
	
	function fadeImg(eImg){
	    if (!this.bFadePause){
	        if (this.bFadeIn){
	            this.nOpacity = this.nOpacity + 10;
	            eImg.style.opacity = this.nOpacity/100;
	            if (eImg.filters) eImg.filters.alpha.opacity = this.nOpacity;
	            this.bFadeIn = (this.nOpacity >= 100)?false:true;
	        }
	        else{
	            this.nOpacity = this.nOpacity - 10;
                eImg.style.opacity = this.nOpacity/100;
                if (eImg.filters) eImg.filters.alpha.opacity = this.nOpacity
	            this.bFadeIn = (this.nOpacity <= 0)?true:false;
	        }
        }
	}
}




function classCLMS_Markee(){
	this["bEngineRunning"] = false;
	this["colMarkees"] = new Object();
	this["eMarkee"] = null;
	this["nIndexTotal"] = 0;
	this["nIntervalEngine"] = 0;
	this["nWidth"] = 0;
	
	this.addMarkee = addMarkee;
	this.engineLoop = engineLoop;
	this.startEngine = startEngine;
	this.stopEngine = stopEngine;
	
	function addMarkee(eMarkee, nWidth){
		var oMarkee = new classCLMS_Markee()
		if(nWidth < eMarkee.parentNode.clientWidth){
			nWidth = eMarkee.parentNode.clientWidth;
		}		
		eMarkee.style.left = eMarkee.parentNode.clientWidth + 'px';
		oMarkee.nWidth = nWidth;
		oMarkee.eMarkee = eMarkee;
		this.colMarkees[this.nIndexTotal] = oMarkee;
		this.nIndexTotal = this.nIndexTotal + 1;
		return oMarkee;
	}
	
	function engineLoop(){
		var oMarkee;
		var nLeft;
		var nWidth;
		
		for (var i in this.colMarkees){
			oMarkee = this.colMarkees[i];
			nLeft = parseInt(oMarkee.eMarkee.style.left);
			nWidth = parseInt(oMarkee.eMarkee.clientWidth);
			
			if (nLeft < (- nWidth)){
				oMarkee.eMarkee.style.left = oMarkee.eMarkee.parentNode.clientWidth + 'px';
			}
			oMarkee.eMarkee.style.left = (parseInt(oMarkee.eMarkee.style.left) - 3) + 'px';
		}
		
		//this.stopEngine();
	}
			
	function startEngine(sMarkeeName){
		if (this.bEngineRunning != true){
			this.bEngineRunning = true;
			this.nIntervalEngine = window.setInterval(sMarkeeName + '.engineLoop()', 1000/32)
		}
		else{
			this.stopEngine();
		}
		return false;
	}
	
	function stopEngine(){
		window.clearInterval(this.nIntervalEngine);
		this.bEngineRunning = false;
		return false;
	}
	
}