/***********************************************
* 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
***********************************************/
// true if you want images shrinked when showed. false shows images in original size
resize = true;

// If resize=true you can specify maxwidth and maxheight of the shown image. Use 0 if you want images shrinked to browser size, so that they are always displayed completely 
maxwidth = 0;
maxheight = 0;
actual_div = "";

//----------------------------------------------------------------------------------------------------------------

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

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

	
function enlarge(which, header, e, imgwidth, imgheight, xDescripcion, div) {
  if (ie||ns6) {
  	
  	if (actual_div) actual_div.style.visibility = 'visible';
  	actual_div = div;
  	//div.style.visibility = 'hidden';
  	xDescripcion = "";
	
    preload = new Image();
    preload.src = which;

    plugurl = RUTA+"include/js/enlarge/"; //pluginurl;
    beschr = header;
    crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;

	desc_pic = "";
	if (xDescripcion) {
		desc_pic = "<BR><table width=200><tr><td align=center><parrafo>"+xDescripcion+"</parrafo></td></tr></table>";
	}

	// PAGINATOR
	var which_array = which.split("/");
	var my_file = which_array.pop();
	var file_folder = which_array.join("/")+"/"; 
	/*if($('ARR_IMAGES')){
		var ARR_IMAGES = $F('ARR_IMAGES').split(",");
		var current = 1;
		if (ARR_IMAGES.length > 1) {
			for (var i = 0; i < ARR_IMAGES.length; i++) {
				if (String(my_file) == String(ARR_IMAGES[i])) { current = i+1; break; } 
			}
			if (current > 1) header += '<a href="javascript:;" onclick="javascript:enlarge(\''+file_folder+ARR_IMAGES[current-2]+'\',\'\',\'\',100,75,\'\',$(\'div_thumb_'+(current-1)+'\')); return false;">Anterior</a>&nbsp;';
			else header += "Anterior&nbsp;";
			header += current+"/"+ARR_IMAGES.length;
			if (current < ARR_IMAGES.length) header += '&nbsp;<a href="javascript:;" onclick="javascript:enlarge(\''+file_folder+ARR_IMAGES[current]+'\',\'\',\'\',100,75,\'\',$(\'div_thumb_'+(current+1)+'\')); return false;">Siguiente</a>';
			else header += "&nbsp;Siguiente";
		}
	}
	*/
    
    crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><table cellpading=0 cellspacing=0 border=0 width="100%"><tr><td align="center">'+header+'</td><td align="right" width=16><img style="cursor: pointer" src="'+plugurl+'cerrar.jpg" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="cerrar" /></td></tr></table></td></tr><tr><td align=center valign=middle><img id="picture"/>'+desc_pic+'</td></tr></table></div>';
    crossobj.style.zIndex = 1005;
    crossobj.style.visibility="visible";

    //setTimeout("bildgeladen()", 200);
    bildgeladen();
    
    return false;
  }
  else //if NOT IE 4+ or NS 6+, simply display image in full browser window
  	alert("FIREOX");
    return true;
}


function position(breite,hoehe) {
	breite=breite+14;
	hoehe=hoehe+32;
	pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop);
	horzpos=ns6? pageXOffset+window.innerWidth/2-breite/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-breite/2;
	vertpos=ns6? pgyoffset+window.innerHeight/2-hoehe/2 : pgyoffset+ietruebody().clientHeight/2-hoehe/2;
	if (window.opera && window.innerHeight) //compensate for Opera toolbar
		vertpos=pgyoffset+window.innerHeight/2-hoehe/2;

	vertpos=Math.max(pgyoffset, vertpos);
	crossobj.style.left=horzpos+"px";
	crossobj.style.top=vertpos+"px";
}


function ausgeben() {
	ratio = preload.width / preload.height;
	
	if(maxwidth == 0) innenbreite=ns6 ? window.innerWidth-47 : ietruebody().clientWidth-47;
	else innenbreite=maxwidth;
	if(maxheight == 0) innenhoehe=ns6 ? window.innerHeight-55 : ietruebody().clientHeight-55;
	else innenhoehe=maxheight;
	if((maxwidth != 0) && (maxheight != 0)) {
		innenbreite=maxwidth;
		innenhoehe=maxheight;
	}

	if(preload.width > innenbreite) {
		preload.width = innenbreite;
		preload.height = preload.width / ratio;
		if(preload.height > innenhoehe) {
			preload.height = innenhoehe;
			preload.width = preload.height * ratio;
		}
	}
	else if(preload.height > innenhoehe) {
		preload.height = innenhoehe;
		preload.width = preload.height * ratio;
		if(preload.width > innenbreite) {
			preload.width = innenbreite;
			preload.height = preload.width / ratio;
		}
	}
	
	imgwidth=preload.width;
	imgheight=preload.height;
	crossobj.style.visibility="hidden";
	position(imgwidth,imgheight);
    crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="'+plugurl+'cerrar.jpg" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="cerrar" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" title="clique&aacute; para ampliar la foto" onclick="vergroessern()" style="cursor:url('+plugurl+'plus.cur)" /></td></tr></table></div>';
  bild=document.getElementById? document.getElementById("picture") : document.all.picture;
	bild.style.width=preload.width+"px";
	bild.style.height=preload.height+"px";
  crossobj.style.visibility="visible";
}


