/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/


var photoContent;
var loadingIcon;

function getXML()
{
	return new XMLHttpRequest();
}

function photoInit()
{
	photoContent = document.getElementById('photoContent');
	loadingIcon = document.getElementById('loading');
	doRequest("pindex.php");
}

function goToPage(s)
{
	var p = s.options[s.selectedIndex].value;
	p = p-1;
	doRequest('pindex.php?path=' + currentPath + '&page=' + p);
}

function doRequestActual(path,action)
{
	loadingIcon.style.display = "";
	var xml = getXML();
	if(path.indexOf('?') <= 0)
		path = path+"?galleryID=" + galleryID;
    else
		path = path+"&galleryID=" + galleryID;
		
	xml.open("GET", "/Scripts/gallery/" + path, true);
	xml.onreadystatechange = function()
	{
		if (xml.readyState == 4) {
		if (xml.status == 200) 
			{
				photoContent.innerHTML = xml.responseText;
				loadingIcon.style.display = 'none';
				xml2.send(null);
			}
		}
	}
	
	var xml2 = getXML();
	if(path.indexOf('?') <= 0)
		path = path+"?request=varsonly";
    else
		path = path+"&request=varsonly";
		
	xml2.open("GET", "/Scripts/gallery/" + path, true);
	xml2.onreadystatechange = function()
	{
		if (xml2.readyState == 4) {
		if (xml2.status == 200) 
			{
				var vars = xml2.responseText.split(",");
				currentPage = vars[0];
				currentPath = vars[1];
				if(vars[2] == "true")
					hasPreviousPage = true;
				else
					hasPreviousPage = false;
					
				if(vars[3] == "true")
					hasNextPage = true;
				else
					hasNextPage = false;
				firstThumbID = vars[4];
				lastThumbID = vars[5];
				
				if(action == 1)
					hs.expand(document.getElementById('thumb_'+firstThumbID));
				else if(action == 2)
					hs.expand(document.getElementById('thumb_'+lastThumbID));
			}
		}
	}
	
	xml.send(null);
}

function doRequest(path)
{
	doRequestActual(path,0);
}

function doRequestHSNext(path)
{
	doRequestActual(path,1);
}


function doRequestHSPrev(path)
{
	doRequestActual(path,2);
}
