//(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
var scrOfX = 0
var scrOfY = 0
var myWidth = 0
var myHeight = 0
var imageHeight = 0
var imageWidth = 0

// This is the function that will set the position in the above varibles 
function getPosition(args) 
{

  // Gets IE browser position
  if (document.all) 
  {
	if(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined") {
		// IE 7 is being used
		X = event.clientX + document.documentElement.scrollLeft
    	Y = event.clientY + document.documentElement.scrollTop
	} else {
   	 	X = event.clientX + document.body.scrollLeft
    	Y = event.clientY + document.body.scrollTop
	}
  }
  
  // Gets position for other browsers
  else 
  {  
    X = args.pageX
    Y = args.pageY
  }  
}
function backgroundFilter()
{
    var div;
    
    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']; 
	
	var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight
	_docHeight += 100;
	div.style.height = _docHeight +"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&&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 getScrollXY() {
  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;
  }
}

function windowSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}

function getImageSize(pic) {
   image = new Image();
   image.src = "../images/"+pic;
   if(image.complete) {
   imageWidth = image.width;
   imageHeight = image.height;
   imageHeight = imageHeight + 30;
   } else {
   imageWidth = 700;
   imageHeight = 500;
   }
}
function popUp(img)
{
    var div;
	var innerDiv;
	var topLeftDiv;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('popupWindow'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['popupWindow']; 
	
	if(document.getElementById)
    // Standard way to get element
    topLeftDiv = document.getElementById('topLeft'); 
    else if(document.all) 
    // Get the element in old IE's 
    topLeftDiv = document.all['topLeft'];
	// set topleftdiv to 0 - this is needed!!!
	topLeftDiv.style.width = 0+'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 and Y position by -150px and -200px
    X = X - 150;
	Y = Y - 350;
    
    // Sets the position of the DIV
    //div.style.left = X+'px';
    //div.style.top = Y+'px';
	windowSize();
	getScrollXY();
	// get the image width
	getImageSize(img);
	// Work out centre of the screen
	var windowX = 0;
	windowX = windowX + ((myWidth - imageWidth) / 2) + scrOfX;
	div.style.left = windowX+'px';
    div.style.top = scrOfY+'px';
	
	// Set the content of popupBody to the current picture
	if(document.getElementById)
    // Standard way to get element
    innerDiv = document.getElementById('popupBody'); 
    else if(document.all) 
    // Get the element in old IE's 
    innerDiv = document.all['popupBody']; 
	//set popupBody size to image size
	innerDiv.innerHTML="<img src='../images/"+img+"'>";
	if(div.style.display == "block") {
		var currentDivWidth = innerDiv.offsetWidth;
		if(currentDivWidth < 50) {
			currentDivWidth = 700;
		} else {
		currentDivWidth = currentDivWidth-23;
		}
		topLeftDiv.style.width = currentDivWidth+'px';
	}
}

