function changePicOver(picname){
   pfadstring = window.location.host;
   if(pfadstring == 'server'){
      pfadstring = "http://" + pfadstring + "/sloggahouseshop/";
   }
   pfadstringlength = pfadstring.length;
   lastslash = pfadstring.lastIndexOf("/")+1;
   navsw = window.navigator['userAgent'];

   if(pfadstringlength == lastslash){
      if(picname == "wk_warenkorb"){
         document.getElementById(picname).src = pfadstring + "/templates/sloggahouse/buttons/german/" + picname + "hover.gif";
      }
      else{
         document.getElementById(picname).src = pfadstring + "/templates/sloggahouse/img/" + picname + "hover.gif";
      }
      if(navsw.indexOf("MSIE 5.5") == -1 && navsw.indexOf("MSIE 6.0") == -1){
         document.body.style.cursor='pointer';
      }else{
         document.body.style.cursor='hand';
      }
   }else{
      pfadstring = pfadstring.substr(0,lastslash);
      if(picname == "wk_warenkorb"){
         document.getElementById(picname).src = pfadstring + "templates/sloggahouse/buttons/german/" + picname + "hover.gif";
      }
      else{
         document.getElementById(picname).src = pfadstring + "templates/sloggahouse/img/" + picname + "hover.gif";
      }
      if(navsw.indexOf("MSIE 5.5") == -1 && navsw.indexOf("MSIE 6.0") == -1){
         document.body.style.cursor='pointer';
      }else{
         document.body.style.cursor='hand';
      }
   }
   //alert('String: "' + pfadstring + '" Stringlänge: ' + pfadstringlength + ' Lastslash: ' + lastslash);

}
function changePicOut(picname){
   pfadstring = window.location.host;
   if(pfadstring == 'server'){
      pfadstring = "http://" + pfadstring + "/sloggahouseshop/";
   }
   pfadstringlength = pfadstring.length;
   lastslash = pfadstring.lastIndexOf("/")+1;

   if(pfadstringlength == lastslash){
      if(picname == "wk_warenkorb"){
         document.getElementById(picname).src = pfadstring + "/templates/sloggahouse/buttons/german/" + picname + ".gif";
      }
      else{
         document.getElementById(picname).src = pfadstring + "/templates/sloggahouse/img/" + picname + ".gif";
      }
      document.body.style.cursor='default';
   }else{
      pfadstring = pfadstring.substr(0,lastslash);
      if(picname == "wk_warenkorb"){
         document.getElementById(picname).src = pfadstring + "templates/sloggahouse/buttons/german/" + picname + ".gif";
      }
      else{
         document.getElementById(picname).src = pfadstring + "templates/sloggahouse/img/" + picname + ".gif";
      }
      document.body.style.cursor='default';
   }
   //alert('String: "' + pfadstring + '" Stringlänge: ' + pfadstringlength + ' Lastslash: ' + lastslash);
   //alert(document.getElementById(picname).src);
}

function displayButtons(){
   buttoncontainer.style.display = "block";
}
function hideButtons(){
   buttoncontainer.style.display = "none";
}

