function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  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;
  }
 // window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 return myHeight;
}
function matchHeight() {
	 var divs,contDivs,maxHeight,divHeight,d;
	 
	 var sourceDiv = window.document.getElementById('content-main');
	 // alert(sourceDiv);
	 
     var targetDivLeft = window.document.getElementById('content-left');
	 var targetDivRight = window.document.getElementById('content-right');
	
	 		
	var maxHeight;
	if (sourceDiv.offsetHeight) {
		maxHeight = sourceDiv.offsetHeight;
	} else if (sourceDiv.pixelHeight) {
		maxHeight = sourceDiv.pixelHeight;
	}
	// alert (maxHeight);	 
	
	var winHeight = getWindowHeight();
	if (winHeight > maxHeight) {
		maxHeight= winHeight;
		sourceDiv.style.height = maxHeight+'px';
	}
	
    
	
	targetDivLeft.style.height = maxHeight+'px';
	
	if (targetDivRight) {
		targetDivRight.style.height = maxHeight+'px';
	}
	 
	 
	 	
	targetDivLeft.style.visibility = "visible";
	
	if (targetDivRight) {
		targetDivRight.style.visibility = "visible";
	}
	
	//window.document.geElementById('content-main').style.visibility = "visible";
	//window.document.geElementById('content-body').style.visibility = "visible";
 
}

function matchHeight2() {
	 var divs,contDivs,maxHeight,divHeight,d;
	 
	 var sourceDiv = window.document.getElementById('content-main');
	 // alert(sourceDiv);
	 
     var targetDivLeft = window.document.getElementById('content-left');
	 var targetDivRight = window.document.getElementById('content-right');
	 
	 
	 
	 // ALL DIVS MAX
	  var divs,contDivs,maxHeight,divHeight,d;
	 divs=document.getElementsByTagName('div');
	 contDivs=[];
	 maxHeight=0;
	 for(var i=0; i<divs.length; i++){
		   if(divs[i].className == 'column') {
				d=divs[i];
				contDivs[contDivs.length]=d;	 
				if(d.offsetHeight){
					 divHeight=d.offsetHeight;
				}
				else if(d.style.pixelHeight){
					 divHeight=d.style.pixelHeight;
				}
				maxHeight=Math.max(maxHeight,divHeight);  		         
		  }             
	 }
	
	 		
	//if (sourceDiv.offsetHeight) {
	//	maxHeight = sourceDiv.offsetHeight;
	//} else if (sourceDiv.pixelHeight) {
	//	maxHeight = sourceDiv.pixelHeight;
	//}
	// alert (maxHeight);	 
	
	//var winHeight = getWindowHeight();
	//if (winHeight > maxHeight) {
	//	maxHeight= winHeight;
	//	sourceDiv.style.height = maxHeight+'px';
	//}
	
    
    sourceDiv.style.height = maxHeight + 'px';
	
	targetDivLeft.style.height = maxHeight+'px';
	
	if (targetDivRight) {
		targetDivRight.style.height = maxHeight+'px';
	}
	 
	 
	 	
	targetDivLeft.style.visibility = "visible";
	
	if (targetDivRight) {
		targetDivRight.style.visibility = "visible";
	}
	
	//window.document.geElementById('content-main').style.visibility = "visible";
	//window.document.geElementById('content-body').style.visibility = "visible";
 
}



function getHeight(d) {
	//  alert(d.offsetHeight);
	
	if (d.offsetHeight != undefined) {
		 return d.offsetHeight;
	} else if (d.style.pixelHeight) {
		 return d.style.pixelHeight;
	}
}
function getWidth(d) {
	//  alert(d.offsetHeight);
	if (d.offsetWidth) {
		 return d.offsetWidth;
	} else if (d.style.pixelWidth) {
		 return d.style.pixelWidth;
	}
}
function getMaxHeight () {
 	var divs,contDivs,maxHeight,divHeight,d;
	 divs=document.getElementsByTagName('div');
	 contDivs=[];
	 maxHeight=0;
	 for(var i=0; i != divs.length; i++) {
		   if (divs[i].className == 'column') {
				d=divs[i];
				contDivs[contDivs.length]=d;	 
				if(d.offsetHeight){
					 divHeight=d.offsetHeight;
				}
				else if(d.style.pixelHeight){
					 divHeight=d.style.pixelHeight;
				}
				maxHeight=Math.max(maxHeight,divHeight);  		         
		  }             
	 }
	 return maxHeight;
}

