var iCurrentPage = 0;
var iPrevPage = 0;
var iZoom = 0;

$(document).ready (function () {
	for (var iCount = 0; iCount < iNrOfPages; iCount++) {
		if (iCount == 0) {
			$("#image").append ("<div><img width=\"480\" height=\"360\" id=\"page" + iCount + "\" src=\"screenshots/" + aPages[iCount].image + "\" border=\"0\"/></div>");
		} else {
			$("#image").append ("<img class=\"reflect\" width=\"480\" height=\"360\" id=\"page" + iCount + "\" src=\"screenshots/" + aPages[iCount].image + "\" border=\"0\"/>");
		}
		$("#page" + iCount).css ("left", iCount * 1000 + 77);
	}
	
	DoAnim ();
	$("#prev").mousedown (function () {
		PrevPage ();
	});
	$("#next").mousedown (function () {
		NextPage ();
	});
	$(window).keydown(function(event){
		if ((event.keyCode == 72) && (iZoom == 0)) {
			iPrevPage = iCurrentPage;
			iCurrentPage = 0;
			DoAnim ();
		}
		if ((event.keyCode == 69) && (iZoom == 0)) {
			iPrevPage = iCurrentPage;
			iCurrentPage = iNrOfPages - 1;
			DoAnim ();
		}
		if ((event.keyCode == 37) && (iZoom == 0)) {
			PrevPage ();
		}
		if ((event.keyCode == 39) && (iZoom == 0)) {
			NextPage ();
		}
		if (event.keyCode == 32) {
			if (iZoom == 0) {
				$("#zoom").html ("<img style=\"width:480px;height:360px;left:352px;top:153px\" id=\"zoomimg\" src=\"screenshots/" + aPages[iCurrentPage].image + "\" border=\"0\"/>");
				$("#zoom").show ();
				$("#zoomimg").animate({ 
			        width: "1024px",
					height: "768px",
					left: "0px",
					top: "0px"
				}, 500 );
				iZoom = 1;
			} else {
				$("#zoomimg").animate({ 
			        width: "480px",
					height: "360px",
					left: "352px",
					top: "153px"
				}, 500, "linear", function () {
					$("#zoom").hide();
				});
				iZoom = 0;
			}
		}
	});
	
	window.setTimeout ("addReflections()", 1000);
});

function PrevPage () {
	iPrevPage = iCurrentPage;
	if (iCurrentPage != 0) {
		iCurrentPage--;
		DoAnim ();
	}
}

function NextPage () {
	iPrevPage = iCurrentPage;
	if (iCurrentPage != iNrOfPages - 1) {
		iCurrentPage++;
		DoAnim ();
	}
}

function DoAnim () {
	if (iCurrentPage == 0) {
		if (iPrevPage != 0) {
			$("#background_home").fadeIn ("slow");
		}
	} else {
		if (iPrevPage == 0) {
			$("#background_home").fadeOut ("slow");
		}
	}

	iOffset = (iCurrentPage - iPrevPage) * 1000;
	$("#image > div").animate({"left": "-=" + iOffset + "px"}, "slow", function () {
	});

	$("#fadelayer > div").fadeOut ("fast", function () {
		if (iCurrentPage == 0) {
			$("#subtitle").css ("color", "#262626");
			$("#subtitle").css ("text-align", "center");
		} else {
			$("#subtitle").css ("color", "#ffffff");
			$("#subtitle").css ("text-align", "left");
		}
		$("#title").html (aPages[iCurrentPage].title);
		$("#subtitle").html (aPages[iCurrentPage].subtitle);
		var sHtml = "<ul>";
		if (aPages[iCurrentPage].content1 != "") { sHtml += "<li>" + aPages[iCurrentPage].content1 + "</li>"; }
		if (aPages[iCurrentPage].content2 != "") { sHtml += "<li>" + aPages[iCurrentPage].content2 + "</li>"; }
		if (aPages[iCurrentPage].content3 != "") { sHtml += "<li>" + aPages[iCurrentPage].content3 + "</li>"; }
		sHtml += "</ul>";
		$("#content").html (sHtml);
		if (aPages[iCurrentPage].demo == 1) {
			$("#demo").show ();
		} else {
			$("#demo").hide ();
		}
		$("#fadelayer > div").fadeIn ("fast");
	});
}


