var popupWindow;

function popup(index, imageArray) {
	if(popupWindow == null || popupWindow.closed ) {
		var w = 0, h = 0;
		if (document.all) {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		else if (document.layers) {
			w = window.innerWidth;
			h = window.innerHeight;
		}
		var popW = 640, popH = 530, numberOfImages = 3, leftPos = (w-popW)/2, topPos = (h-popH)/2;
		popupWindow = window.open(
			'','','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes');
		popupWindow.location.visible = false;
		popupWindow.document.open();
		popupWindow.document.writeln('<html><head><title>Screen Shots</title>');
		popupWindow.document.writeln('<META name="ROBOTS" content="ALL, INDEX, FOLLOW"></meta>');
		popupWindow.document.writeln('<META HTTP-EQUIV=content-type CONTENT="text/html; charset=ISO-8859-1"></meta>');
		popupWindow.document.writeln('<script type="text/javascript">');
		popupWindow.document.writeln('var imageArray = new Array(); ');
		for (i=1;i<=numberOfImages;i++) {
		popupWindow.document.writeln('imageArray['+ i +'] = \'' + imageArray[i] + '\'; ');
		}
		popupWindow.document.writeln('var numberOfImages = 3;');
		popupWindow.document.writeln('function swapImage(index) {');
		popupWindow.document.writeln('	var element = document.getElementById(\'lss\'); ');
		popupWindow.document.writeln('	element.src = imageArray[index]; ');
		popupWindow.document.writeln('	var ele = document.getElementById(\'currentImage\'); ');
		popupWindow.document.writeln('	ele.value = index; ');
		popupWindow.document.writeln('	setButtons(); ');
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('function setButtons() {');
		for (i=1;i<=numberOfImages;i++) {
		popupWindow.document.writeln('	setButtonAttributes(document.getElementById(\'Button' + i + '\'), '+ i +'); ');
		}
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('function setButtonAttributes(b, ind) {');
		popupWindow.document.writeln('	var currentInd = getCurrentImageIndex(); ');
		popupWindow.document.writeln('	if(currentInd == ind) {');
		popupWindow.document.writeln('		b.src = "http://www.spintop-games.com/i/btn_" + ind + "_smloff.gif"; ');
		popupWindow.document.writeln('		b.onclick = ""; ');
		popupWindow.document.writeln('		b.style.cursor = "default"; ');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('	else {');
		popupWindow.document.writeln('		b.src = "http://www.spintop-games.com/i/btn_" + ind + "_sml.gif"; ');
		popupWindow.document.writeln('		b.onclick = function() {swapImage(ind)}; ');
		popupWindow.document.writeln('		b.style.cursor = "pointer"; ');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('function previous() {');
		popupWindow.document.writeln('	var ind = parseInt(getCurrentImageIndex()); ');
		popupWindow.document.writeln('	if(ind > 1) {');
		popupWindow.document.writeln('		ind--;');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('	else {');
		popupWindow.document.writeln('		ind = numberOfImages;');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('	swapImage(ind);');
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('function next() {');
		popupWindow.document.writeln('	var ind = parseInt(getCurrentImageIndex()); ');
		popupWindow.document.writeln('	if(ind < numberOfImages) {');
		popupWindow.document.writeln('		ind++;');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('	else {');
		popupWindow.document.writeln('		ind = 1;');
		popupWindow.document.writeln('	}');
		popupWindow.document.writeln('	swapImage(ind);');
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('function getCurrentImageIndex() {');
		popupWindow.document.writeln('	return document.getElementById(\'currentImage\').getAttribute(\'value\'); ');
		popupWindow.document.writeln('}');
		popupWindow.document.writeln('<\/script>');
		popupWindow.document.writeln('</head><body style="font-family:arial;font-size:small;" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="swapImage(getCurrentImageIndex());" ><center>');			
		popupWindow.document.writeln('<div style="width:' + popW + 'px;text-align: center; margin-bottom:10px"><IMG id="lss" src="' + imageArray[index] + '" /></div>');
		popupWindow.document.writeln('<IMG id="leftButton" src="http://www.spintop-games.com/i/btn_left_sml.gif" onclick="previous();" style="cursor:pointer"/>');
		for (i=1;i<=numberOfImages;i++) {
		popupWindow.document.writeln('<IMG id="Button' + i + '" src="" onclick="" style=""/>');
		}
		popupWindow.document.writeln('<IMG id="rightButton" src="http://www.spintop-games.com/i/btn_right_sml.gif" onclick="next();" style="cursor:pointer">');
		popupWindow.document.writeln('<IMG id="closeButton" src="http://www.spintop-games.com/i/btn_close_sml.gif" onclick="self.close();" style="cursor:pointer"/>');
		popupWindow.document.writeln('</center><input type="hidden" id="currentImage" value="' + index + '"/></body></html>');
		popupWindow.document.close();
		popupWindow.focus();
	} else {
		popupWindow.close();
		popup(index, imageArray);
	}
}
