/*****************************************************
 * ypSlideOutMenu
 * 3/04/2001
 * 
 * a nice little script to create exclusive, slide-out
 * menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
 * mac and win32. I've got no linux or unix to test on but 
 * it should(?) work... 
 *
 * --youngpup--
 *****************************************************/

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 500
ypSlideOutMenu.minCPUResolution = 10

isActive_menu1=0
isActive_menu2=0

var unself

var isNS = (navigator.appName == "Netscape");
var isMacIE = ( (navigator.userAgent.indexOf("IE 4") > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
var layerRef = (isNS) ? "document" : "document.all";
var styleRef = (isNS) ? "" : ".style";
var isDynamic = ( ((document.layers && document.layers['layerTest']) || (document.all && document.all['layerTest'])) && !isMacIE );

//temporary storage for x y pos
var xpos;
var ypos;

isIe  = document.all ? 1 : 0
isNs4 = document.layers ? 1 : 0
isDom = document.getElementById ? 1 : 0

function getXCoord(imgID) {        

	if (isNS) xPos = document.images[imgID].x;
	else xPos = getIEXCoord(imgID)
	return xPos;
}

function getYCoord(imgID) {
  	if (isNS) yPos = document.images[imgID].y;
  	else yPos = getIEYCoord(imgID);
  	return yPos;
}

function getIEXCoord(imgElem) {	
	
	if (typeof imgElem=='object' && imgElem){
		//alert("is object")
		xPos = eval(imgElem).offsetLeft;
		tempEl = eval(imgElem).offsetParent;
		while (tempEl != null) {
				xPos += tempEl.offsetLeft;
				tempEl = tempEl.offsetParent;
		}
		return xPos;		
		//window.status="is object";	
	
	}else{
		//alert("not object");
		xPos = document.getElementById(imgElem).offsetLeft
		tempEl = document.getElementById(imgElem).offsetParent
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		return xPos;
	}		
	
}



function getIEYCoord(imgElem) {
	if (typeof imgElem=='object' && imgElem){
        yPos = eval(imgElem).offsetTop;
        tempEl = eval(imgElem).offsetParent;
        while (tempEl != null) {
                yPos += tempEl.offsetTop;
                tempEl = tempEl.offsetParent;
        }
        return yPos;
        
     }else{
     
		yPos = document.getElementById(imgElem).offsetTop
		tempEl = document.getElementById(imgElem).offsetParent
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
     }
}











// constructor
function ypSlideOutMenu(id, dir, img, left,top, width, height)
{
	this.ie  = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0
	
	
	//Roy L 27.9.05 use the base item to calc where to put layer
	// makes menu appear at right place when page uses centering	

	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id
		this.dir		 = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
		this.dim		 = this.orientation == "h" ? width : height
		this.hideTimer	 = false
		this.aniTimer	 = false
		this.open		 = false
		this.over		 = false
		this.startTime	 = 0

		// global reference to this object
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")

		// add this menu object to an internal list of all menus
		ypSlideOutMenu.Registry[id] = this

		var d = document
		d.write('<style type="text/css">')
		d.write('#' + this.id + 'Container { visibility:hidden; ')		
		d.write('left:' + left + 'px; ')
		d.write('top:' + top + 'px; ')
		d.write('overflow:hidden; }')
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ')
		d.write('width:' + width + 'px; ')
		d.write('height:' + height + 'px; ')
		d.write('clip:rect(0 ' + width + ' ' + height + ' 0); ')
		d.write('}')
		d.write('</style>')
		
		
		
		this.load(img,left,top)
	}
}



ypSlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container	= obj1
		this.menu		= obj2
		this.style		= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos		= 0
		this.accelConst	= (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide()
	}
}


	
ypSlideOutMenu.showMenu = function(id,imgId,imageName,left,top)
{
	//window.status = id
	var reg = ypSlideOutMenu.Registry;
	var obj = ypSlideOutMenu.Registry[id];
	//window.status=parentId.style.left;
	//window.status=parentId.style.left;
	
	if(imageName){
		
		var xOffset = getXCoord(imgId);
		var yOffset = getYCoord(imgId);
		//window.status = "x=" + xOffset+ " y=" + yOffset;		
	 	xOffset += left;
	 	yOffset += top;
	
		//RL: change image src so that menu shows selected tab			
		document.images[imgId].src='/images/menu_tab_' + imageName + '_o.gif';
		//change
		if (imageName == 'prosedyrer'){
			isActive_menu1 = 1;
			document.images['prosedyrer_left'].src = '/images/menu_tab_left_gray.gif';
			document.images['separator'].src = '/images/menu_tab_gray_white_separato.gif';
			document.images['DropDownToolbarMenus1_ImageKrefttyper'].src = '/images/menu_tab_krefttyper.gif';
			document.images['krefttyper_right'].src = '/images/menu_tab_white_separato.gif';
		}else if (imageName=='krefttyper'){
			isActive_menu2 = 1;
			document.images['krefttyper_right'].src = '/images/menu_tab_gray_white_separato.gif';
			document.images['separator'].src = '/images/menu_tab_white_gray_separato.gif';
			document.images['prosedyrer_left'].src = '/images/menu_tab_left_white.gif';
			document.images['DropDownToolbarMenus1_ImageProsedyrer'].src = '/images/menu_tab_prosedyrer.gif';
		}else if (imageName == 'procedures'){
			isActive_menu1 = 1;
			document.images['prosedyrer_left'].src = '/images/menu_tab_left_gray.gif';
			document.images['separator'].src = '/images/menu_tab_gray_white_separato.gif';
			document.images['DropDownToolbarMenus1_ImageKrefttyper'].src = '/images/menu_tab_cancertypes.gif';
			document.images['krefttyper_right'].src = '/images/menu_tab_white_separato.gif';
		}else if (imageName=='cancertypes'){
			isActive_menu2 = 1;
			document.images['krefttyper_right'].src = '/images/menu_tab_gray_white_separato.gif';
			document.images['separator'].src = '/images/menu_tab_white_gray_separato.gif';
			document.images['prosedyrer_left'].src = '/images/menu_tab_left_white.gif';
			document.images['DropDownToolbarMenus1_ImageProsedyrer'].src = '/images/menu_tab_procedures.gif';
		}
				
		
		//alert(obj.style.left);
	//	alert(document.all["ypSlideOutMenu_"+id].left);
		//alert(ypSlideOutMenu.Registry[id].style.left); 
		//works//ypSlideOutMenu.Registry[id].style.left=200;
		//alert(document.all["menu1Container"].left);		
		//alert(ypSlideOutMenu.Registry[id].style.left);			
		
		xpos = xOffset;
		ypos=yOffset;
	
	}else
	{
		xOffset=xpos;		
		yOffset=ypos;		
	}
	
	
	//this will set the inner sliding box x pos   //debug pass  1
	ypSlideOutMenu.Registry[id].style.left=0; 	//debug pass 1
	
	//this will set the outer layer box x pos   //debug pass 2	
	//will create non critical error
	
	
	//alert(document.all[id+"Container"].style.left);
	//if (!xOffset) alert("xOffset is empty")
	
	document.all[id+"Container"].style.left = xOffset  //debug pass 2
	//alert("ok1")
	//if (typeof(document.all[id+"Container"].style)=='object') alert("okjhhhjj")
	document.all[id+"Container"].style.top=yOffset  //debug pass 2
	
	//alert("ok2")
	
	
	
	//document.all["menu1Container"].left=700;//xOffset;
		/*if (isNS) {         
		 	document[id].left = getXCoord(imageName) + left;
            document[id].top = getYCoord(imageName) + top;
        } else {	
		
		alert(this.style["top"]);
		
            document.all[id].style.pixelLeft = getXCoord(imageName) + left;
            document.all[id].style.pixelTop = getYCoord(imageName) + top;
        }
	*/
	
	
	
	if (obj.container) {
		obj.over = true

		// close other menus.
		for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
}



ypSlideOutMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
}



