Months = Array("January","February","March","April","May","June","July","August","September","October","November","December");
sHREF = "http://shared.adnec.ae/ipcameras/awc-0008/";
inMotion = false;
oInterval = null;

function printPage() {
	if(!document.getElementById) return false;
	
	var loc = window.location + "";
	
	if(loc.substr(loc.length-1,1) == "#") {
		loc = loc.substr(0,loc.length-1);	
	}
	
	var printWin = window.open(loc + "?print=1","printwindow","width=520,height=500,menubar=yes,scrollbars=yes");
}

function checkForMotion() {
	if(!document.getElementById) return false;
	oControl = document.getElementById('play_sequence');

	if(inMotion) {
		clearInterval(oInterval);
		oControl.style.backgroundImage = "url(i/film_play.gif)";
		inMotion = false;
	}
}

function nextImage() {
	if(!document.getElementById) return false;

	oImg = document.getElementById('ci');
	oTag = document.getElementById('timetag');
	
	nextImg = curImage - 1;

	if(nextImg < 0) {
		nextImg = imageHolder.length-1;
	}
	
	iY = imageHolder[nextImg].substr(6,4);
	iM = imageHolder[nextImg].substr(10,2);
	iD = imageHolder[nextImg].substr(12,2);
	iH = imageHolder[nextImg].substr(14,2);
	iI = imageHolder[nextImg].substr(16,2);

	iTag = iD + " " + Months[Number(iM)-1] + " " + iY + " at " + iH + ":" + iI;
	
	checkForMotion();
	
	oTag.innerHTML = "<strong>" + iTag + "</strong>";
	oImg.src = sHREF + imageHolder[nextImg];
	curImage = nextImg;
}

function prevImage() {
	if(!document.getElementById) return false;

	oImg = document.getElementById('ci');
	oTag = document.getElementById('timetag');
	
	nextImg = curImage + 1;

	if(nextImg >= imageHolder.length) {
		nextImg = 0;
	}
	
	iY = imageHolder[nextImg].substr(6,4);
	iM = imageHolder[nextImg].substr(10,2);
	iD = imageHolder[nextImg].substr(12,2);
	iH = imageHolder[nextImg].substr(14,2);
	iI = imageHolder[nextImg].substr(16,2);

	iTag = iD + " " + Months[Number(iM)-1] + " " + iY + " at " + iH + ":" + iI;
	
	checkForMotion();
	
	oTag.innerHTML = "<strong>" + iTag + "</strong>";
	oImg.src = sHREF + imageHolder[nextImg];
	curImage = nextImg;
}

function jumpImage(imageIndex) {
	if(!document.getElementById) return false;

	oImg = document.getElementById('ci');
	oTag = document.getElementById('timetag');

	iY = imageHolder[imageIndex].substr(6,4);
	iM = imageHolder[imageIndex].substr(10,2);
	iD = imageHolder[imageIndex].substr(12,2);
	iH = imageHolder[imageIndex].substr(14,2);
	iI = imageHolder[imageIndex].substr(16,2);

	iTag = iD + " " + Months[Number(iM)-1] + " " + iY + " at " + iH + ":" + iI;

	checkForMotion();
	
	oTag.innerHTML = "<strong>" + iTag + "</strong>";
	oImg.src = sHREF + imageHolder[imageIndex];
	curImage = imageIndex;
}

function toggleLoader() {
	if(!document.getElementById) return false;
	
	oLoader = document.getElementById("loader");
	
	if(oLoader.style.display == "" || oLoader.style.display == "block") {
		oLoader.style.display = "none";
	} else {
		oLoader.style.display = "block";
	}
}

function stopMotion() {
	if(!document.getElementById) return false;
	timeInterval = 1; // seconds

	oControl = document.getElementById('play_sequence');

	if(inMotion) {
		clearInterval(oInterval);
		oControl.style.backgroundImage = "url(i/film_play.gif)";
		inMotion = false;
	} else {
		oInterval = setInterval('changeImage()',timeInterval*1000);
		oControl.style.backgroundImage = "url(i/film_stop.gif)";
		inMotion = true;
	}
}

function changeImage() {
	if(!document.getElementById) return false;

	oImg = document.getElementById('ci');
	oTag = document.getElementById('timetag');

	nextImg = curImage - 1;

	if(nextImg < 0) {
		nextImg = imageHolder.length-1;
	}
	
	iY = imageHolder[nextImg].substr(6,4);
	iM = imageHolder[nextImg].substr(10,2);
	iD = imageHolder[nextImg].substr(12,2);
	iH = imageHolder[nextImg].substr(14,2);
	iI = imageHolder[nextImg].substr(16,2);

	iTag = iD + " " + Months[Number(iM)-1] + " " + iY + " at " + iH + ":" + iI;
	
	oTag.innerHTML = "<strong>" + iTag + "</strong>";
	oImg.src = sHREF + imageHolder[nextImg];
	curImage = nextImg;
}