function verkleinern() {
	imgwidth=preload.width;
	imgheight=preload.height;
	crossobj.style.visibility="hidden";
    crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="'+plugurl+'cerrar.jpg" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="cerrar" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" title="clique&aacute; para ampliar la foto" onclick="vergroessern()" style="cursor:url('+plugurl+'plus.cur)" /></td></tr></table></div>';
  bild=document.getElementById? document.getElementById("picture") : document.all.picture;
	bild.style.width=preload.width+"px";
	bild.style.height=preload.height+"px";
  crossobj.style.visibility="visible";
}

function vergroessern() {
	imgwidth=originalbreite;
	imgheight=originalhoehe;
	crossobj.style.visibility="hidden";
	
	crossobj.innerHTML='<div id="img-shadow"><table id="tabelle" border="0" cellpadding="0" cellspacing="4"><tr><td valign=middle id="dragbar"><div style="float:left;" id="dragbar">'+beschr+'</div><img style="float:right;" src="'+plugurl+'cerrar.jpg" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="cerrar" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" title="clique&aacute; para achicar la foto" onclick="verkleinern()" style="cursor:url('+plugurl+'minus.cur)" /></td></tr></table></div>';
	bild=document.getElementById? document.getElementById("picture") : document.all.picture;
	bild.style.width=originalbreite+"px";
	bild.style.height=originalhoehe+"px";
	var horzpos=ns6? pageXOffset+15 : ietruebody().scrollLeft+15
	var vertpos=ns6? pageYOffset : ietruebody().scrollTop	
//	crossobj.style.left=horzpos+"px";
//	crossobj.style.top=vertpos+15+"px";
	crossobj.style.visibility="visible";
}

function bildgeladen() {
  if(preload.complete) {
  	originalbreite = preload.width;
  	originalhoehe = preload.height;

		if(maxwidth == 0) innenbreite=ns6 ? window.innerWidth-47 : ietruebody().clientWidth-47;
		else innenbreite=maxwidth;
		if(maxheight == 0) innenhoehe=ns6 ? window.innerHeight-55 : ietruebody().clientHeight-55;
		else innenhoehe=maxheight;
		
  	if(((preload.width > innenbreite) || (preload.height > innenhoehe)) && resize) {
			ausgeben();
		}
		else {
			imgwidth=preload.width;
			imgheight=preload.height;

			crossobj.style.visibility="hidden";
			position(imgwidth,imgheight);

			bild=document.getElementById? document.getElementById("picture") : document.all.picture;
			bild.src = preload.src;
			bild.style.width=preload.width+"px";
			bild.style.height=preload.height+"px";
			crossobj.style.visibility="visible"
		}
  }
  else { setTimeout("bildgeladen()", 200) }
}


function showhover(pluginurl){
	closebild=document.getElementById? document.getElementById("schliessen") : document.all.schliessen;
  closebild.src=pluginurl+"cerrar.jpg"
}


function showdefault(pluginurl){
	closebild=document.getElementById? document.getElementById("schliessen") : document.all.schliessen;
  closebild.src=pluginurl+"cerrar.jpg"
}


function showpush(pluginurl){
	closebild=document.getElementById? document.getElementById("schliessen") : document.all.schliessen;
  closebild.src=pluginurl+"cerrar.jpg"
}
	

function closepreview(){
  crossobj.style.visibility="hidden";
  if (actual_div) actual_div.style.visibility = 'visible';
  hideBg();
}

	
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")

// <div id="showimage"></div> erzeugen

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

//addLoadEvent(diverzeugen);	// diverzeugen aufrufen onLoad

function diverzeugen() {
  var DerBody = document.getElementsByTagName("body").item(0);
  var objImagediv = document.createElement("div");
  objImagediv.setAttribute('id','showimage');
  DerBody.appendChild(objImagediv);
}
diverzeugen();
