var pageTitle = "Barry Hargan and Assoicates LLC - Evaluations and Experts for Attorneys - ";
var pageNames = ["Home","Philosophy","Experts","Evaluations","Referrals","Resources","Contact"];
var myPanelNames = ["home","phlo","exp","eva","ref","reso","cont"];
var myPanels = new Array();
var selectedPage;
var userAgent = navigator.userAgent.toLowerCase();
var ieVersion = parseInt(userAgent.substring(userAgent.indexOf("msie") + 4));
if (this.ieVersion == 0) this.ieVersion = 100;

if (!Array.indexOf) {
	Array.prototype.indexOf = function (obj) {
		for (var i = 0; i < this.length; i += 1) {
			if (this[i] == obj) {
				return i;
			}
		}
		return -1;
	};
}
function FnCaller(fn, scope, arg)
{
    this.doCall = function(e)
    {
        var args = [arg];
        var ev = e ? e : window.event;
        if ( ev ) {
            args = [ev, arg];
        } 
        if ( scope ) {
        	scope = (typeof scope == "string") ? util.getO(scope) : scope;
            return fn.apply(scope, args);
        }
        else {
            return fn(args);
        }
    };
};
function selectPage(id) {
	if (selectedPage && selectedPage.id == id) 
		return;
	var index = myPanelNames.indexOf(id);
	document.title = pageTitle + pageNames[index];
	if ( selectedPage ) {
		selectedPage.className = "panel-h";
	}
	
	selectedPage = myPanels[index];
	selectedPage.className = "panel";
	applySize(selectedPage);
}
	
function getWidth() {
	if (typeof (window.innerWidth) == "number") {
    	return window.innerWidth;
	} 
	else {
		if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			return document.documentElement.clientWidth;
		} 
		else {
			if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
				return document.body.clientWidth;
			}
		}
	}
}
function applySize() {
	var w = getWidth();
	if (w < 950) 
		w = ((w < 740) ? 480 : (w - 270));
	else
		w = 690;
		document.getElementById("aroundall").style.width = (w+220) + "px";
		document.getElementById("header").style.width = (w+220) + "px";
		document.getElementById("header-text").style.width = (w+220) + "px";
			var ch = selectedPage.getElementsByTagName("div");
			selectedPage.style.width = w + "px";
			for (var j = 0; j < ch.length; j++) {
				if ((ch[j].className == "pn-top") || (ch[j].className == "pn-mid") || (ch[j].className == "pn-bottom"))
					ch[j].style.width = w + "px";
				else if ((ch[j].className == "pn-tc") || (ch[j].className == "pn-bc") || (ch[j].className == "pn-mc"))
					ch[j].style.width = (w - 8) + "px";
			}
			selectedPage.mr.style.height = ch[4].offsetHeight + "px";
}

function initialize() {
	for (var i=0; i < myPanelNames.length; i++) {
		var p = document.getElementById(myPanelNames[i] + "-panel");
		if (p) {
			p.shId = myPanelNames[i];
			myPanels.push(p);
			var menuitem = document.getElementById(myPanelNames[i]);
			menuitem.onclick = function(){selectPage(this.id);};
			if (ieVersion < 7) {
				menuitem.onmouseover = function(){this.className += (" " + this.id + "-over");};
				menuitem.onmouseout = function(){this.className = "menu-item";};
			}
			p.mr = document.getElementById(p.id + "-mr");
			p.getElementsByTagName("div")[4].appendChild(document.getElementById(myPanelNames[i] + "-cnt"));
		}
	}
	selectPage(myPanels[0].shId);
	applySize();
}
window.onresize = applySize;
window.onload = initialize;
