var xmlHttp = createXmlHttpRequestObject();
var HOST_DOMAIN = 'http://192.168.128.100/labcms2';
function createXmlHttpRequestObject()	{
	var xmlHttp;
	
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)	{
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {}
		}
	}
	
	if (!xmlHttp)	{
		alert("Error creating XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
}

function load_main(id)	{
	
	//Effect.Fade('portfolioImg', { duration: 0 });
	if (xmlHttp)	{
		try {
			xmlHttp.open("GET", HOST_DOMAIN + "/load_gallery_item.php?id=" + id, true);
			
			xmlHttp.onreadystatechange = lm_handleRequestStateChange;
			xmlHttp.send(null);
		} catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

function lm_handleRequestStateChange()	{
	if (xmlHttp.readyState == 4)	{
		if (xmlHttp.status == 200)	{
			try {
				lm_handleServerResponse();
			} catch (e) {
				alert("Error reading the response:\n" + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function lm_handleServerResponse()	{
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parseerror")	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	
	xmlRoot = xmlResponse.documentElement;
	
	if (rootNodeName != "galleryHolder" || !xmlRoot.firstChild)	{
		throw("Invalid XML Structure:\n" + xmlHttp.responseText);
	}
	responseText = xmlRoot.firstChild.data;
	myDiv = document.getElementById("galleryHolder");
	
	startFade(myDiv);
}

function startFade(myDiv)	{
	//myDiv.setStyle.display = 'hidden';
	myDiv.innerHTML = responseText;
	setTimeout("Effect.Appear(galleryHolder);", 100);

}
