var theTime = 0;

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if (el.style.display == 'none') {	
		el.style.display = 'block';
	} else {
		el.style.display = 'none';
	}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2;
	popUpDiv_height="20";
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width="20";
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname,i) {
	document.getElementById('content').scrollTop = 0;
	blanket_size(windowname);
	window_pos(windowname);
	j = i + 1; 
	document.getElementById('aTitle').innerHTML = j + '/' + theImage.length + ':  ' + theTitle[i];
	
	if (document.getElementById('pich')) {
		document.getElementById('pich').src = theImage[i];
		document.getElementById('pich').width = theWidth[i];
		document.getElementById('someTexth').innerHTML = theText[i];
		document.getElementById('picv').src = theImage[i];
		document.getElementById('picv').width = theWidth[i];
		document.getElementById('someTextv').innerHTML = theText[i];
	} 
	else if (document.getElementById('pic')) {
		document.getElementById('pic').src = theImage[i];
		/* document.getElementById('pic').width = theWidth[ikk]; */
		document.getElementById('someText').innerHTML = theText[i];
	}
	
	ikk = i;
	if (ikk == theImage.length-1) {
		document.getElementById('next').style.display = 'none';
	} else { 
		document.getElementById('next').style.display = 'block'; 
	}
	if (ikk == 0) {
		document.getElementById('prev').style.display = 'none';
	} else { 
		document.getElementById('prev').style.display = 'block'; 
	}
	if (theSwitch[i] == "h") {
		document.getElementById('horiz').style.display = 'block';
		document.getElementById('vert').style.display = 'none';
	} else if (theSwitch[i] == "v") {
		document.getElementById('horiz').style.display = 'none';
		document.getElementById('vert').style.display = 'block';
	}
	toggle('blanket');
}

function popdown() {
	document.getElementById('aTitle').innerHTML = "";
	if (document.getElementById('pich')) {document.getElementById('pich').src = "";}
	if (document.getElementById('someTexth')) {document.getElementById('someTexth').innerHTML = "";}
	if (document.getElementById('picv')) {document.getElementById('picv').src = "";}
	if (document.getElementById('someTextv')) {document.getElementById('someTextv').innerHTML = "";}
	if (document.getElementById('pic')) {document.getElementById('pic').src = "";}
	if (document.getElementById('someText')) {document.getElementById('someText').innerHTML = "";}
	var el = document.getElementById('blanket');
	el.style.display = 'none';
}

function popstay(windowname,i) {
	if (theSwitch[ikk] != "") {
		document.getElementById('horiz').style.display = 'none';
		document.getElementById('vert').style.display = 'none';
	}
	if (document.getElementById('pich')) {document.getElementById('pich').src = "";}
	if (document.getElementById('picv')) {document.getElementById('picv').src = "";}
	if (document.getElementById('pic')) {document.getElementById('pic').src = "";}
	var elnext = document.getElementById('next');
	var elprev = document.getElementById('prev');
	if (i == 1) {
		if (ikk == theImage.length-2) {
			elnext.style.display = 'none';
			elprev.style.display = 'block';
			ikk = ikk + 1;
		} else { 
			elnext.style.display = 'block';
			elprev.style.display = 'block';
			ikk = ikk + 1;
			}
	} else if (i == -1){
		if (ikk == 1) { 
			elprev.style.display = 'none';
			elnext.style.display = 'block';
			ikk = 0;
		} else { 
			elprev.style.display = 'block';
			elnext.style.display = 'block';
			ikk = ikk - 1; 
		}
	} else if (i == 0) { 
		elprev.style.display = 'none';
		elnext.style.display = 'block';
		ikk = 0;
	} else { 
		elprev.style.display = 'block';
		elnext.style.display = 'none';
		ikk = theImage.length-1; 
	}
	j = ikk + 1; 
	document.getElementById('aTitle').innerHTML = j + '/' + theImage.length + ':  ' + theTitle[ikk];

	if (document.getElementById('pich')) {
		document.getElementById('pich').src = theImage[ikk];
		document.getElementById('pich').width = theWidth[ikk];
		document.getElementById('someTexth').innerHTML = theText[ikk];
		document.getElementById('picv').src = theImage[ikk];
		document.getElementById('picv').width = theWidth[ikk];
		document.getElementById('someTextv').innerHTML = theText[ikk];
	} 
	else if (document.getElementById('pic')) {
		document.getElementById('pic').src = theImage[ikk];
		/* document.getElementById('pic').width = theWidth[ikk]; */
		document.getElementById('someText').innerHTML = theText[ikk];
	}

	if (theSwitch[ikk] == "h") {
		document.getElementById('horiz').style.display = 'block';
		document.getElementById('vert').style.display = 'none';
	} else if (theSwitch[ikk] == "v") {
		document.getElementById('horiz').style.display = 'none';
		document.getElementById('vert').style.display = 'block';
	}
	blanket_size(windowname);
	window_pos(windowname);
}

 
var theIntervalId = 0; 
var twitch = 0;

function starttimer(windowname,form) {
	var theInterval = form.timespan.value * 1000;
	var el = document.getElementById('toggle');
	var elnext = document.getElementById('next');
	var elprev = document.getElementById('prev');
	var elfirst = document.getElementById('first');
	var ellast = document.getElementById('last');
	if(el.value=='Start') {
		el.value = 'Stop';
		elnext.style.display = 'none';
		elprev.style.display = 'none';
		elfirst.style.display = 'none';
		ellast.style.display = 'none';
		if (ikk >= theImage.length-1) {
			ikk = -1;
			updateDiv('popUpDiv');
		}
		theIntervalId = setInterval("updateDiv('popUpDiv')", theInterval);
	} else {
	    clearInterval(theIntervalId);
		el.value = 'Start';
		if (ikk == theImage.length-1) {
			elnext.style.display = 'none';
		} else {
			elnext.style.display = 'block';
		}
		if (ikk == 0) {
			elprev.style.display = 'none';
		} else {
			elprev.style.display = 'block';
		}
		elfirst.style.display = 'block';
		ellast.style.display = 'block';
	}
}

function updateDiv(windowname) {
		ikk = ikk + 1;
		j = ikk + 1;
		document.getElementById('aTitle').innerHTML = j + '/' + theImage.length + ':  ' + theTitle[ikk];
		if (document.getElementById('pich')) {
			document.getElementById('pich').src = theImage[ikk];
			document.getElementById('pich').width = theWidth[ikk];
			document.getElementById('someTexth').innerHTML = theText[ikk];
			document.getElementById('picv').src = theImage[ikk];
			document.getElementById('picv').width = theWidth[ikk];
			document.getElementById('someTextv').innerHTML = theText[ikk];
		} 
		else if (document.getElementById('pic')) {
			document.getElementById('pic').src = theImage[ikk];
			/* document.getElementById('pic').width = theWidth[ikk]; */
			document.getElementById('someText').innerHTML = theText[ikk];
		}
		if (theSwitch[ikk] == "h") {
			document.getElementById('horiz').style.display = 'block';
			document.getElementById('vert').style.display = 'none';
		} else if (theSwitch[ikk] == "v") {
			document.getElementById('horiz').style.display = 'none';
			document.getElementById('vert').style.display = 'block';
		}
		if (ikk >= theImage.length-1) {
			clearInterval(theIntervalId);
			document.getElementById('next').style.display = 'none';
			document.getElementById('prev').style.display = 'block';
			document.getElementById('first').style.display = 'block';
			document.getElementById('last').style.display = 'block';
			document.getElementById('toggle').value = 'Start';
		}
		blanket_size(windowname);
		window_pos(windowname);
}



