//----------------------------------------------------------------------//
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var div;
var imag;
var iText;
//----------------------------------------------------------------------//
function showImage(num) {
	imag = document.getElementById('mainImage');
	iText = document.getElementById('imageDetails');
	div = document.getElementById('loadingDiv');
	
	callServer("view_image.php?info="+num);
	
	callServer("view_image.php?width="+num);

	imag.src = "images/uploads/Main_"+num+".jpg";
	
	// doesn't work in inter-suck explorer, otherwise works very very well
	//imag.src = "view_image.php?imageId="+num;
	
}
//----------------------------------------------------------------------//
function updatePage() {
	if (xmlHttp.readyState == 4) {
		var result = xmlHttp.responseText;
		if (result.indexOf("-|_") <= 0) {
			var thing = result.split(",");
			imag.width = thing[0];
			imag.height = thing[1];
			div.style.width = imag.width - 12 + "px";
			div.style.height = imag.height - imag.height/2 + "px";
			div.style.margin = "5px";
			div.style.paddingTop = imag.height/2 - 12 + "px";
			InitializeTimer(2);
		} else {
			var thing = result.split("-|_");
			if (thing[1] != " ") {
				thing[1] = (thing[1].replace(/\n/g, " "));
				iText.innerHTML = "<em>"+thing[0]+" - "+thing[1]+"</em>";
			} else {
				iText.innerHTML = "<em>"+thing[0]+"</em>";
			}
		}
	}
}
//----------------------------------------------------------------------//
function InitializeTimer(tim) {
	div.style.display = "block";
	imag.src = "";
	imag.style.visibility = "hidden";
    secs = tim;
    StopTheClock();
    StartTheTimer();
}
//----------------------------------------------------------------------//
function StopTheClock() {
    if (timerRunning) {
        clearTimeout(timerID);
    }
    timerRunning = false;
}
//----------------------------------------------------------------------//
function StartTheTimer() {
    if (secs == 0) {
		div.style.display = "none";
		imag.style.visibility = "visible";
    } else {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}
//----------------------------------------------------------------------//