

/* globals */
var selectedPic = null;
var resizeAllowed = true;
var urlresizepath = null;


/* will be called when an image is selected */
function onImageSet(id)
{
   var pic = s.getImageById(id);
    
   $('lightboxlink').href = pic.url;
   //$('lightboxlink').rel = "lightbox[fotoalbum]";
  
   if(selectedPic != null)
   {
      $('previmg' + selectedPic.id).className = $('previmg' + selectedPic.id).className.replace("_sel","");
      $('prevdiv' + selectedPic.id).className = $('prevdiv' + selectedPic.id).className.replace("_sel","");
   }
   
   $('previmg' + id).className = $('previmg' + id).className += "_sel";
   $('prevdiv' + id).className = $('prevdiv' + id).className += "_sel";
    
   selectedPic = pic;
   
   resizeAllowed = true;
   resizeImage();
}

/* sets and resizes the image to optimal width and height */
function resizeImage()
{
    
    if(resizeAllowed == false)
        return;
          
    var imagediv = $('imagediv');
    var img = $('containerimg');

    if (selectedPic == null)
        return;
        
    var previmg = $('previmg' + selectedPic.id);
    
    if(img == null || imagediv == null || previmg == null)
        return;
        
    var horiz = false;
    
    if(previmg.width >= previmg.height)
        horiz = true;
        
    if(horiz == false)
         DivResizer.resizeAll();
         
    var width = imagediv.offsetWidth-10;
    var height = imagediv.offsetHeight-10;
     
    if(selectedPic != null)
        img.src = urlresizepath + "?w=" + (width) + "&h=" + (height) + "&url=" + selectedPic.url; 
        
//    if(horiz == true)
//        imagediv.style.height = (img.height+10) + "px";

    resizeAllowed = false;
}

function onImageLoaded(img)
{
    var horiz = false;
    
    if(img.width >= img.height)
        horiz = true;
        
     if(horiz == true)
        imagediv.style.height = (img.height) + "px";
    
}
/* resize image when window gets resized */
function onFotoResize()
{
    resizeAllowed = true;
    resizeImage();
}

/* startet oder stopp diashow */
function toggleShow(imgbutton)
{
    if(imgbutton.src.indexOf('starten') >= 0)
    {
        s.play('s', 4000);
        imgbutton.src = "grafik/buttons/b_diashow_stoppen_off.gif"; 
    }
    else
    {
        s.stop();
        imgbutton.src = "grafik/buttons/b_diashow_starten_off.gif"; 
    }
        
}
