var xmlhttp;
var currImg;
var totalImg;

function showSlideshow(id) {
	currImg = 1;
	document.getElementById("cslideshow").style.display = '';
	document.getElementById("cslideshow").style.position = 'fixed';
	document.getElementById("cslideshow").style.height = '120%';
	document.getElementById("cslideshow").style.width = '100%';
	document.getElementById("cslideshow").style.top = '0px';
	document.getElementById("cslideshow").style.zIndex = '2';
	document.getElementById("cslideshow").style.backgroundImage = 'url(/include/slideshow/back.png)';
	document.getElementById("cslideshow").innerHTML = '<div style="background-color: #fff; margin:70px auto; padding:10px; width:725px; height: 550px; border:1px solid #bbb; -moz-border-radius:8px; -khtml-border-radius:8px;"><div style="height:30px;"><div style="float:left;margin-right:10px;"><a href="javascript:goSlideshow('+id+',\'prev\');" id="linkprev"><img src="/include/slideshow/prev.png" border=0 /></a></div><div style="float:left;" id="cslideshowdescr"></div><div style="float:right;"><a href="javascript:goSlideshow('+id+',\'next\');" id="linknext"><img src="/include/slideshow/next.png" border=0 style="margin-right:5px;" /></a><a href="javascript:closeSlideshow();"><img src="/include/slideshow/close.png" border=0 /></a><img src="/include/slideshow/ajax-loader.gif" style="display:none;" border=0 /></div><div id="cslideshowimageno" style="float:right;margin-right:3px; heigth:22px;"></div></div><a href="javascript:goSlideshow('+id+',\'next\');"><img scr="" id="cslideshowimage" style="margin:8px auto; display:block;" border="0" /></a></div>';
	goSlideshow(id, currImg);
	document.getElementById("cslideshow").style.display = '';
}

function goSlideshow(id, to) {
	if (to=='next') currImg++;
	if (to=='prev') currImg--;
	if ((currImg-1)<1) document.getElementById("linkprev").style.display = 'none';
	else document.getElementById("linkprev").style.display = '';
	if ((currImg+1)>totalImg) document.getElementById("linknext").style.display = 'none';
	else document.getElementById("linknext").style.display = '';
	if ((currImg)>totalImg) closeSlideshow();
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET","/slideshow/"+id+"/"+currImg,true);
	xmlhttp.send(null);
}

function stateChanged() {
	if (xmlhttp.readyState==4) {
		totalImg = xmlhttp.responseText.substring(0, xmlhttp.responseText.indexOf(":"));
		imagename = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf(":")+1, xmlhttp.responseText.indexOf("::"));
		ext = imagename.lastIndexOf(".");
		image = imagename.substring(0, ext);
		ext = imagename.substring(ext);
		descr = xmlhttp.responseText.substring(xmlhttp.responseText.indexOf("::")+2);
		document.getElementById("cslideshowimage").src = '/include/slideshow/ajax-loader.gif';
		document.getElementById("cslideshowimage").src = '/images/image_'+image+',700,500,,'+ext;
		document.getElementById("cslideshowdescr").innerHTML = descr;
		document.getElementById("cslideshowimageno").innerHTML = currImg+'/'+totalImg;
	}
}

function closeSlideshow() {
	document.getElementById("cslideshow").style.display = 'none';
	document.getElementById("cslideshow").innerHTML = '';
}


function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