var picwidthresized = false;
var picheightresized = false;
var picalpha;
var oldpicw;
var oldpich;
var picwidth;
var picheight;
var newwidth;
var newheight;
var picdiffwidth;
var picdiffheight;
var picscaler = 15;
function picContainerResize(oldpicw, oldpich, picwidth, picheight, newwidth, newheight){
   if(document.all && picalpha > 0){
      picalpha = picalpha - 20;
      picselected.style.filter = "Alpha(opacity="+picalpha+")";
   }else if(picalpha > 0){
      picalpha = picalpha - 0.2;
      picselected.style.MozOpacity = picalpha;
   }

   // Breite skalieren
   if(picwidth < newwidth){
      picheightresized = false;
      picdiffwidth = newwidth - picwidth;
      if(picdiffwidth > picscaler){
         picdiffwidth = picscaler;
      }else{
         picdiffwidth = 1;
      }
      picwidth = picwidth + picdiffwidth;
      picselected.width = picwidth;
      buttoncontainer.style.width = picwidth + "px";
      //alert('Bild ist noch schmäler! Breite:'+picwidth+', Sollbreite: '+newwidth);
   }else if(picwidth > newwidth){
      picheightresized = false;
      picdiffwidth = picwidth - newwidth;
      if(picdiffwidth > picscaler){
         picdiffwidth = picscaler;
      }else{
         picdiffwidth = 1;
      }
      picwidth = picwidth - picdiffwidth;
      picselected.width = picwidth;
      buttoncontainer.style.width = picwidth + "px";
      //alert('Bild ist noch breiter! Breite:'+picwidth+', Sollbreite: '+newwidth);
   }else if(picwidth == newwidth){
      //alert('Sollbreite erreicht! Breite:'+picwidth+', Sollbreite:'+newwidth);
      picwidthresized = true;
   }

   // Höhe skalieren
   if(picheight < newheight){
      picheightresized = false;
      picdiffheight = newheight - picheight;
      if(picdiffheight > picscaler){
         picdiffheight = picscaler;
      }else{
         picdiffheight = 1;
      }
      picheight = picheight + picdiffheight;
      picselected.height = picheight;
      //alert('Bild ist noch niedriger! Höhe:'+picheight+', Sollhöhe: '+newheight);
   }else if(picheight > newheight){
      picheightresized = false;
      picdiffheight = picheight - newheight;
      if(picdiffheight > picscaler){
         picdiffheight = picscaler;
      }else{
         picdiffheight = 1;
      }
      picheight = picheight - picdiffheight;
      picselected.height = picheight;
      //alert('Bild ist noch höher! Höhe:'+picheight+', Sollhöhe: '+newheight);
   }else if(picheight == newheight){
      //alert('Sollhöhe erreicht! Höhe:'+picheight+', Sollhöhe:'+newheight);
      picheightresized = true;
   }

   if(picwidthresized == true && picheightresized == true && picalpha <= 0){
      //alert('Sollbreite erreicht! Breite:'+picwidth+', Sollbreite:'+newwidth+'\nSollhöhe erreicht! Höhe:'+picheight+', Sollhöhe:'+newheight+'\nBild wird ersetzt');
      //alert('Bild skaliert! Breite alt:'+oldpicw+', Breite neu:'+newwidth+'\nHöhe alt:'+oldpich+', Höhe neu:'+newheight);
      picselected.src = sourcefile.src;
      if(document.all){
         picalpha = 100;
         picselected.style.filter = "Alpha(opacity="+picalpha+")";
      }else{
         picalpha = 1;
         picselected.style.MozOpacity = picalpha;
      }
   }else{
      //alert('picContainerResize('+picwidth+', '+picheight+', '+newwidth+', '+newheight+') wird aufgerufen');
      setTimeout('picContainerResize('+oldpicw+', '+oldpich+','+picwidth+', '+picheight+', '+newwidth+', '+newheight+')', 50);
   }

}

function changePic(direction, filestring, maxpics){
   lastslash = filestring.lastIndexOf("/")+1;
   file = filestring.substring(lastslash, filestring.length);
   filepath = filestring.substring(0, lastslash);
   filenum = file.split('_');
   productnum = filenum[0];
   filenum = filenum[1].split('.');
   filenum = filenum[0];
   maxpics = maxpics - 1;
   if(document.all){
      picalpha = 100;
   }else{
      picalpha = 1;
   }

   if(direction == "prev" && filenum > 0){
      newfilenum = Number(filenum) - 1;
      next_pic_src = filepath + productnum + "_" + newfilenum + ".jpg";
   }
   if(direction == "next" && filenum < maxpics){
      newfilenum = Number(filenum) + 1;
      next_pic_src = filepath + productnum + "_" + newfilenum + ".jpg";

   }

   sourcefile = new Image();
   sourcefile.src = next_pic_src;
   //alert(sourcefile.src);

   oldpicwidth = picselected.width;
   oldpicheight = picselected.height;
   realwidth = sourcefile.width;
   realheight = sourcefile.height;

   if(document.all){
      fullwidth = document.body.offsetWidth;
      fullheight = document.body.offsetHeight;
   }else{
      fullwidth = window.innerWidth;
      fullheight = window.innerHeight;
   }

   halfwidth = fullwidth / 2;
   halfheight  = fullheight / 2;

   if(fullheight < realheight){
      picmultiply = fullheight / realheight - 0.2;
      newpicwidth = realwidth * picmultiply;
      newpicheight = realheight * picmultiply;
      //picselected.width = newpicwidth;
      //picselected.height = newpicheight;
      //buttoncontainer.style.width = newpicwidth + "px";
   }else{
      newpicwidth = realwidth;
      newpicheight = realheight;
      //picselected.width = newpicwidth;
      //picselected.height = newpicheight;
      //buttoncontainer.style.width = newpicwidth + "px";
   }
   //alert('Bild alt hat: '+oldpicwidth+'x'+oldpicheight+' Pixel\nBild neu hat: '+newpicwidth+'x'+newpicheight+' Pixel');
   picContainerResize(oldpicwidth, oldpicheight, oldpicwidth, oldpicheight, newpicwidth, newpicheight);
   //picselected.src = sourcefile.src;

   if(newfilenum == 0){
      prev_pic.style.display = "none";
   }else{
      prev_pic.style.display = "block";
   }
   if(newfilenum == maxpics){
      next_pic.style.display = "none";
   }else{
      next_pic.style.display = "block";
   }
   //initScreenUpdate();
   //alert("current: " + filenum + " new:" + newfilenum);
   //alert(next_pic_src);
}

