

var ImageSource = new Image();
var ImageLoading = new Image();
var ImageViewerStatus = "off";
var padding_corrector = (document.all) ? 2 : 0; 

ImageLoading.src = WEBDIR+"images/load.gif";


function loadImage(imgSrc)
{
//    ImageViewerStatus = ImageViewerStatus == "loading" ? "loading" : "start_loading";
    ImageViewerStatus = "start_loading";
    ImageSource = new Image();
    ImageSource.src = imgSrc;
    checkImage();
}

function checkImage()
{
    if(ImageViewerStatus == "off")
    {
        return true;
    }
    if(ImageSource.complete == true)
    {
        //Image Resizing ENDE
        
        var width=ImageSource.width;
        var height=ImageSource.height;
        var newwidth=600;
        var newheight=450;    
        
        if(width > height)
        {
          if(width > newwidth)
          {
            var newheight2=newheight;
            newheight=height / (width / newwidth);
            if (newheight>newheight2)
            {
            newheight=newheight2;
            newwidth=width/(height/newheight);
            }
          }
          else
          {
            newheight=height;
            newwidth=width;
          }                           
        }
        else if (width < height)
        {
          if(height>newheight)
          {
            var newwidth2=newwidth;
            newwidth = width / (height / newheight);
            if(newwidth > newwidth2)
            {
              newwidth=newwidth2;
              newheight=height / (width / newwidth);
            }
          }
          else
          {
            newheight=height;
            newwidth=width;
          }                               
        }
        else
        {
          if(width > newwidth)
          {
              newwidth = newheight;
          }
          else
          {
            newheight=height;
            newwidth=width;
          }                           
        }

        //Image Resizing ENDE

        showImage(ImageSource.src, newwidth, newheight);
        ImageViewerStatus = "showing";
        return true;
    }
    if(ImageViewerStatus == "start_loading")
    {
        ImageViewerStatus = "loading";
        showImage(ImageLoading.src, ImageLoading.width, ImageLoading.height);
    }
    if(ImageViewerStatus == "loading")
    {
        window.setTimeout("checkImage()", 150);
    }
    return true;
}

function showImage(imgSrc, boxwidth, boxheight)
{
    selecter = document.getElementById("farbenSelect");
				if(selecter)
				{
         		selecter.style.display = "none";
				}      
    viewer     = document.getElementById("ImageViewer");
    if(!viewer)
    {
        document.body.innerHTML = document.body.innerHTML + '<div id="ImageViewer"><\/div>';
        viewer     = document.getElementById("ImageViewer");
    }
    if(viewer)
    {
        var bildbreite=boxwidth;
        var bildhoehe=boxheight;
        viewer.align = "right";
        viewer.style.display="none";
        viewer.style.position="absolute";
        viewer.style.border="1px solid black";
        viewer.style.backgroundColor="white";
        viewer.innerHTML = 
          '<div style="padding: 10px;"><a class="admin_link" href=""' 
        + 'onclick="closeImage(); return false;"><img style="border-width: 0px;'
        + 'width:38px; height: 9px;" src="'+WEBDIR+'images/close3.gif" alt="Schlie&szlig;en"><\/a><br>'
        + '<div style="padding: 0px; margin: 0px;" id="ImageViewerContent"><\/div><\/div>';

        if(document.all)
        {
            boxtop    = document.body.scrollTop - 255;
            boxleft   = document.body.scrollLeft - 0;
        } else {
            boxtop    = window.pageYOffset - 255;
            boxleft   = window.pageXOffset - 0;
        }
        boxheight = boxheight + 59;
        boxwidth  = boxwidth + 40 + padding_corrector;

        viewer.style.top  = boxtop;
        viewer.style.left = boxleft;
        viewer.style.zIndex = 2000;        
        viewer.style.width  = boxwidth;
        viewer.style.height = boxheight;

        viewer_con = document.getElementById("ImageViewerContent");
        viewer_con.innerHTML = '<img style="margin-top:10px;margin-right:10px;" width="' + bildbreite + '" height="' + bildhoehe + '" src="' + imgSrc + '">';

        viewer.style.display = "inline";
    }

    return true;
}

function closeImage()
{
    ImageViewerStatus = "off";
    viewer = document.getElementById("ImageViewer");
    selecter = document.getElementById("farbenSelect");
    if(viewer)
    {
        viewer.style.display = "none";
				if(selecter)
				{
         		selecter.style.display = "inline";
				}        
        return true;
    }
    return false;
}


/*
    if(!viewer)
    {
        document.body.innerHTML = document.body.innerHTML 
        + '<div align="right" id="ImageViewer" style="display: none;'
        + 'z-index: 1000; background-color: white;'
        + 'border: 1px solid black;">'
        + '<div style="padding: 20px;"><a href=""' 
        + 'onclick="closeImage(); return false;"><img style="border-width: 0px;'
        + 'width:38px; height: 9px;" src="images/close3.gif" alt="Schlie&szlig;en"><\/a><br>'
        + '<div style="padding: 0px; margin: 0px;" id="ImageViewerContent"><\/div><\/div><\/div>';
//        alert(document.body.innerHTML);
        showImage(imgSrc, boxwidth, boxheight);
        return false;
    }
*/    

