/* Copyright (c) 2008 S. M. Eskola */
var tmgTimer;
function TMGimagePopup (TMGimg, angle, pid){
	if(TMGimg == 0){document.getElementById("TMGpuImgr").style.display = "none";document.getElementById("ctrls").style.display = "none";with(document.getElementById("TMGwindow")){style.opacity=1;style.filter = "alpha(opacity=100)";}TMGbackLock(false);tmgNewSlides(false, pid);}
	else{var nI = returnNext(pid,true);var nextImg = "TMGimagePopup(document.getElementById("+nI+").src,document.getElementById("+nI+").name,document.getElementById("+nI+").id);";TMGimg = TMGimgSS(TMGimg);with(document.getElementById("TMGwindow")){style.opacity=0.5;style.filter = "alpha(opacity=50)";}with(document.getElementById("TMGpuImgr")){innerHTML = "<a onclick='"+nextImg+" tmgNewSlides(false,"+nI+");'><img id=TMGpuImg name='"+pid+"' src='"+TMGimg+"'/></a>";}with(document.getElementById("TMGpicPrint")){innerHTML = "<br/><br/><br/><img src='"+TMGimg+"'/>";}writeCtrls(pid);TMGimgSize(angle);}
}
function returnPath(id){return document.getElementById(id).src;}
function returnAngle(id){return document.getElementById(id).name;}
function returnNext(id,direction){id *=1;return (direction)?((id==count)?0:id+1):((id==0)?count:id-1);}
function TMGimgSS (image){return image.substring(0,image.length-5)+image.substring(image.length-4,image.length);}
function TMGbackLock(test){with(document.getElementById("TMGpopupImg")){style.display = (test)?"block":"none";}}
function TMGimgSize(angle){
	TMGbackLock(true);var MxSH = ScreenHeight("max");var MxSW = ScreenWidth("max");var MnSH = ScreenHeight("min");var MnSW = ScreenWidth("min");var SH = document.body.scrollHeight;var SW = document.body.scrollWidth;var Pwide = (angle == "0")?"600":"400";var Phigh = (angle == "0")?"400":"600";var Ptop = (half(MnSH)-half(Phigh));var Pleft = (half(MnSW)-half(Pwide));Ptop = (Ptop>0)?Ptop:0;Pleft = (Pleft>0)?Pleft:0;
	with(document.getElementById("TMGpuImgr")){style.top = Ptop+"px";style.left = Pleft+"px";style.height = Phigh+"px";style.width = Pwide+"px";style.display = "block";}
	with(document.getElementById("ctrls")){style.top = (Ptop*1+Phigh*1+1)+"px";style.left = Pleft+"px";style.width = Pwide+"px";style.display = "block";}
	with(document.getElementById("TMGpopupImg")){style.height = ((SH>MxSH)?SH:MxSH)+"px";var tmp =(SW>MxSW)?SW:MxSW;tmp = (sbc()>tmp)?sbc():tmp;tmp = (600>tmp)?600:tmp;style.width = tmp+"px";}
}
function sbc (){return ScreenWidth("max");}
function TMGimgpuResize (){
	if(document.getElementById("TMGpuImgr").style.display == "block"){var ImgH = returnPixels(document.getElementById("TMGpuImgr").style.height);ImgH = (ImgH == 400)?0:1;TMGimgSize(ImgH);}
}
function returnPixels(input){return input.substring(0,input.length-2);}
function half(input){return Math.round(input/2);}
function ScreenWidth(size){
	if(size == "max"){return (document.body.clientWidth > document.documentElement.clientWidth)?document.body.clientWidth : document.documentElement.clientWidth;}
	else {return (document.body.clientWidth < document.documentElement.clientWidth)?document.body.clientWidth : document.documentElement.clientWidth;}
}
function ScreenHeight(size){
	if(size == "max"){return (document.body.clientHeight > document.documentElement.clientHeight)?document.body.clientHeight : document.documentElement.clientHeight;}
	else {return (document.body.clientHeight < document.documentElement.clientHeight)?document.body.clientHeight : document.documentElement.clientHeight;}
}
function tmgNewSlides(test, id){
	if(test){ tmgPreImg(id);tmgTimer = setTimeout("tmgNewSlides(true,"+returnNext(id,true)+")",5000);with(document.getElementById(id)){TMGimagePopup(src, name, id);}}
	else {clearTimeout(tmgTimer);tmgTimer=0;writeCtrls(id);}
}
function tmgPreImg (id){id = returnNext(id,true);MM_preloadImages(TMGimgSS(document.getElementById(id).src));}
function writeCtrls(pid){
	var pI = returnNext(pid,false);var nI = returnNext(pid,true);var nextImg = "TMGimagePopup(document.getElementById("+nI+").src,document.getElementById("+nI+").name,document.getElementById("+nI+").id);";var prevImg = "TMGimagePopup(document.getElementById("+pI+").src,document.getElementById("+pI+").name,document.getElementById("+pI+").id);";
	document.getElementById("ctrls").innerHTML = (tmgTimer)?"<a onclick='"+prevImg+" tmgNewSlides(false,"+pid+");'> previous </a> | <a onclick='tmgNewSlides(false,"+pid+");'> pause </a> | <a onclick='TMGimagePopup(0,0,0);'> close </a> | <a onclick='"+nextImg+" tmgNewSlides(false,"+pid+");'> next </a>":"<a onclick='"+prevImg+"'> previous </a> | <a onclick='tmgNewSlides(true,"+nI+");'> play </a> | <a onclick='TMGimagePopup(0,0,0);'> close </a> | <a onclick='"+nextImg+"'> next </a>";
}