function preloadImages(img_string){
   var i = 0;
   var imageArray = new Array();
   //alert(img_string);
   imageArray = img_string.split('|');
   //alert(imageArray);
   var imageObj = new Image();
   for(i=0; i<=imageArray.length-1; i++) {
      //alert(imageArray[i]);
      document.write('<img src="' + imageArray[i] + '" style="width:0px; height:0px;" />');// Write to page (uncomment to check images)
      imageObj.src=imageArray[i];
   }
}

function preloadPics(filepath, productnum , maxpics){
   for(i=0;i<=maxpics;i++){
      img = new Image();
      srcstring = filepath + productnum + "_" + i + ".jpg";
      img.src = srcstring;
      //alert(img.src);
   }
}

var alphadiv = 0;
function alphaIEToDark(){
   //alert("Alpha IE started");
   tabletoalpha.style.filter = "Alpha(opacity="+alphadiv+")";

   navsw = window.navigator['userAgent'];

   if(navsw.indexOf("MSIE 5.5") >= 1 || navsw.indexOf("MSIE 6.0") >= 1){
      selecttohide = document.getElementById('product_options_holder');
      selecttohide.style.display = "none";
      select2tohide = document.getElementById('manufacturers_holder');
      select2tohide.style.display = "none";
   }
   if(alphadiv != 80){
      alphadiv = alphadiv + 20;
      setTimeout('alphaIEToDark()', 1);
   }else{
      div2toshow.style.display = "block";
   }
}
function alphaIEToLight(){
   tabletoalpha.style.filter = "Alpha(opacity="+alphadiv+")";
   navsw = window.navigator['userAgent'];
   if(alphadiv != 0){
      alphadiv = alphadiv - 20;
      setTimeout('alphaIEToLight()', 1);
   }else{
      divtohide.style.display = "none";
      if(navsw.indexOf("MSIE 5.5") >= 1 || navsw.indexOf("MSIE 6.0") >= 1){
         selecttoshow = document.getElementById('product_options_holder');
         selecttoshow.style.display = "block";
         select2toshow = document.getElementById('manufacturers_holder');
         select2toshow.style.display = "block";
      }
   }
}
function alphaMozToDark(){
   //alert("Alpha Mozilla started");
   tabletoalpha.style.MozOpacity = alphadiv;
   if(alphadiv < 0.8){
      alphadiv = alphadiv + 0.2;
      setTimeout('alphaMozToDark()', 1);
   }else{
      div2toshow.style.display = "block";
   }
}
function alphaMozToLight(){
   tabletoalpha.style.MozOpacity = alphadiv;
   if(alphadiv > 0){
      alphadiv = alphadiv - 0.2;
      setTimeout('alphaMozToLight()', 1);
   }else{
      divtohide.style.display = "none";
   }
}


function newPicHolderPosition(){

   divtoshow = document.getElementById('fotodiv1');
   div2toshow = document.getElementById('fotodiv2');

   if(document.all){
      scrollhoehe  = document[docEl].scrollTop;
      divtoshow.style.top = scrollhoehe;
      div2toshow.style.top = scrollhoehe;
   }else{
      scrollhoehe  = document[docEl].scrollTop;
      divtoshow.style.top = scrollhoehe + "px";
      div2toshow.style.top = scrollhoehe + "px";
   }
}

