var BaseHref="";
var pathPrefix="";
if (location.href.indexOf("/html/")!=-1) {
	var pathPrefix = "../../";
}

var galleryWindow = null;
var singleQuote = "'";
var timeOn = null;
var imageRestoreDelay = 10000;

var imageCountHome = 21;
var slideImageNbr = 1;
var nextImageNbr = null;
var imageCountGallery = 12;
var imageCountConstruction = 12;
var imageCountBali = 18;

if (location.href.indexOf("luxury")!=-1) {
	var imageCount = imageCountConstruction;
}
else if (location.href.indexOf("gallery")!=-1) {
	var imageCount = imageCountGallery;
}
else if (location.href.indexOf("bali")!=-1) {
	var imageCount = imageCountBali;
}
else {
	var imageCount = imageCountHome;
}

function pauseDisplay(delay) {
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < delay);
}

function getImageTop(dir){
	if (dir.indexOf("home")!=-1) {
		document.write('<img src="' + pathPrefix + 'images_' + dir + '/image_top01.jpg" alt="Batu Belig Residences" height="406" width="900" border="0" name="imageTop" id="imageTop" usemap="#homeMap" />');
	}
	else {
		document.write('<img src="' + pathPrefix + 'images_' + dir + '/image_top01.jpg" alt="Batu Belig Residences" height="312" width="900" border="0" name="imageTop" id="imageTop" usemap="#level2Map" />');
	}
}

function getImageBottom(dir){
	document.write('<img src="' + pathPrefix + 'images_' + dir + '/image_bottom01.jpg" alt="Batu Belig Residences" height="87" width="900" border="0" name="imageBottom" id="imageBottom" usemap="#logoMap" />');
	restoreImageTimer()
}

function restoreImageTimer() {
	timeOn = setTimeout("showNextImage()",imageRestoreDelay);
}

function showNextImage() {
	if ((location.href.indexOf("villas")!=-1) || (location.href.indexOf("luxury")!=-1)) {
		var dir = "images_level2";
		var maxImages = (imageCountHome-1);
	}
	else if (location.href.indexOf("bali")!=-1) {
		var dir = "images_bali";
		var maxImages = (imageCountBali-1);
	}
	else {
		var dir = "images_home";
	}
	if (slideImageNbr > maxImages) {
		slideImageNbr = 1;
	}
	else {
		slideImageNbr = slideImageNbr + 1;
	}
	if (slideImageNbr<10) {
		var imageNbrAlpha = "0" + slideImageNbr;
	}
	else {
		var imageNbrAlpha = slideImageNbr;
	}
	var currentImageTop = new Image();	
	currentImageTop.src = pathPrefix + dir + "/image_top" + imageNbrAlpha + ".jpg";
	var currentImageBottom = new Image();
	currentImageBottom.src = pathPrefix + dir + "/image_bottom" + imageNbrAlpha + ".jpg";
	document.getElementById('imageTop').src = currentImageTop.src;
	document.getElementById('imageBottom').src = currentImageBottom.src;
	var nextImageTop = new Image();	
	nextImageTop.src = pathPrefix + dir + "/image_top" + nextImageNbr + ".jpg";
	var nextImageBottom = new Image();
	nextImageBottom.src = pathPrefix + dir + "/image_bottom" + nextImageNbr + ".jpg";
	timeOn = setTimeout("showNextImage()",imageRestoreDelay);
}

function showLargeResidenceImage(image, title) {
	OpenWindow = window.open('','','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=820,height=728,left=5,top=5');
	OpenWindow.document.write('<html><title>' + title + '</title><body leftmargin="0" marginheight="0" marginwidth="0" topmargin="0"  onBlur="window.close()"><img src=' + image + ' width="820" height="728"></body></html>');
	OpenWindow.focus();
}

function showLargeBuildingImage(path, imgNbr) {
	var phpURL = "gallery_image.php?path=" + path + "&imgNbr=" + imgNbr;
	galleryWindow = window.open(phpURL,'galleryWindow','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=500,left=5,top=5');
	galleryWindow.focus();
}

function showLargeFinishedImage(path, imgNbr) {
	var phpURL = "gallery_image.php?path=" + path + "&imgNbr=" + imgNbr;
	galleryWindow = window.open(phpURL,'galleryWindow','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=500,left=5,top=5');
	galleryWindow.focus();
}

function showLargeLocationImage(path, imgNbr) {
	var phpURL = "gallery_image.php?path=" + path + "&imgNbr=" + imgNbr;
	galleryWindow = window.open(phpURL,'galleryWindow','toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=500,left=5,top=5');
	galleryWindow.focus();
}
