/*
onerror=handleErr;
var txt="";
function handleErr(msg,url,l) {
	txt="outisde.\n\n";
	txt+="Error: " + msg + "\n";
	txt+="URL: " + url + "\n";
	txt+="Line: " + l + "\n\n";
	txt+="Click OK to continue.\n\n";
	alert(txt);
	return true;
}
*/
newVersion = true;

function preloadImages(a) {
	var d = document;
	if (d.images) {
		if (!d.p) {
			d.p = new Array();
		}
		var i, j = d.p.length;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf("#") != 0) {
				d.p[j] = new Image();
				d.p[j++].src = a[i];
			}
		}
	}
}
function navSwapImage(type,what) {
	if (dontSwap == what) return;
	var e = document.getElementById("b"+what);
	if (!e) return;
	v2 = (what == 10) ? 'v2_' : "";
	e.src = "/images/menu_"+v2+((type == 'over') ? "2_" : "")+"r" + what + "_c1.gif";
}
function swapImage(what,img) {
	if (typeof restoreList == 'undefined') restoreList = Array();
	var e = document.getElementById(what);
	if (!e) return;
	if (!restoreList[what]) restoreList[what] = e.src;
	e.src = img;
}
function restoreImage(what) {
	if (typeof restoreList == 'undefined') restoreList = Array();
	var e = document.getElementById(what);
	if (!e || !restoreList[what]) return;
	e.src = restoreList[what];
}
function init(button) {
	if (typeof(button) == 'undefined') {
		origButton = 0;
	} else {
		origButton = button;
	}
	isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;	
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;	
	var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false; 
	var isIE4Mac = (isMac && isIE) ? true : false;
	if (isIE) theVer = parseInt(navigator.userAgent.substr(navigator.userAgent.indexOf('MSIE')+5,4).split(".")[0]);
	else theVer = true;
	
	if (isIE && theVer < 6 || isIE4Mac) return;

	var urls = Array('/iframes/grownups_main_source.html',
					 '/iframes/behindp4b_main_source.html',
					 '/iframes/thesecretbox_main_source.html',
					 '/iframes/weekbyweek_main_source.html',
					 '/iframes/testimonials_main_source.html',
					 '/iframes/registering_main_source2.html',
					 '/iframes/p4b4educators_main3.html',
					 '/iframes/parents_main_source.html',
					 'dummy 8!',
					 '/psagallery/', //'/gallery/',
					 '/iframes/contact_form.html');
	var preloadArray = new Array();
	if (newVersion) {
		for (i=0;i<=10;i++) {
			e = document.getElementById('b'+i);
			L = document.getElementById('L'+i);
			if (!e) continue;
			preloadArray.push("/images/menu_2_r"+i+"_c1.gif");
			e.myNum = i;
			e.onmouseover = function() {
				navSwapImage('over',this.myNum);
			}
			e.onmouseout = function() {
				navSwapImage('out',this.myNum);
			}
			/*
			if (urls[i] == "/gallery/" || urls[i] == "/gallery") {
				L.hold = urls[i];
				L.onclick = function() {
					window.top.popwindow(this.hold,true); 
					return false;
				}
			} else {
			*/
				if (!L) continue;
				L.i = i;
				L.onclick = function() {
					var e = frames['if1'];
					var temp1 = urls[this.i].split("http://").join("").split("/")[2];
					var temp2 = e.lastPage.split("http://").join("").split("/")
					temp2 = temp2[temp2.length-1];
					//alert(temp1 +" : " + temp2);
					if (e.location.href == urls[this.i] || (temp1.indexOf(".html") > 0 && temp2.indexOf(".html") > 0 && temp1 == temp2)) return false;
					//e.location.href = urls[this.i];
					
					var temp = dontSwap;
					dontSwap = false;
					navSwapImage('out',temp);
					if (this.i != 0) {
						navSwapImage('over',this.i);
						dontSwap = this.i;
					}
	
					if (isIE) {
						window.top.frames['tracker1'].location.search = "hash=" + urls[this.i].split("/iframes/").join("") +"&href=" + urls[this.i] + "&butt=" + window.top.dontSwap;
					} else {
						var temp = urls[this.i].split("/iframes/").join("");
						if (temp.length > 0) temp += "," + this.i;
						window.top.location.hash = temp;
					}
					return false;
				}
			//}
		}
	}

	dontSwap = false;
	var tempButton = window.top.location.hash.split(",")[1];
	if (tempButton) {
		navSwapImage('out',button);
		button = tempButton;
		if (tempButton != 0) {
			navSwapImage('over',tempButton);
		}
	}

	preloadImages(preloadArray);

	if (!button) return;
	dontSwap = button;
}
function swapIfDiff() {
	var temp = document.location.hash.split(",")[1];
	if (typeof(temp) == 'undefined') {
		temp = origButton;
	}
	if (typeof(temp) != 'undefined' && dontSwap != temp) {
		//alert("swapIfDiff("+dontSwap +"!="+ temp+")");
		var temp2 = dontSwap;
		dontSwap = false;
		navSwapImage('out',temp2);
		if (temp != 0) {
			navSwapImage('over',temp);
			dontSwap = temp;
		}
	}
}
/*
function addHash() {
	var e1 = document.getElementById('idif1').src;
	var i1 = e1.indexOf('/iframes');
	if (i1 > 0 && e1.substr(i1) == frames['if1'].location.pathname) false;
	else if (frames['if1'].location.pathname.substr(0,8) == "/iframes") window.location.hash = '#' + frames['if1'].location.pathname.substr(9);
	//else window.location.hash = "";
}
*/
function setIfHash() {
	if (window.location.hash.substr(0,1) == "#" && window.location.hash.length > 1) {
		var temp1 = window.location.hash.substr(1).split(",");
		temp2 = (temp1[0].substr(0,1) == "/") ? temp1[0] : "/iframes/" + temp1[0];
		if (temp1[2]) temp2 += "#" + temp1[2];
		frames['if1'].location.href = temp2;
	}
}
