// JavaScript Document

//Screen Dimensions for IE and Everything Else
function screenDimensions(){
	if(window.innerHeight !==undefined)A= [window.innerWidth,window.innerHeight,window.pageYOffset]; // good browsers
	else{ // IE
	var D=document.documentElement;
	A= [D.clientWidth,D.clientHeight,D.scrollTop];
	}
	return A;
} 

function mouseOver(prefix)
{
document.getElementById("footerEmailElement").src=prefix + "images/footerEmailHover.gif";
}
function mouseOut(prefix)
{
document.getElementById("footerEmailElement").src=prefix + "images/footerEmail.gif";
}

function popImg(vis, imageSource, h, w) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.

  var height= parseInt(h) + 100;
  var width= parseInt(w) + 100;
  
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 50;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  var imgDiv=document.getElementById('imgDiv');
  var popupImage = document.getElementById('popupImage');
  var loadingImg = document.getElementById('loadingImg');
  var img            = new Image();
  
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    	tbody.appendChild(tnode);                            // Add it to the web page
    	dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if(!imgDiv) {
		      // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='imgDiv';                   // Name it so we can find it later
    	tbody.appendChild(tnode);                            // Add it to the web page
    	imgDiv=document.getElementById('imgDiv');  // Get the object.
  }
  if(!loadingImg) {
	var tbody = document.getElementsByTagName("body")[0];
	var tnode = document.createElement('img');
	tnode.style.position='absolute';
	tnode.style.overflow='hidden';
	tnode.style.display='none';
	tnode.id='loadingImg';
	tbody.appendChild(tnode);
	loadingImg=document.getElementById('loadingImg');
  }
  if(!popupImage) {
	// The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];

    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='popupImage';                   // Name it so we can find it later
		//tnode.style.backgroundColor='#CCC';
    	tbody.appendChild(tnode);                            // Add it to the web page
    	popupImage=document.getElementById('popupImage');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth;
        var pageHeight = document.body.scrollHeight;
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth;
      var pageHeight = document.body.offsetHeight;
    } else {
       var pageWidth = document.body.width;
       var pageHeight= document.body.height;
    }   
  	var A = screenDimensions();
	var myWidth=A[0];
	var myHeight=A[1];
	
    //set the shader to cover the entire page and make it visible.
	dark.style.top='0px';                          
    dark.style.left='0px';                          
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth + 'px';
    dark.style.height= pageHeight + 'px';
    dark.style.display='block';      
	
	// The white container
	
	// first lets do some math
	//window.alert("height = " + myHeight);
	var top= parseInt(myHeight) / 2 ;
	top = top - parseInt(height/2) ;
	top = parseInt(top) + A[2];
	
	imgDiv.style.height= height+'px';                           // make sure it's smaller than the website.  
    imgDiv.style.width=width+'px';                          // We'll center it in a bit
	imgDiv.style.zIndex=zindex+1;    
	imgDiv.style.top= top + 'px';     
    imgDiv.style.left= parseInt(pageWidth / 2) - parseInt(width / 2)  + 'px';       
	imgDiv.style.backgroundColor='#fff';
	imgDiv.style.border='1px solid #333';
	imgDiv.style.display='block';
	
	
	// The Loading Amination...
	loadingImg.style.height=100 + 'px';
	loadingImg.style.width=150 + 'px';
	loadingImg.style.zIndex=zindex+3;
	loadingImg.style.top= myHeight / 2 - 50 + A[2] + 'px';
	loadingImg.style.left= pageWidth / 2 - 75 + 'px';	
	loadingImg.style.backgroundcColor='#333';
	loadingImg.src='../images/loading.gif';
	//loadingImg.style.border='1px solid #000';
	loadingImg.style.display='block';
	
	// The Image
	popupImage.style.top= myHeight / 2 - parseInt(h / 2) + A[2]  +  'px';
    popupImage.style.left= pageWidth / 2 - parseInt(w/2) + 'px';     
	popupImage.style.zIndex=zindex+4;
    popupImage.style.height=h + 'px';                           // make sure it's smaller than the website.  
    popupImage.style.width=w + 'px';                          // We'll center it in a bit
    img.src        = imageSource;
	//popupImage.src=imageSource;
	popupImage.style.backgroundImage  = "url("+img.src+")";
	popupImage.style.display='block';
	
	
	//popupImage.onmousedown= popImg(false, '', 0, 0);
	
	var unGray = document.getElementById('unGray'); 
		unGray.style.display='block';
		unGray.style.zIndex='63';
		unGray.style.position='absolute';
		unGray.style.top= (myHeight / 2 + height / 2 + A[2]) - 30 + 'px';
		unGray.style.left=pageWidth/2 + width/2 - 55 + 'px';
		unGray.style.cursor='pointer';
  } else {
     dark.style.display='none';
	 imgDiv.style.display='none';
	 popupImage.style.display='none';
	 //popupImage.src="";
	 img.src='none';
	 popupImage.style.backgroundImage='none';
	 popupImage.style.top=50000 + 'px';
	 loadingImg.style.display='none';
	 var closeThis = document.getElementById('unGray');
	 closeThis.style.display='none';
  }
}

function hideLoad() {
	document.getElementById('loadingImg').style.display='none';	
}

function getImageHeight(imgSrc)
{
	var newImg = new Image();
	newImg.src = imgSrc;
	return newImg.height;
}

function getImageWidth(imgSrc)
{
	var newImg = new Image();
	newImg.src = imgSrc;
	return newImg.width;
}
