/***********************************************
* Image Thumbnail viewer- © Dynamic Drive (www.dynamicdrive.com)
* Last updated Sept 26th, 03'. This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var ie=document.all
var ns6=document.getElementById&&!document.all

var fotos;
var curFoto;
var maxFoto;

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlargeSingle(which, position, imgwidth, imgheight, thumb) {
//------------------------------------------------------------------	
	if (ie||ns6){
	crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage

	pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
	horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
	vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
	if (window.opera && window.innerHeight) //compensate for Opera toolbar
	vertpos=pgyoffset+window.innerHeight/2-imgheight/2
	vertpos=Math.max(pgyoffset, vertpos)

	crossobj.style.left=horzpos+"px"
	crossobj.style.top=vertpos+"px"
	
	if (isNumeric(which)) {
		crossobj.innerHTML='<div align="right" id="dragbar"><span id="closetext" onClick="closepreview()">Close</span></div><img src="showupload.php?id='+which+'&thumb='+thumb+'">'
	} else {
		crossobj.innerHTML='<div align="right" id="dragbar"><span id="closetext" onClick="closepreview()">Close</span></div><img src="' + which + '">'		
	}
	
	crossobj.style.visibility="visible"
	//return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
	return true
}

function enlargeMulti(which, position, imgwidth, imgheight, thumb, ecms_dir) {
//----------------------------------------------------------------------------	
	fotos = which.split("-");
	curFoto = 0;
	maxFoto = fotos.length - 1;
	if (ie||ns6) {
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		if (position=="center")	{
			pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else {
			var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}
		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		
		crossobj.innerHTML='<div align="right" id="dragbar"><img src="/' + ecms_dir + '/images/first.gif" class="navigation" onClick="showFirst();"><img src="/' + ecms_dir + '/images/prev.gif" class="navigation" onClick="showPrev();"><span id="num" class="navigationnum">1/'+(maxFoto+1)+'</span><img src="/' + ecms_dir + '/images/next.gif" class="navigation" onClick="showNext();"><span id="closetext" onClick="closepreview()">Close</span> </div><img src="/' + ecms_dir + '/pages/showupload.php?id='+fotos[0]+'" width="'+imgwidth+'" id="foto">'
		
		crossobj.style.visibility="visible"
		return false
	} else { //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
	}
}

function isNumeric(sText) {
//-------------------------
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}

function showFirst(ecms_dir) {
//----------------------------	
	curFoto = 0;
	imgobj=document.getElementById? document.getElementById("foto") : document.all.foto;
	imgobj.src="/" + ecms_dir + "/pages/showupload.php?id="+fotos[curFoto];
	numObj = document.getElementById? document.getElementById("num") : document.all.num;
	numObj.innerHTML =(curFoto+1)+'/'+(maxFoto+1); 
}

function showPrev(ecms_dir) {
//---------------------------
	if (curFoto == 0) curFoto = maxFoto;
	else curFoto = curFoto -1;
	imgobj=document.getElementById? document.getElementById("foto") : document.all.foto;
	imgobj.src="/" + ecms_dir + "/pages/showupload.php?id="+fotos[curFoto];
	numObj = document.getElementById? document.getElementById("num") : document.all.num;
	numObj.innerHTML =(curFoto+1)+'/'+(maxFoto+1); 	
}

function showNext(ecms_dir) {
//---------------------------
	if (curFoto >= maxFoto) curFoto = 0;
	else curFoto = curFoto +1;
	imgobj=document.getElementById? document.getElementById("foto") : document.all.foto;
	imgobj.src="/" + ecms_dir + "/pages/showupload.php?id="+fotos[curFoto];
	numObj = document.getElementById? document.getElementById("num") : document.all.num;
	numObj.innerHTML =(curFoto+1)+'/'+(maxFoto+1); 	
}

function closepreview() {
//-----------------------	
	crossobj.style.visibility="hidden"
}

function drag_drop(e) {
//---------------------	
	if (ie&&dragapproved) {
		crossobj.style.left=tempx+event.clientX-offsetx+"px"
		crossobj.style.top=tempy+event.clientY-offsety+"px"
	}
	else if (ns6&&dragapproved) {
		crossobj.style.left=tempx+e.clientX-offsetx+"px"
		crossobj.style.top=tempy+e.clientY-offsety+"px"
	}
	return false
}

function initializedrag(e) {
//--------------------------	
	if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar") {
		offsetx=ie? event.clientX : e.clientX
		offsety=ie? event.clientY : e.clientY
		
		tempx=parseInt(crossobj.style.left)
		tempy=parseInt(crossobj.style.top)
		
		dragapproved=true
		document.onmousemove=drag_drop
	}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")
