// JavaScript Document
var ie=document.all;
var ns6=document.getElementById&&!document.all;
var aktuelleBox;
var worteDiv;
var zIndex=0;

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

function selektierenWeg(){
  if(aktuelleBox!=null){
    aktuelleBox.style.cursor="auto";
  }
  aktuelleBox=null;
}

function selektieren(welcheBox){
  aktuelleBox=welcheBox;
  aktuelleBox.style.cursor="move";
  zIndex++;
  aktuelleBox.style.zIndex=zIndex;
}


function vergroessern(welche, e, position, imgwidth, imgheight){
  if (ie||ns6){
    horizoposi = 240;
    vertiposi = ieobjekt().scrollTop + 50;
    aufbau=document.getElementById? document.getElementById("zeigedasbild") : document.all.zeigedasbild;
    /*
    horizoposi=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ieobjekt().scrollLeft+ieobjekt().clientWidth/2-imgwidth/2;
    vertiposi=ns6? seite_y_stellung+window.innerHeight/2-imgheight/2 : seite_y_stellung+ieobjekt().clientHeight/2-imgheight/2;
    }
    */
    if (window.opera && window.innerHeight){ //Ausgleich fuer Opera
      seite_y_stellung=ns6? parseInt(pageYOffset) : parseInt(ieobjekt().scrollTop);
      //vertiposi=seite_y_stellung+window.innerHeight/2-imgheight/2;
      //vertiposi=Math.max(seite_y_stellung, vertiposi);
      vertiposi=seite_y_stellung + 50;
    }
    aktuelleBox=aufbau;
    
    aufbau.style.zIndex=zIndex;
    aufbau.style.left=horizoposi+"px";
    aufbau.style.top=vertiposi+"px";
    aufbau.innerHTML='<div onclick="selektieren(this);" align="right" id="leiste"><span id="schliessen_text" onClick="vorschau_zu()">Schlie&szlig;en</span> </div><img src="'+welche+'">';
    aufbau.style.visibility="visible";
    return false
  }
  else //falls kein IE 4+ oder NS 6+, zeige das Bild einfach in einem neuen Browser-Fenster
    return true
}

function vorschau_zu(){
  aufbau.style.visibility="hidden"
}

function drag_and_drop(e){
  
  if(aktuelleBox!=null){
    if (ie&&dragapproved){
      if((event.srcElement.id!="hintergrund")){
        //aktuelleBox.style.left=tempx+event.clientX-offsetx+"px";
        aktuelleBox.style.top=tempy+event.clientY-offsety+"px";
      } else {
        aktuelleBox.style.cursor="auto";
        aktuelleBox=null;
      }
    } else if (ns6&&dragapproved){
      if((e.target.id!="hintergrund")){
        aktuelleBox.style.left=tempx+e.clientX-offsetx+"px"
        aktuelleBox.style.top=tempy+e.clientY-offsety+"px"
      } else {
        aktuelleBox.style.cursor="auto";
        aktuelleBox=null;
      }
    }
  }
  return false;
}


function initiiere_drag(e){
  if (ie&&event.srcElement.id=="leiste"||ns6&&e.target.id=="leiste"){
    tempx=parseInt(aufbau.style.left)
    tempy=parseInt(aufbau.style.top)
  }
  if(aktuelleBox==null){
    return true;
  }  
  
  offsetx=ie? event.clientX : e.clientX
  offsety=ie? event.clientY : e.clientY
  
  dragapproved=true
  document.onmousemove=drag_and_drop
  if(aktuelleBox!=null){
    tempx=parseInt(aktuelleBox.style.left)
    tempy=parseInt(aktuelleBox.style.top)
  }

  return false;
}

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