var docEl = (typeof document.compatMode != "undefined" && document.compatMode != "BackCompat")? "documentElement" : "body";
function imageGreater(srcfile, maxpics, products_name){

   if (srcfile.search(/info_images+/) != -1){
      srcfile = srcfile.replace(/info_images/g, "popup_images");
      //alert(srcfile);
   }
   if (srcfile.search(/thumbnail_images+/) != -1){
      srcfile = srcfile.replace(/thumbnail_images/g, "popup_images");
      //alert(srcfile);
   }

   productstextfield = document.getElementById('picproductname');
   productstextfield.value = products_name;
   sourcefile = new Image();
   sourcefile.src = srcfile;
   //alert(sourcefile.src);

   realwidth = sourcefile.width;
   realheight = sourcefile.height;

   divtoshow = document.getElementById('fotodiv1');
   div2toshow = document.getElementById('fotodiv2');
   tabletoalpha = document.getElementById('fototable11');
   tabcontainer = document.getElementById('fototable22');
   tabtrcontainer = document.getElementById('fototd221');;
   tabtdcontainer = document.getElementById('fototd2211');
   picselected = document.getElementById('picgreat');
   prev_pic = document.getElementById('div_prev_pic');
   next_pic = document.getElementById('div_next_pic');

   divtoshow.style.display = "block";

   lastslash = srcfile.lastIndexOf("/")+1;
   file = srcfile.substring(lastslash, srcfile.length);
   filepath = srcfile.substring(0, lastslash);
   filenum = file.split('_');
   productnum = filenum[0];
   filenum = filenum[1].split('.');
   filenum = filenum[0];
   maxpics = maxpics - 1;
   //preloadPics(filepath, productnum , maxpics);
   //alert(filenum + " --- " + maxpics);
   if(filenum == 0){
      prev_pic.style.display = "none";
   }else{
      prev_pic.style.display = "block";
   }
   if(filenum == maxpics){
      next_pic.style.display = "none";
   }else{
      next_pic.style.display = "block";
   }


   if(document.all){
      scrollhoehe  = document[docEl].scrollTop;
      divtoshow.style.top = scrollhoehe;
      div2toshow.style.top = scrollhoehe;
      //alert(scrollhoehe);
      fullwidth = document.body.offsetWidth;
      fullheight = document.body.offsetHeight;
      //alert(fullwidth + ' x ' + fullheight);
      //tabletoalpha.style.filter = "Alpha(opacity=80)";
      //div2toshow.style.display = "block";
      alphaIEToDark();
   }else{
      buttoncontainer = document.getElementById('buttoncontainer');
      scrollhoehe  = document[docEl].scrollTop;
      divtoshow.style.top = scrollhoehe + "px";
      div2toshow.style.top = scrollhoehe + "px";
      //alert(scrollhoehe);
      fullwidth = window.innerWidth;
      fullheight = window.innerHeight;
      //tabletoalpha.style.MozOpacity = 0.8;
      //div2toshow.style.display = "block";
      alphaMozToDark();
   }

   halfwidth = fullwidth / 2;
   halfheight  = fullheight / 2;

   if(fullheight < realheight){
      picmultiply = fullheight / realheight - 0.2;
      picselected.src = srcfile;
      newpicwidth = realwidth * picmultiply;
      newpicheight = realheight * picmultiply;
      picselected.width = newpicwidth;
      picselected.height = newpicheight;
      buttoncontainer.style.width = newpicwidth + "px";
      buttoncontainer.style.top = halfheight + "px";
   }else{
      picselected.src = srcfile;
      newpicwidth = realwidth;
      newpicheight = realheight;
      picselected.width = newpicwidth;
      picselected.height = newpicheight;
      buttoncontainer.style.width = newpicwidth + "px";
      buttoncontainer.style.top = halfheight + "px";
   }
   initScreenUpdate();
   //divtoshow.style.display = "block";
}

function imageClose(){
   divtohide = document.getElementById('fotodiv1');
   //divtohide.style.display = "none";
   div2tohide = document.getElementById('fotodiv2');
   div2tohide.style.display = "none";
   if(document.all){
      alphaIEToLight();
   }else{
      alphaMozToLight();
   }
}
function initScreenUpdate(){
   if(browserscroll == true){
      window.onscroll = newPicHolderPosition;
   }else{
      var aktiv = window.setInterval("newPicHolderPosition()",1);
   }
}