var count = 0;
var defaultWidth  = 580;
var defaultHeight = 420;

// popup( url, <name>, <features>, width, height, top, left )
function popup( url, width, height, top, left, name, features )
{
 if( width == null )  width  = defaultWidth;
 if( height == null ) height = defaultHeight;

 if( document.all )
 {
  availWidth  = window.screen.availWidth;
  availHeight = window.screen.availHeight;

  if( top  == null ) top  = ",top="  + ( availHeight / 2 - height / 2 ); else top  = ",top=" + top;
  if( left == null ) left = ",left=" + ( availWidth  / 2 - width  / 2 ); else left = ",left="+ left;
 }
 else
 {
  if( top  == null ) top  = (screen.height) ? ",screenY=" + (screen.height / 2 - height / 2 ) : ""; else top  = ",screenX="+ top;
  if( left == null ) left = (screen.width)  ? ",screenX=" + (screen.width  / 2 - width  / 2 ) : ""; else left = ",screenY="+ left;
 }

 tmp = "";
 if( features != null && typeof( features ) == "string" ) {
  tmp = "toolbar=" + ( features.indexOf("toolbar") > - 1 ? "yes" : "no" ) + ",";
  tmp += "scrollbars=" + ( features.indexOf("scrollbar") > - 1 ? "yes" : "no" ) + ",";
  tmp += "menubar=" + ( features.indexOf("menubar") > - 1 ? "yes" : "no" ) + ",";
  tmp += "resizable=" + ( features.indexOf("resizable") > - 1 ? "yes" : "no" ) + ",";
  tmp += "status=" + ( features.indexOf("status") > - 1 ? "yes" : "no" ) + ",";
  tmp += "location=" + ( features.indexOf("location") > - 1 ? "yes" : "no" ) + ",";
  tmp += "directories=" + ( features.indexOf("directories") > - 1 ? "yes" : "no" ) + ",";
  features = tmp+"width="+ width +",height="+ height + top + left;
 } else {
  features = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,"
           + "resizable=no,width="+ width +",height="+ height + top + left;
 }

 // alert( features );
 if( name == null ) {
  id = count + Math.floor( Math.random() * 8192 );
  name = "Win"+id;
 }

 win = window.open( url, name, features);
 count++;

 if( win ) {
  win.focus();
 }
}

function popupWindow(url, width, height)
{
 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150')
}

function versandk(lang)
{
 window.open("/layer1/agb.php?lang="+lang,"nfo","locationbar=no,menubar=yes,scrollbars=yes");
}

function framecheck()
{
 var locate = document.URL;
 if (parent.frames.length < 3 && locate.search("http://") != -1 && locate.search("images") == -1 || parent.frames.length < 3 && locate.search("https://") != -1 && locate.search("images") == -1)
    {
     var url = document.location.href;
     var prothost = document.location.protocol + '//' + document.location.hostname;
     location.replace('/index.php?frame='+encodeURIComponent(url.replace(prothost,'')));
    }
 var ref = document.referrer;
 if (ref.search("lang=eng") != -1 && document.getElementById("english") != null || ref.search("lang=fra") != -1 && document.getElementById("english") != null)
    { changelang('eng'); }
}

function changelang(value)
{
 switch (value)
        {
         case 'eng':
              document.getElementById("deutsch").style.visibility = "hidden";
              document.getElementById("english").style.visibility = "visible";
              break;
         case 'ger':
              document.getElementById("deutsch").style.visibility = "visible";
              document.getElementById("english").style.visibility = "hidden";
              break;
        }
}


var ie = document.all?1:0;
var w3c = document.getElementById?1:0;
var ns4 = document.layers?1:0;

var smallWidth, smallHeight, smallLeft, smallTop;
var leftClip, rightClip, topClip, bottomClip;
var largeWidth, largeHeight;
var lensWidth, lensHeight;
var detailLeft, detailTop;
var zoomx, zoomy;
var loading, lens, mouseX = 0, mouseY = 0, X, Y;