function makeVisible () {
 	var divs,contDivs,maxHeight,divHeight,d;
	 divs=document.getElementsByTagName('div');
	 contDivs=[];
	 maxHeight=0;
	 for(var i=0; i != divs.length; i++) {
		   if (divs[i].className == 'layout') {
				d=divs[i];
				d.style.visibility = "visible";
		  } else if (divs[i].className == 'column') {
		  		d=divs[i];
				d.style.visibility = "visible";
		  }
	 }
	 return;
}
function getPortalWidth () {
	if (window.document.body.clientWidth) {
	 	// alert('clientWidth='+ window.document.body.clientWidth);
		return window.document.body.clientWidth;
	} else if (window.innerWidth) {
		//alert('inner='+window.innerWidth);
		return window.innerWidth;
	}
}
function resizeLayout () {
	var leftColumn = window.document.getElementById('left-column');
	var rightColumn = window.document.getElementById('right-column');
	var middleColumn = window.document.getElementById('middle-column');
	var footer = window.document.getElementById('footer');
	var maxHeight = getMaxHeight();
	var footerTop = 130 + maxHeight + 6;
	window.document.getElementById('footer').style.top = footerTop+'px';

	var minWidth = getWidth(rightColumn) + getWidth(middleColumn) + getWidth(rightColumn) + 30;
	// alert (minWidth);
	// var minWidth = 1000;
	var portalWidth = getPortalWidth();
	
	var right = Math.max(minWidth, portalWidth);

	/*
		The math is:
		The right column starts at the right side of the page,
		minus the width of the rightColumn
		then antoerh 
	*/
	// var margins = rightColumn.style.marginLeft + rightColumn.style.marginRight;
	// alert(margins);
	rightColumn.style.left = (right - getWidth(rightColumn) -10)+'px';
	
	/* 
	*/
	var minPos = getWidth(leftColumn) + 20;
	var middle = (portalWidth / 2) - (getWidth(middleColumn) /2);
	middleColumn.style.left = Math.max(minPos, middle)+'px';
	footer.style.left = middleColumn.style.left;
	makeVisible();
}
function adjustLayout () {
	window.onresize = resizeLayout;
	var header = window.document.getElementById('header');
	
	/* Adjust header column to content */
	var headerContent = window.document.getElementById('header-wrapper');
	var header = window.document.getElementById('header');
	header.style.height = getHeight(headerContent)+'px';
	
	/* Adjust left column to content */
	var leftColumnContent = window.document.getElementById('left-column-wrapper');
	var leftColumn = window.document.getElementById('left-column');
	leftColumn.style.height = getHeight(leftColumnContent)+'px';
	
	/* Adjust right columnt to content */
	var rightColumnContent = window.document.getElementById('right-column-wrapper');
	var rightColumn = window.document.getElementById('right-column');	
	rightColumn.style.height = getHeight(rightColumnContent)+'px';
	
	/* Adjust middle columnt to content */	
	//var middleColumnContent = window.document.getElementById('middle-column-wrapper');
	//var middleColumn = window.document.getElementById('middle-column');
	//middleColumn.style.height = getHeight(middleColumnContent)+'px';
	
	
	
	/* Adjust footer to content */
	var footerContent = window.document.getElementById('footer-wrapper');
	var footer = window.document.getElementById('footer');
	footer.style.height = getHeight(footerContent)+'px';
	
	
	var maxHeight = getMaxHeight();
	
	//leftColumn.style.height = maxHeight+'px';
	//middleColumn.style.height = maxHeight+'px';
	//rightColumn.style.height = maxHeight+'px';
	
	// Now the footer
	// 130 is the top of all columns.
	// 6 is fake padding.
	var footerTop = 130 + maxHeight + 6;
	window.document.getElementById('footer').style.top = footerTop+'px';
	
	
	/*
		Okay, fancy stuff. Try to put the right column on the right of the page...
	*/
	resizeLayout();
	window.onresize = resizeLayout;
}

function doOnLoad () {
	adjustLayout();
	// imageAnimationOnload();	
}



window.ADAPT = {};
// Preloaded images

window.ADAPT.imageSets = new Object();




function preload (imageSetName) {
	
		var images = ADAPT.imageSets[imageSetName];
		var len2 = images.length;
		for (var k = 0; k < len2; k++) {
			var temp = new Image();
			temp.src = images[k];
		}
}

function nextImage(time, imageSetName, i) {
	var images = ADAPT.imageSets[imageSetName];
	if ((images == null) || (images == undefined)) {
		alert("Image set '"+imageSetName+"' was not defined.");
		return;
	}
	var len = images.length;
	if (i >= len) {
		i = 0;
	}
	var e = document.getElementById(imageSetName);
	
	if (e == null) {
		// alert("The image '"+imageSetName+"' is null.");
		return;
	}
	e.src = images[i];
	i++;
	var script = "nextImage("+time+", '"+imageSetName+"', "+i+")";
	// alert("script is '"+script+"'");
	var timer = setTimeout(script, time);
}

// Reusable timer

function timeimgs(numb)
{
  thetimer = setTimeout("imgturn('" +numb+ "')", 1000);
}

// Reusable image turner

function imgturn(numb)
{
  if (document.images)
  {
	// This will loop the image
	if (numb == "3")
	{
	  document["demo"].src = eval("demo3.src");
	  timeimgs('1');
	}
	else
	{
	  document["demo"].src = eval("demo" + numb + ".src");
	  timeimgs(numb = ++numb);
	}
  }
}





function imageAnimationOnload () {
	ADAPT.imageSets.powerlogo = ["/i/animations/powerlogo-blue.png", "/i/animations/powerlogo-green.png", "/i/animations/powerlogo-red.png"];
	nextImage(1000, "powerlogo", 0);
}

function getURLParam( name )
		{
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var regexS = "[\\?&]"+name+"=([^&#]*)";
		  var regex = new RegExp( regexS );
		  var results = regex.exec( window.location.href );
		  if( results == null )
			return "";
		  else
			return results[1];
		}

