var imageControl;
function getImage(id,iName,w,h) {	
	//prevent more than one  image being open at the same time   
	//but let function take its course if an image is clicked twice
	if(imageControl && imageControl!=id){
		closeImage(imageControl);
	}
	imageControl=id;
	document.images[id].src=iName;
	FadeInImage(id,w,h);
}
function FadeInImage(id,w,h) {
	image = document.getElementById(id);
	image.style.display = (image.style.display == "block") ? "none":"block" ;
	div = document.getElementById(id +'d');
	div.style.display = (div.style.display == "block") ? "none":"block" ;
	if (image.style.display == "block"){		
		if(!w){
			var w=image.width;
		}
		if(!h){
			var h=image.height;
		}
		var i=0;
		var bh=browserHeight();
		var bw=browserWidth();
		//get position of top of window after scrolling
		if (navigator.appName == "Microsoft Internet Explorer"){
			var scrolledTo=document.documentElement.scrollTop;
		}else{
			var scrolledTo=window.pageYOffset;
		}
		//image is centered horizontally, and, if page height is less than window height
		//top of image is at top of window, othwerise it is centered vertically in the window
		var W=(bw-w)/2;	
		if (h<bh){
			var T =((bh-h)/2)+scrolledTo;
		}else{ 
			var T=scrolledTo;
		}
		//var n=Math.floor(Math.random()*2);
		scaleIn(T,W,i,w,h);
		setOpacity(image,0);
		fadeIn(id,0);
	}
}
function scaleIn(T,W,i,w,h){
	if (i <= 100) {
		imgWidth=i*w*0.01;
		imgHeight=i*h*0.01;
		var j=W+(w/2*(100-i)/100);				
		var k=T+(h/2*(100-i)/100);
		div.style.marginLeft=j + "px";			
		div.style.marginTop=k+ "px";
		div.style.width=imgWidth + "px";		
		div.style.height=imgHeight + "px";
		image.style.width=imgWidth + "px";		
		image.style.height=imgHeight + "px";
		i++;
		setTimeout("scaleIn("+T+","+W+","+i+","+w+","+h+")",1);	
	}	
}
//My thanks to Richard Rutter: clagnut.com/sandbox/imagefades.php/ for the following two functions.
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity ++;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 1);
		}
	}
}
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}
function closeImage(id){
	image = document.getElementById(id);
	div = document.getElementById(id +'d');
	image.style.display =  "none";
	div.style.display = "none";
}
function browserWidth() {
  var bw = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    bw = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    //IE 6+ in 'standards compliant mode'
    bw = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    bw = document.body.clientWidth;
  }
  return bw;
}
function browserHeight() {
  var bh = 0;
  if( typeof( window.innerHeight) == 'number' ) {
    //Non-IE
    bh = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight) ) {
    //IE 6+ in 'standards compliant mode'
    bh = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    bh = document.body.clientHeight;
  }
  return bh;
}

function FullPageSize(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		PageSize = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		PageSize = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		PageSize = document.body.offsetHeight;
  	}
	return PageSize;
}
function pup(pupped){	
	theframe = document.getElementById(pupped);
	theframe.style.display = (theframe.style.display == "block") ? "none":"block" ;
}
function closepup(pupped){	
	theframe = document.getElementById(pupped);
	theframe.style.display = "none" ;
}
//chose style
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

