//var xmlHttpReq = null;

function init() {
	getTitles();
	getTopic('0');
}

function swapPhotos(newPhoto) {
	//alert(newPhoto)
	var src = newPhoto.src;
	if (src=="http://guide/images/spacer.gif") {
		return;
	}


	var bigPicEle = document.getElementById('bigPicture');
	var oldSrc = bigPicEle.src;
	//alert(newPhoto)
	var srcWidth = getImageSize(newPhoto).width;
	var srcHeight = getImageSize(newPhoto).height;

	var magicnumW = 305;
	var magicnumH = 260;

	if (srcWidth>=srcHeight) {
		if (srcWidth>magicnumW) {
			var size = magicnumW + "px";
		} else {
			var size = srcWidth + "px";
		}
		//if (bigPicEle.style) {
		//	bigPicEle.style.width=size;
		//	alert(size);
		//}
		//	bigPicEle.style.width=size;
		//} else {
			bigPicEle.width=size;
		//}


	} else {
		if (srcHeight>magicnumH) {
			var size = magicnumH + "px";
		} else {
			var size = srcHeight + "px";
		}
		//if (bigPicEle.style) {
		//	alert("It likes it.");
		//}
		//	bigPicEle.style.height=size;
		//} else {
			bigPicEle.height=size;
		//}
	}

	//alert(srcHeight);
	bigPicEle.src = src;
	newPhoto.src = oldSrc;
	//bigPicEle.style.width="50px";

}





function getTitles() {
	var xmlHttpReq;

	xmlHttpReq = GetXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = "automation.php?func=getfolders&";
	xmlHttpReq.onreadystatechange = function() { PHP_GetFolders_Response(xmlHttpReq); };
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.send(null);

}

function PHP_GetFolders_Response(xmlHttpReq) {
	if (xmlHttpReq.readyState==4) {
		if (xmlHttpReq.status==200) {
			var info = document.getElementById('topictitles');
			info.innerHTML = xmlHttpReq.responseText;
		} else {
			alert("There was a problem retrieving the XML data:\n" + xmlHttpReq.statusText);
		}
	}
}

function getTopic(param) {
	var xmlHttpReq;

	xmlHttpReq = GetXMLHttpReqObject();
	if (xmlHttpReq == null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url = "automation.php?func=gettopic&param=" + param + "&";
	//url = url + "?q=" + str;
	//url = url + "&sid=" + Math.random();

	//xmlHttpReq.onreadystatechange=stateChanged
	xmlHttpReq.onreadystatechange = function() { PHP_GetTopic_Response(xmlHttpReq); };
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.send(null);
}

function PHP_GetTopic_Response(xmlHttpReq) {
	if (xmlHttpReq.readyState==4) {
		if (xmlHttpReq.status==200) {
			var info = document.getElementById('info');
			info.innerHTML = xmlHttpReq.responseText;
		} else {
			alert("There was a problem retrieving the XML data:\n" + xmlHttpReq.statusText);
		}
	}
}

function GetXMLHttpReqObject() {
	var xmlHttpReq = null;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xmlHttpReq = new XMLHttpRequest();

		if (xmlHttpReq.overrideMimeType) {
			xmlHttpReq.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	return xmlHttpReq;
}

function getImageSize(myImage) {
	var imageObj= new Image()
	imageObj.src = myImage.src;
	return imageObj;
}