function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){if(oldonload){oldonload();}func();}}}function updateCSS(){document.getElementById('screenview').href='/css/print.css';window.print();}function restoreCSS(){document.getElementById('screenview').href='/css/all.css';}
// 
//********************************** popup ********************************** //
// 
var flag=1;
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getClientCenterX()
{
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1];
		var wid=document.body.scrollWidth;

	return parseInt(wid/2);
}
function getClientCenterY()
{
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1];
		var wid=document.body.scrollWidth;

	return parseInt(hei/2)+getBodyScrollTop();
}
	function openPopup()
		{
		var width=680;
		var height=520;
		
		var arrayPageSize = getPageSize();
		var hei=arrayPageSize[1]-4;
		var wid=document.body.scrollWidth;

		var half_width=width/2;
		var half_height=height/2;

		document.getElementById('shaded').style.height=hei+"px";
		document.getElementById('shaded').style.width=wid+"px";

		if((getClientCenterY()-half_height)>0) var tp=170;

		document.getElementById('infoiframe_div').style.top=tp+"px";
		document.getElementById('infoiframe_div').style.left=(getClientCenterX()-half_width)+"px";

		document.getElementById('infoiframe_div').style.width=width+"px";
		document.getElementById('infoiframe_div').style.height="auto";
		document.getElementById('shaded').className="shaded_vis";
		document.getElementById('infoiframe_div').className="infoiframe_visible";
		}
	function closepopup()
		{
			document.getElementById('shaded').className="shaded_hid";
			document.getElementById('infoiframe_div').className="infoiframe_hidden";
		}
// 
//********************************** fontsize-controller ********************************** //
// 
var fontsizes=new Array;
var currentSize=3;

fontsizes[1]=9;
fontsizes[2]=11;
fontsizes[3]=13;
fontsizes[4]=15;
fontsizes[5]=17;
addLoadEvent(function() {   

});
function setSize(num){
var cont=document.getElementById('fontarea');
if(cont && fontsizes[num])
	{
var parags=cont.getElementsByTagName("P");
for(var i=0; i<parags.length; i++) {
		parags[i].style.fontSize=fontsizes[num]+"px";
		//#if(num==4 || num==5)
		parags[i].style.lineHeight=(fontsizes[num]+3)+"px";
	}


var litags=cont.getElementsByTagName("LI");
for(var i=0; i<litags.length; i++) {
		litags[i].style.fontSize=fontsizes[num]+"px";
		//#if(num==4 || num==5)
		litags[i].style.lineHeight=(fontsizes[num]+3)+"px";
	}



var htwo=cont.getElementsByTagName("H2");
for(var i=0; i<htwo.length; i++) {
		htwo[i].style.fontSize=(fontsizes[num]+2)+"px";
	}

	}

			var now = new Date()			
			now.setTime(now.getTime()+ 12*31*24*60*60*1000);
			expires=now;

			setCookie("brainsize",num,expires,"/");
}


function doNextSize(){
if(currentSize<5) { currentSize=currentSize+1;} else currentSize=5;
setSize(currentSize);
}

function doPrevSize(){
if(currentSize>1) { currentSize=currentSize-1;} else currentSize=1;
setSize(currentSize);
}


var path = "/";
var domain = "";
var expires="18000";
var secure=false;

var caution=false;

function setCookie(name, value, expires, path, domain, secure) {
 var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
  {
  //alert(curCookie);
                document.cookie = curCookie
  }
        else
                        document.cookie = curCookie
}
//********************************** Reding ********************************** //
function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return '';
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

//********************************** Deleting ********************************** //
function deleteCookie(name, path, domain) {
//alert(path);
        if (getCookie(name)) {
                document.cookie = name + "=" + 
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
        }
}
// 
//********************************** slide-selector ********************************** //
// 
var currentSlide=1;
var timer;
var slides=new Array();
var textes=new Array();
var slidelinks=new Array();

slides[1]='slides-1.jpg';
slides[2]='slides-2.jpg';
slides[3]='slides-3.jpg';

textes[1]='<a href="../work-smarter-not-harder.html">Work Smarter,<br />Not Harder</a>';
textes[2]='<a href="../memory-loss/memory-loss-normal.html">Is My Memory<br />Loss Normal?</a>';
textes[3]='<a href="../unbelievable-feats.html">Unbelievable Feats<br />of Brain Power</a>';

slidelinks[1]='../work-smarter-not-harder.html';
slidelinks[2]='../memory-loss/memory-loss-normal.html';
slidelinks[3]='../unbelievable-feats.html';

  
 addLoadEvent(function() {   
   /* more code to run on page load */  
setButtonClick(1);
initAnimation();
});   

function initAnimation(){
timer=window.setInterval('doNext()',5000); 
}

function setOnClass(id){
if(document.getElementById('slidebutton'+id)){
	document.getElementById('slidebutton'+id).className="slide-buttons-item_on";
}
}

function setOffClass(id){
if(document.getElementById('slidebutton'+id)){
	document.getElementById('slidebutton'+id).className="slide-buttons-item_off";
}
}

function setImage(id){
if(document.getElementById('slide')){
	document.getElementById('slide').src="../images/"+slides[id];
}

if(document.getElementById('slidelink')){
	document.getElementById('slidelink').href=slidelinks[id];
}


}

function setLabel(id){
if(document.getElementById('slide-text')){
	document.getElementById('slide-text').innerHTML=textes[id];
}
}

function setButtonClick(id){
stopTimer();
setOffClass(currentSlide);
currentSlide=id;
setOnClass(id);
setLabel(id);
setImage(id);
}

function stopTimer(){clearInterval(timer);}

function doNext(){
setOffClass(currentSlide);
if(currentSlide<3) { currentSlide=currentSlide+1;} else currentSlide=1;
setOnClass(currentSlide);
setLabel(currentSlide);
setImage(currentSlide);
}


