/*********************************************************************
*
* Kate Whitworth Javascript Functions
*
* Copyright 2008 Sonassi Media Services.
* This Code remains property of Sonassi Media Services.
* For more information, please visit http://www.sonassi.com/terms/
* ===================================================================/
*/
  
// Replaces target="_new" with XHTML compliant code
function externalLinks()
{
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++)
  {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
  }
}
window.onload = externalLinks;

// Imagebox code
function showphoto(img) {
  document.getElementById("actphoto").innerHTML = "<div style='width:100%;text-align:center;'><img onclick=\"closeDiv('photo')\" style='cursor:pointer;margin:0px auto;' src='/images/portfolio/" + img + "' alt='Image' /></div>";
  
  height = 475;
  width = 725;
  document.getElementById("photo").style.width = width+30 + "px";
  document.getElementById("photo").style.height = height+60 + "px";
  centerDiv('photo',height+60,width+30);
  document.getElementById("photo").style.display = "inline";
  changeOpac(10,'wrapper','down');
}

function closeDiv(div) {
  document.getElementById(div).style.display = "none";
  if (document.getElementById("photo").style.display != "inline") {
    changeOpac(100,'wrapper','up');  
  } else {  
    changeOpac(100,'photo','up');  
  }
}

function centerDiv(name,height,width) {
  document.getElementById(name).style.top = (scrollOffsetTop()+(windowHeight()-(height))/2) + "px";
  document.getElementById(name).style.left = ((windowWidth()/2)-(width)/2) + "px";   
}

//change the opacity for different browsers
function changeOpac(opacity, id, direction) {
	var object = document.getElementById(id).style; 
	if( opacity == 1 & direction == "down") {
   	document.getElementById(id).style.display = "none";
	}
	
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if ( opacity == 1 & direction == "up" ) {
  	document.getElementById(id).style.display = "inline";
	}
}

function scrollOffsetTop() {
  var y;
  if (self.pageYOffset) // all except Explorer
  {
  	y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  	// Explorer 6 Strict
  {
  	y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
  	y = document.body.scrollTop;
  }  
  return y;
}
function scrollOffsetLeft() {
  var x;
  if (self.pageYOffset) // all except Explorer
  {
  	x = self.pageXOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  	// Explorer 6 Strict
  {
  	x = document.documentElement.scrollLeft;
  }
  else if (document.body) // all other Explorers
  {
  	x = document.body.scrollLeft;
  }  
  return x;
}

function pageHeight() {  
  var y;
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight
  if (test1 > test2) // all but Explorer Mac
  {
  	y = document.body.scrollHeight;
  }
  else // Explorer Mac;
       //would also work in Explorer 6 Strict, Mozilla and Safari
  {
  	y = document.body.offsetHeight;
  }
  return y;
}    
function pageWidth() {  
  var x;
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight
  if (test1 > test2) // all but Explorer Mac
  {
  	x = document.body.scrollWidth;
  }
  else // Explorer Mac;
       //would also work in Explorer 6 Strict, Mozilla and Safari
  {
  	x = document.body.offsetWidth;
  }
  return x;
}    
function windowHeight() {
  var y;
  if (self.innerHeight) // all except Explorer
  {
  	y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  	// Explorer 6 Strict Mode
  {
  	y = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
  	y = document.body.clientHeight;
  }
  return y;     
}
function windowWidth() {
  var x;
  if (self.innerHeight) // all except Explorer
  {
  	x = self.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  	// Explorer 6 Strict Mode
  {
  	x = document.documentElement.clientWidth;
  }
  else if (document.body) // other Explorers
  {
  	x = document.body.clientWidth;
  }    
  return x;     
}

