// Set event handler to initialize API
var isCSS, isW3C, isIE4, isIE6CSS, isNN4, isNN6; 
var widthWindow, heightWindow;
var heightHTML;
var browserWidth;

window.onresize = dynamicLayout;
window.onload = dynamicLayout;

// let all IBrowsers establish content objects
function dynamicLayout() {
	
	if (document.images) {
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isNN6 = (document.getElementById && !document.all) ? true : false;
		isOPE = (window.opera) ? true : false;

		if (isW3C) {

				offY = (isNN6)? 12: (isOPE)? 12 : (isIE6CSS)? 12 : 0;
				if (screen.width < 900){
					changeLayout("thin");
				}
				
				if (getRawObject("span_main").scrollHeight > getRawObject("span_banner_02").scrollHeight) {
					getObject("span_banner_02").height = getRawObject("span_main").scrollHeight -2  + "px";
				}
				else{
					if (getObject("div_text2")){
					getObject("div_text2").height = getRawObject("span_banner_02").scrollHeight - getRawObject("div_text1").scrollHeight - 13 + "px";	
					}
					else{
						getObject("div_text1").height = getRawObject("span_banner_02").scrollHeight - 10 + "px";	
					}
				}
		}
		return true;
	}
	else return false;
}


// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}
	return theObj;
}
// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isW3C) {
			theObj = document.getElementById(obj);
		} else if (isIE4) {
			theObj = document.all(obj);
		} else if (isNN4) {
			theObj = seekLayer(document, obj);
		}
	} else {
		// pass through object reference
		theObj = obj;
	}
	return theObj;
}

function getBrowserWidth(){
	if (window.innerWidth){ return window.innerWidth; }	
	else if (document.documentElement && document.documentElement.clientWidth != 0){ return document.documentElement.clientWidth;	}
	else if (document.body){return document.body.clientWidth; } return 0;
}
function changeLayout(styleTitle){
	var currTag;
	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};

