﻿function openMenu(elem,stat) {
	var menuElem = document.getElementById(elem);
	
	switch(stat) {
		case 'on':
			menuElem.style.display = 'block';
			break;
		case 'alive':
			menuElem.style.display = 'block';
			break;
		case 'off':
			menuElem.style.display = 'none';
			break;
	}
	
}


function fadeButtons(){

}

function ShowImagePopup(imgName, title){   
   // var elModalPopup = document.getElementById("ModalPopupContainer");
    var elImgTitle = document.getElementById("ImgTitle");
    var elImgPopup = document.getElementById("ImgPopup");     
    elImgPopup.src = imgName;
    elImgTitle.innerHTML = title;
    setTimeout("FloatDivInCenter('ModalPopupContainer','ModalLayer')", 100);  
    
    //because ie6 is stupid and cant have layers over dropdown inputs
    if(isIE6 = /msie|MSIE 6/.test(navigator.userAgent)){
        document.getElementById("WidgetIFrame").style.display = "none";
        document.getElementById("ImgWidgetIFrame").style.display = "block";    
    }
}

function HideImagePopup(){
    var elModalLayerPopup = document.getElementById("ModalPopupContainer");
    var elModalLayer = document.getElementById("ModalLayer");
    var elImgPopup = document.getElementById("ImgPopup");
    
    elModalLayerPopup.style.visibility = elModalLayer.style.visibility = "hidden";
    clearTimeout(stayCenterTimeoutID);
    
    if(isIE6 = /msie|MSIE 6/.test(navigator.userAgent)){
        document.getElementById("WidgetIFrame").style.display = "block";
        document.getElementById("ImgWidgetIFrame").style.display = "none";    
    }
}

function getScrollXY(){
  var scrOfX=0, scrOfY=0;
  if(typeof(window.pageYOffset)=='number'){
    //Netscape compliant
    scrOfY=window.pageYOffset;
    scrOfX=window.pageXOffset;
  }else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){
    //DOM compliant
    scrOfY=document.body.scrollTop;
    scrOfX=document.body.scrollLeft;
  }else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){
    //IE6 standards compliant mode
    scrOfY=document.documentElement.scrollTop;
    scrOfX=document.documentElement.scrollLeft;
  }
  return [scrOfX,scrOfY];
}

function getSize() {
  var W=0, H=0;
  if(typeof(window.innerWidth)=='number'){
    //Non-IE
    W=window.innerWidth;
    H=window.innerHeight;
  }else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
    //IE 6+ in 'standards compliant mode'
    W=document.documentElement.clientWidth;
    H=document.documentElement.clientHeight;
  }else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){
    //IE 4 compatible
    W=document.body.clientWidth;
    H=document.body.clientHeight;
  }
  return [W,H];
}


function centerElement(elem, parentID) {
//Centers and element withing the parent element
//If parentID is null it will center the element within the document
//by DR

    var d = document;    
    if (parentID) {
        var parentEl = d.getElementById?d.getElementById(parentID):d.all?d.all[parentID]:d.layers[parentID];         
        intW = parentEl.offsetWidth;
        intH = parentEl.offsetHeight;        
    }else {
       intW = getSize()[0];     
       intH = getSize()[1]; 
    }
        
    var left = parseInt((intW - elem.offsetWidth) / 2, 10);
    var top =  parseInt((intH - elem.offsetHeight) / 2, 10);

    //ie6 fix
    if(isIE6 = /msie|MSIE 6/.test(navigator.userAgent))
        elem.style.left = (left + 305) + 'px';
    else
        elem.style.left = (left) + 'px';
        
    elem.style.top = (top )  + 'px';

    parentEl = left = top = elem = null;
}

var stayCenterTimeoutID;

function FloatDivInCenter(id, parentID)
{  
//Keeps element centered on page
//Tested and works on IE6, IE7, Safari, and FF2
//fixed to work on multiple browsers by DR
//Be sure to clear the timeout using timeoutid "stayCenterTimeoutID" 

	var startY = 250;
	var d = document;
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	
	centerElement(el, parentID);
	document.getElementById("ModalPopupContainer").style.visibility = document.getElementById("ModalLayer").style.visibility = "visible";
	function ml(id)
	{		
		if(d.layers)el.style=el;		
		el.sP=function(y){this.style.top=y + 'px';};
		el.y = Math.floor(getScrollXY()[1]+getSize()[1]/2)-50;
		el.y -= startY;
		return el;
	}
	window.stayCenter=function()
	{
		var pY = Math.floor(getScrollXY()[1]+getSize()[1]/2 )-50;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.y);
		stayCenterTimeoutID = setTimeout("stayCenter()", 10);		
	}
	ftlObj = ml(id);
	stayCenter();
}

