//(C) Stephen Daly
// www.stephendaly.org
// Date: 11/3/2008

// Checks if the browsers is IE or another.
// document.all will return true or false depending if its IE
// If its not IE then it adds the mouse event
//if (!document.all)
//document.captureEvents(Event.MOUSEMOVE)

// On the move of the mouse, it will call the function getPosition
//document.onmousemove = getPosition;

// These varibles will be used to store the position of the mouse
//var X = 0
//var Y = 0

// This is the function that will set the position in the above varibles 
/*function getPosition(args) 
{
  // Gets IE browser position
  if (document.all) 
  {
    X = event.clientX + document.body.scrollLeft
    Y = event.clientY + document.body.scrollTop
  }
  
  // Gets position for other browsers
  else 
  {  
    X = args.pageX
    Y = args.pageY
  }  
}*/

var viewportwidth;
var viewportheight;

function setViewport()
{
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof document.body.clientWidth != 'undefined')
	{
		viewportwidth = document.body.clientWidth;
		viewportheight = document.body.clientHeight;
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	
	// older versions of IE
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	
	if(window.innerHeight < viewportheight)
	{
		if(navigator.appName == "Microsoft Internet Explorer")
			document.getElementById('backgroundFilter').style.height = viewportheight + 50 + "px";
		else
			document.getElementById('backgroundFilter').style.height = viewportheight + "px";
	}
	else
	{
		if(navigator.appName == "Microsoft Internet Explorer")
			document.getElementById('backgroundFilter').style.height = document.documentElement.clientHeight + "px";
		else
			document.getElementById('backgroundFilter').style.height = window.innerHeight + "px";
	}
}


function backgroundFilter()
{
    var div;
    setViewport();
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('backgroundFilter'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['backgroundFilter']; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&div.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the background is hidden ('none') then it will display it ('block').
    // If the background is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
}

function popUp(winWidth, winHeight, windowName)
{
    var div;
    setViewport();
    
    if(window.innerHeight < viewportheight)
    {
		if(navigator.appName == "Microsoft Internet Explorer")
			window.scrollTo(0, (viewportheight - document.documentElement.clientHeight) / 2);
		else
			window.scrollTo(0, (viewportheight - window.innerHeight) / 2);
	}
	else
	{
		if(navigator.appName == "Microsoft Internet Explorer")
			viewportheight = document.documentElement.clientHeight;
		else
			viewportheight = window.innerHeight;
	}
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById(windowName); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all[windowName]; 
    
    // Set width and height of the div
	div.style.width = winWidth + "px";
    div.style.height = winHeight + "px";
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
    
    // Off-sets the X position by 15px
    //X = X + 15;
    
    // Sets the position of the DIV
    var centerWidth = viewportwidth / 2;
    var centerHeight = viewportheight / 2;
    var X = centerWidth - (winWidth / 2);
    var Y = centerHeight - (winHeight / 2);
    div.style.left = X + 'px';
    div.style.top = Y + 'px';
}

setViewport();