//fires when mouse over tab
ypSlideOutMenu.hide = function(id)
{
	var obj = ypSlideOutMenu.Registry[id]
	obj.over = false

	
	
	// flag that this scheduled event has occured.
	obj.hideTimer = 0

	if (obj.hideTimer){
		//gets here when we are about to hide a layer 
		window.clearTimeout(obj.hideTimer);	
	   //window.status="hideTimer";
	}else if (obj.open && !obj.aniTimer) {// if this menu is open, close it.
		obj.startSlide(false);
		 //window.status="obj hide";
	}
}


ypSlideOutMenu.prototype.startSlide = function(open,xOfs) {
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime()	
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-")		d = -d
		else if (this.open && this.dirType == "+")	d = -d
		else if (!this.open && this.dirType == "-")	d = -this.dim + d
		else										d = this.dim + d

		this.moveTo(d)
	}
}


//reset to hidden position
ypSlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
	
	//window.status="over="+this.over+" open="+this.open+" isActive_menu1="+isActive_menu1+" isActive_menu2="+isActive_menu2;
	
	
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden";
	//alert(this.id + "setVisibility =" + bShow)
	
	if (!bShow){
	if (isActive_menu1 ){
		//close menu
	//document.images['separator'].src = '/images/menu_tab_white_separato.gif';
	    if (this.id=='menu1') isActive_menu1=0;
//alert(' menu1 closed');
		}
		if (isActive_menu2 ){
			//close menu
			if (this.id=='menu2') {
				isActive_menu2=0;
				//show combobox if hidden
				obj = document.getElementById('_ctl3_ddKreftType');	
				if(obj){	
					obj.style.visibility = '';
				}	
				//alert('gg');
			}
		//document.images['separator'].src = '/images/menu_tab_white_separato.gif';
	//alert(' menu2 closed');
		}
	}
	
	
	//if (this.id=='menu1') isActive_menu1=0;
	//if (this.id=='menu2') isActive_menu2=0;
	
	
	if(!bShow){
		//reset onmouseoveer tabs
		
		if (this.id == 'menu1'){
			strImgSrc = document.images['DropDownToolbarMenus1_ImageProsedyrer'].src;
			document.images['prosedyrer_left'].src = '/images/menu_tab_left_white.gif';			
			//alert(document.images['DropDownToolbarMenus1_ImageProsedyrer'].src);
			if(strImgSrc.indexOf("procedures")>0){
	  	    	document.images['DropDownToolbarMenus1_ImageProsedyrer'].src = '/images/menu_tab_procedures.gif';
			}else{
			    document.images['DropDownToolbarMenus1_ImageProsedyrer'].src = '/images/menu_tab_prosedyrer.gif';
			}
			
		}else if (this.id == 'menu2'){	
			strImgSrc = document.images['DropDownToolbarMenus1_ImageKrefttyper'].src;				
			document.images['krefttyper_right'].src = '/images/menu_tab_white_separato.gif';
			if(strImgSrc.indexOf("cancertypes") > 0){
	  	    	document.images['DropDownToolbarMenus1_ImageKrefttyper'].src = '/images/menu_tab_cancertypes.gif';
			}else{
			    document.images['DropDownToolbarMenus1_ImageKrefttyper'].src = '/images/menu_tab_krefttyper.gif';
			}
		}
	}
	
			
	if ((!isActive_menu1 && !isActive_menu2)){
		//alert("rest");
		//window.status="over="+this.over+" open="+this.open+" bShow="+bShow+" isActive_menu1="+isActive_menu1+" isActive_menu2="+isActive_menu2;
		document.images['separator'].src = '/images/menu_tab_white_separato.gif';
	}
	
}







ypSlideOutMenu.prototype.moveTo = function(p) { 
	this.style[this.orientation == "h" ? "left" : "top"] = p
}


ypSlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}