function loadmagnifier(smallid, magnifyid, largeurl, largex, largey, loadingid, loadingtext) {

 // Opera ab Version 7 ermitteln - unabhaengig von der eingestellten Identifizierung
 if((window.opera) && !(navigator.userAgent.indexOf("7")!=-1))
    { return; }

   windowwidth = (ie) ? document.body.offsetWidth : window.innerWidth;
  windowheight = (ie) ? document.body.offsetHeight : window.innerHeight;

   pageOffsetX = document.body.scrollLeft;
   pageOffsetY = document.body.scrollTop;

   smallWidth = document.getElementById(smallid).width;
  smallHeight = document.getElementById(smallid).height;	// Breite und Hoehe der kleinen Grafik
   largeWidth = largex;
  largeHeight = largey;	// Breite und Hoehe der kleinen Grafik
    smallLeft = findPosX(document.getElementById(smallid));
     smallTop = findPosY(document.getElementById(smallid));	// Position der kleinen Grafik

    distanceToLeft = smallLeft;
   distanceToRight = windowwidth-smallLeft-smallWidth;
     distanceToTop = smallTop-pageOffsetY;
  distanceToBottom = windowheight-smallTop-smallHeight+pageOffsetY;

   maxdistancex = Math.max(distanceToLeft, distanceToRight);
   maxdistancey = Math.max(distanceToTop, distanceToBottom);

/*
   dragmarginx = windowwidth  - document.body.clientWidth  + 5;
   dragmarginy = windowheight - document.body.clientHeight + 5;
*/

   ((dragmarginx = windowwidth  - document.body.clientWidth)  > 0) ? dragmarginx+=5 : dragmarginx = 0;
   ((dragmarginy = windowheight - document.body.clientHeight) > 0) ? dragmarginy+=5 : dragmarginy = 0;

    lensWidth = Math.min(smallWidth, maxdistancex);
   lensHeight = Math.min(smallHeight, maxdistancey);
   // Minimale Lupengröße
    lensWidth = Math.max(lensWidth, 200);
   lensHeight = Math.max(lensHeight, 150);
   // Maximale Lupengröße
    lensWidth = Math.min(largex/2, lensWidth);
   lensHeight = Math.min(largey/2, lensHeight);
    lensWidth -= dragmarginx;
   lensHeight -= dragmarginy;


   detailLeft = smallLeft+smallWidth/2-lensWidth/2;
    detailTop = smallTop+smallHeight;	// Position des Rahmen-Layers

  zoomx = largeWidth/smallWidth;
  zoomy = largeHeight/smallHeight;

     lens = (ie)?document.all[magnifyid].style:(w3c)?document.getElementById(magnifyid).style:document[magnifyid];
  loading = (ie)?document.all[loadingid]:(w3c)?document.getElementById(loadingid):document[loadingid];


  if (loading.innerHTML == 'undefined' || loading.innerHTML == '') // Moz = undefined, IE = ''
     { loading.innerHTML = loadingtext; }

  var img = new Image();
  img.onload = function()
               {
                lens.backgroundImage = "url('" + largeurl + "')";
                loading.innerHTML = ' ';
               }
  img.src = largeurl;

  loading = loading.style;
  loading.backgroundColor = "#FFFFFF";
  loading.width = lensWidth + "px";
  loading.height = lensHeight + "px";

  lens.width = lensWidth + "px";
  lens.height = lensHeight + "px";
  lens.display = "block";

  if (distanceToRight >= lensWidth && distanceToTop >= 10 && distanceToBottom >= 10) // rechts Platz
     {
      lensx = smallLeft+smallWidth ;
      lensy = smallTop+smallHeight/2-lensHeight/2;
     }
  else if (distanceToLeft >= lensWidth) // links Platz
     {
      lensx = smallLeft-lensWidth;
      lensy = smallTop+smallHeight/2-lensHeight/2;
     }
  else if (distanceToBottom >= lensHeight) // unten Platz
     {
      lensx = smallLeft+smallWidth/2-lensWidth/2;
      lensy = smallTop+smallHeight;
     }
  else if (distanceToTop >= lensHeight) // oben Platz
     {
      lensx = smallLeft+smallWidth/2-lensWidth/2;
      lensy = smallTop-lensHeight;
     }
  else
     {
      lens.display = "none";
      loading.display = "none";
      return;
     }

  lens.left = lensx + "px";
  lens.top  = lensy + "px";

  loading.left = lensx;
  loading.top = lensy;
  loading.visibility = 'visible';

  if(ns4) {
   document.captureEvents(Event.MOUSEMOVE);
  }
  setInterval("cut()", 15);
  document.onmousemove = pos;

}



function pos(e) { // Mausposition und Clipping-Werte berechnen

 if(!e) e = window.event; // Event-Definition fuer IE
 mouseX = ((ns4)?e.pageX:e.clientX) + document.body.scrollLeft - smallLeft; // Mausposition innerhalb der
 mouseY = ((ns4)?e.pageY:e.clientY) + document.body.scrollTop - smallTop;  // kleinen Grafik ermitteln

 X = Math.round(mouseX * zoomx); // Umrechnen der Mausposition
 Y = Math.round(mouseY * zoomy); // auf grosse Grafik

 // Overscan verhindern - zuerst links/oben, dann rechts/unten
 if (X < lensWidth/2)
    { X = lensWidth/2; }
 if (Y < lensHeight/2)
    { Y = lensHeight/2; }
 if (X+lensWidth/2 > largeWidth)
    { X = largeWidth-lensWidth/2; }
 if (Y+lensHeight/2 > largeHeight)
    { Y = largeHeight-lensHeight/2; }

 leftClip = X - lensWidth /2; // Clipping-Werte
 topClip = Y - lensHeight /2; // fuer die grosse Grafik
// rightClip = X + lensWidth /2;
// bottomClip = Y + lensHeight /2;
}


function cut() {

 if(mouseX > 0 && mouseX < smallWidth && mouseY > 0 && mouseY < smallHeight)
   {
    lens.visibility = "visible";
    lens.backgroundPosition = -leftClip + "px " + -topClip + "px";
   }
 else
   {
    loading.visibility = "hidden";
    lens.visibility = "hidden";
   }
}

function closemagnifier()
{
 lens.visibility = 'hidden';
 lens.display = 'none';
 loading.visibility = 'hidden';
 loading.display = 'none';
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

