/***********************************************
* Zap_ImgPop JavaScript Source
* Author: Tom Koehler
* Author URI: http://www.zappelfillip.de
* Plugin URI: http://www.zappelfillip.de/index.php/2005-10-25/zap_imgpop/
*
* Based on: 
* 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;

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

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(pluginurl, which, beschreibung, e, imgwidth, imgheight) {
  if (ie||ns6) {

    preload = new Image();
    preload.src = which;

    plugurl = pluginurl;
    beschr = beschreibung;
    crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;
    
		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">'+beschreibung+'</div><img style="float:right;" src="'+pluginurl+'closebutton.gif" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+pluginurl+'\');" onmouseout="showdefault(\''+pluginurl+'\');" onmousedown="showpush(\''+pluginurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+pluginurl+'loading.gif" alt="Image View" /></td></tr></table></div>';
    crossobj.style.visibility="visible";

    setTimeout("bildgeladen()", 200);

    return false;
  }
  else //if NOT IE 4+ or NS 6+, simply display image in full browser window
    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+'closebutton.gif" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom in" 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";
//	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+'closebutton.gif" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom in" 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+'closebutton.gif" id="schliessen" onclick="closepreview();" onmouseover="showhover(\''+plugurl+'\');" onmouseout="showdefault(\''+plugurl+'\');" onmousedown="showpush(\''+plugurl+'\');" alt="close" title="close" /></td></tr><tr><td><img id="picture" src="'+preload.src+'" alt="Image View" title="Click to zoom out" 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+"closeover.gif"
}


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


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

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

// <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);
}
