// Ann Bean Mansion functions
// copyright 2007 Bruce Kaskubar
var BASE=""; // "http://localhost/abm/"
var dest;	// id of element to fill
var js;
var loaderPix = new Array();
var tourPix = new Array('pix/wabmNW.jpg','pix/wabmNWannAlbert.jpg','pix/wabmNNEaCynthia.jpg','pix/wabmNNEa.jpg','pix/wabmNNEaGuest.jpg','pix/wabmWSWaJacob.jpg','pix/wabmWSWa.jpg','pix/wabmNWtower.jpg');
var URL;
var XHR;	// XMLhttpRequest object

function checkNeeds() {
// if a function required for reasonable behavior is missing, transfer to secondary site
	if (!document.getElementById) parent.location="forward.html";
}

function get(d, j) { // retrieve HTML document d into content and execute javascript j after retrieval
	XHRrequest(BASE +(d) +'.html', '', 'content', true, j);
	pageTracker._trackPageview(d +'.html');
}

function getItem(d) { // retrieve HTML document d into item container and set item n to current
	XHRrequest(BASE +(d) +'.html','','item',true);
	pageTracker._trackPageview(d +'.html');
}

function loadImages() {
//	preload some images for smooth roll overs
	for (var i =0; i <tourPix.length; i++) {
		loaderPix.push(new Image());
		loaderPix[loaderPix.length -1].src =tourPix[i];
	}
} 

function XHRrequest(url, parms, destination, asynch, j) { // AJAX request initiator
// url: document to be retrieved; string
// parms: parameters for the respondent; string
// destination: name of container to receive response; string
// asynch: whether the request should be asynchronous or not; boolean
// j: javascript to execute after successful receipt; optional string
	if (j) js =j;
	else js ="";
	try { XHR =new XMLHttpRequest(); }
	catch(e) {
		try { XHR =new ActiveXObject("MSXML2.XMLHTTP"); }
		catch (e) {
			try { XHR =new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {parent.location='forward.html';}
		}
	}
	if (XHR) {
		dest =destination;
		XHR.onreadystatechange =XHRreceiver;
		XHR.open("GET", url, asynch);
		if (parms >"") XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		XHR.send(parms);
	}
}

function XHRreceiver() { // AJAX response receiver
	var e ="We're sorry but the requested information could not be found. If the problem persists, we would surely appreciate a note or call about the trouble we're causing you.";
	if (XHR.readyState !=4) return;
	if (XHR.status !=200) {
		if (dest >"") document.getElementById(dest).innerHTML=e +"<br><br>" +XHR.statusText;
		else alert(e +"\n\n" +XHR.statusText);
		return;
	}
	if (dest >"") {
		document.getElementById(dest).innerHTML=XHR.responseText;
		if (js >"") eval(js);
		return;
	}
	
	document.open();
	document.write(XHR.responseText);
	document.close();
	if (js >"") eval(js);
}

