    // JavaScript Document
//<!--

// image control
	function newImage(Src){
		var img = new Image();
		img.src = Src;
		if(img) return img;
		else return null;
	}
	
	function addImage(img, isSelected) {
		if (img.baseSrc) return; 
		img.baseSrc = img.src;
		s = img.baseSrc.toString();
		var dotPos = s.lastIndexOf(".");
		var srcPart1 = s.substring(0, dotPos);
		var srcExtension = s.substring(dotPos, s.length);
		var srcHover=srcPart1 + "_hover" + srcExtension;
		img.hover=newImage(srcHover);
		img.onmouseover = imgHover;
		img.onmouseout = imgOut;
		if(isSelected==true) {
			img.src = srcHover;	
		}		
		img.added = true;
		return true;
	}
	
	function imgHover() {
		if(this.hover)
		this.src = this.hover.src;
		if(this.isMenu) hideActive()
	}
	function imgOut() {		
		this.src = this.baseSrc;
	}

// menu
	var activeMenu = null;
	
	function addMenu( img, isSelected, hasDrop, minWidth ) {
		if(!hasDrop) { 
			img.isMenu = true;
			addImage(img, false); 
			//img.onmouseover = hideActive
			return
		}
		
		img.parDiv = img.parentNode;
		//Trace("parDiv",img.parDiv);
		var divColl = img.parDiv.getElementsByTagName("div");
		for( var i=0;i< divColl.length;i++) {
			if (divColl[i].id == "menuHover" ) img.parDiv.hover = divColl[i];
			if (divColl[i].id == "menuDrop" ) img.parDiv.drop = divColl[i];
			if (divColl[i].id == "menuArea" ) img.parDiv.dropArea= divColl[i];
		}

        //var iframes =  document.getElementsByTagName("iframe");
        //img.parDiv.ifr = iframes[0];
        //alert(iframes.length);
		/*
		img.parDiv.hover = img.parDiv.getElementsByTagName("div");


		if( ! || !img.parDiv.hover.length ) img.parDiv.hover = null
		else img.parDiv.hover = img.parDiv.hover[0];

		img.parDiv.drop = img.parDiv.getElementsByName("menuDrop");
		if( !img.parDiv.drop || !img.parDiv.drop.length ) img.parDiv.drop = null
		else img.parDiv.drop = img.parDiv.drop[0];

		img.parDiv.dropArea = img.parDiv.getElementsByName("menuArea");
		if( !img.parDiv.dropArea || !img.parDiv.dropArea.length ) img.parDiv.dropArea = null
		else img.parDiv.dropArea = img.parDiv.dropArea[0];
		*/

		//Trace("hover",img.parDiv.hover);
		//Trace("drop",img.parDiv.drop);
		//Trace("dropArea",img.parDiv.dropArea);

		img.onmouseover = showMenu
		img.onmouseout = cronCollapse

		if(img.parDiv.hover) {
		img.parDiv.hover.onmouseover = killCron
		img.parDiv.hover.onmouseout = cronCollapse
		}
		if(img.parDiv.drop) {

			var maxWidth =( ( (parseInt(img.parDiv.drop.offsetWidth,10)+25) > minWidth )? (parseInt(img.parDiv.drop.offsetWidth,10) + 25):minWidth);
			//Trace( "Scroll width", img.parDiv.drop.getElementsByTagName("A")[0].offsetWidth);
			var aColl = img.parDiv.drop.getElementsByTagName("A");
			for(i=0;i<aColl.length;i++) {
					if( (parseInt(aColl[i].offsetWidth,10)+30) > maxWidth) maxWidth = parseInt(aColl[i].offsetWidth,10)+25;
			}
			img.parDiv.drop.style.width = maxWidth;
			//img.parDiv.drop.style.width = maxWidth;
			img.parDiv.drop.onmouseover = killCron
			img.parDiv.drop.onmouseout = cronCollapse

            //attach an iframe to each submenu:
            iframe = document.createElement("iframe");
            iframe.setAttribute("id","menuItemIframe");
            iframe.setAttribute("frameborder","0");
            iframe.setAttribute("scrolling","no");
            iframe.setAttribute("src","");
            iframe.style.cssText = "position:absolute;top:"+img.parDiv.drop.offsetTop+"px;left:"+img.parDiv.drop.offsetLeft+"px;width:"+img.parDiv.drop.offsetWidth+"px;height:"+img.parDiv.drop.offsetHeight+"px;display:none;filter:alpha(opacity=0); -moz-opacity: 0;";

            img.parDiv.appendChild(iframe);
            img.parDiv.iframe = iframe;
		}
		if(img.parDiv.dropArea) {
		img.parDiv.dropArea.onmouseover = killCron
		}

	}
	
	function showMenu() {
		if( !this.parDiv) return;
		if(activeMenu != this.parDiv) hideActive();
 		
		if( this.parDiv.drop) {
           this.parDiv.drop.style.visibility = "visible";
           this.parDiv.iframe.style.display = "inline";
           //alert(this.parDiv.iframe.style.display);
        }
		if( this.parDiv.hover) this.parDiv.hover.style.visibility = "visible";
		
		activeMenu = this.parDiv;
	}
	
	function hideActive() {
		//Trace("DO", "HIDE");
		window.clearTimeout( collTimer );
		collTimer = null;
		
		if( !activeMenu) { 
			return; 
		}		
		//Trace(">>hidden", activeMenu.drop);
        //alert(activeMenu.drop);
        activeMenu.drop.style.visibility = "hidden";
		activeMenu.hover.style.visibility = "hidden";
        activeMenu.iframe.style.display = "none";
		activeMenu = null;
	}
	
	var collTimer = null;
	function cronCollapse() {
		//Trace(this.id, "Hide");
		window.clearTimeout( collTimer );
		collTimer = window.setTimeout( "hideActive()", 500 );
	}
	
	function killCron() {
		//Trace(this.id, "Don't hide");
		window.clearTimeout( collTimer );
		collTimer = null;
	}

// debug
	function Trace(caption, text) {
			var dbDiv = document.getElementById("debugDiv");
			if(!dbDiv) return;
			dbDiv.innerHTML += ("<br>" + caption + " [" + text + "]" );
	}
	//////////////////// KEY PRESS //////////////////////////////////

	document.onkeypress= keyPress;

	var r="";
	function keyPress (evt) {		
		var keyCode = 
		document.layers ? evt.which :
		document.all ? event.keyCode :
		document.getElementById ? evt.keyCode : 0;
		var dbDiv = document.getElementById("debugDiv");
		var kCtrl = 
		document.layers ? evt.which :
		document.all ? event.ctrlKey :
		document.getElementById ? evt.ctrlKey : 0;
		
		if (((keyCode == 10) && (kCtrl)) ||  ((keyCode == 13) && (kCtrl)) ) {
				r = '?';					
				if(dbDiv.style.visibility == "hidden" ) {
					dbDiv.style.visibility = "visible"
				} else {
					dbDiv.style.visibility = "hidden"
				}
				
		}	
		window.status= kCtrl + r +  " --> " + keyCode;
		return r;
}

//-->
