﻿function windowSize() {
	//http://www.javascriptkit.com/domref/elementproperties.shtml
	if ( document.getElementById("titleBar") ) {
		document.getElementById("titleBar").style.height = (GetWindowHeight() * .10) + "px";
		}
	
	if ( document.getElementById("title") ) {
		document.getElementById("title").style.height = (GetWindowHeight() * .075) + "px";
		document.getElementById("title").style.width = (GetWindowHeight() * 1.047) + "px";
		}

	if ( document.getElementById("book") ) {
		document.getElementById("book").style.height = (GetWindowHeight() * .82) + "px";
		}
		
	if ( document.getElementById("bookPic") ) {
		document.getElementById("bookPic").style.height = (GetWindowHeight() * .82) + "px";
		}

	if ( document.getElementById("topic") ) {
		document.getElementById("topic").style.fontSize = (GetWindowHeight() * .04) + "px";
		document.getElementById("topic").style.lineHeight = (GetWindowHeight() * .04) + "px";	
		}
	
	if ( document.getElementById("paraLeft") ) {
		document.getElementById("paraLeft").style.fontSize = (GetWindowHeight() * .02) + "px";
		}
		
	if ( document.getElementById("paraLeft2") ) {
		document.getElementById("paraLeft2").style.fontSize = (GetWindowHeight() * .02) + "px";
		}
		
	if ( document.getElementById("paraRight") ) {
		document.getElementById("paraRight").style.fontSize = (GetWindowHeight() * .02) + "px";
		}
	
	if ( document.getElementById("linkBar") ) {
		document.getElementById("linkBar").style.height = (GetWindowHeight() * .05) + "px";
		}

	if ( document.getElementById("links") ) {
		document.getElementById("links").style.fontSize = (GetWindowHeight() * .02) + "px";
		}
	
	if ( document.getElementById("menu") ) {
		document.getElementById("menu").style.fontSize = (GetWindowHeight() * .02) + "px";	
		document.getElementById("menu").style.lineHeight = (GetWindowHeight() * .04) + "px";
		}
	
	if ( document.getElementById("toc") ) {
		document.getElementById("toc").style.fontSize = (GetWindowHeight() * .03) + "px";	
		document.getElementById("toc").style.lineHeight = (GetWindowHeight() * .06) + "px";
		}

	if ( document.getElementById("logo") ) {
		document.getElementById("logo").style.height = (GetWindowHeight() * .08) + "px";
		document.getElementById("logo").style.width = (GetWindowHeight() * .3466) + "px";
		}
	
	if (browser == 'ie' || browser == 'ie7') {
		document.getElementById("ieBuffer").style.height = (GetWindowHeight() * .01) + "px";
		}
		
	// new junk
	var PictureElements = ["pic1","pic2"];
	
	for (var i=0; i < PictureElements.length; i++) {
		if ( document.getElementById(PictureElements[i]) ) {
			var img = document.getElementById( PictureElements[i] );
			var naturalheight = img.naturalHeight || img.naturalheight;
			var naturalwidth = img.naturalWidth || img.naturalwidth;
			var outputstring = "";
			
			if (naturalheight > 0 && naturalwidth > 0) {
				img.height = (naturalheight * (img.offsetWidth / naturalwidth));
			}
		}
	}
		
}

function GetWindowWidth() {
	var width = 1000;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		width = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		width = document.body.clientWidth;
	}
	return width;
}

function GetWindowHeight() {
	var Height = 1000;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		Height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientHeight || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		Height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientHeight || document.body.clientHeight ) ) {
		//IE 4 compatible
		Height = document.body.clientHeight;
	}
	return Height;
}

function getElementsByClass(node,searchClass,tag) {
  var classElements = new Array();
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("\b"+searchClass+"\b");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}

/*var browser = ModernBrowser();

function ModernBrowser() {
	// 0 for old browser, 1 for new, -1 for ancient (Netscape 4 or less)
	var b = navigator.userAgent;
	if			(b.match("Opera"))									{ return 'op';	}
	else if	(b.match("Safari"))									{ return 'sf';	}
	else if	(b.match("FireFox"))									{ return 'ff';	}
	else if	(b.match("MSIE 7.0"))								{ return 'ie7';}
	else if	(b.match("MSIE"))										{ return 'ie';	}
	else if	(b.match("Mozilla/5.0"))							{ return 'mz';	}
	else if	(b.match("Mozilla") && !b.match("Gecko"))		{ return 'ns';	}
	// If not matched yet, we'll assume it's a new browser
	return 'na';
}*/

function SpecialRunOnceOnload() {
	var allimages = document.getElementsByTagName("img");
	for (var j=0; j < allimages.length; j++) {
		var img = allimages[j];
		var outputstring = "All Images Length: " + allimages.length + "\n";
		for (var i=0; i < img.attributes.length; i++) {
			if (img.attributes[i].value != "null") {
				//window.alert(img.naturalwidth + "; " + img.attributes[i].value);
				outputstring+= img.attributes[i].name + " = " + img.attributes[i].value + " \n";
				if (img.attributes[i].name == "height") {
					img.naturalheight = parseInt(img.attributes[i].value);
				}
				if (img.attributes[i].name == "lang") {
					img.naturalwidth = parseInt(img.attributes[i].value);
				}
			}
		}
		//window.alert(outputstring);
	}
	windowSize();
}

window.onload=SpecialRunOnceOnload;
window.onresize=windowSize;

