
  isDone = true;
  var cur_id = 0;   
  
  function cleanFilename (file_name)
  {
    var img_src = file_name;
    img_src = img_src.replace(/-/g,"_");
    img_src = img_src.replace(/\//g,"_");
    img_src = img_src.replace(/ /g,"_");
	img_src = img_src.replace(/\:/g,"_");
	img_src = img_src.replace(".jpg","");     
    img_src = img_src.replace(".gif","");           
    img_src = img_src.replace(".png","");           
    img_src = img_src.replace(/\./g,"_");
	return img_src;
  }
  
  function downloadLink (pic_id)
  {
    var text_header = headers[pic_id];
    document.getElementById("image_header").innerHTML = text_header;
    
    var text_link = 'Download <a href="'+hi_res[pic_id]+'">High resolution</a> ('+hi_res_size[pic_id]+') &nbsp; | &nbsp; <a href="'+lo_res[pic_id]+'">Low resolution</a> ('+lo_res_size[pic_id]+')';
    document.getElementById("download_link").innerHTML = text_link;
  }
  
  function loadImage (pic_id)
  // called form the thumbnail onclick
  // pic_id = image position in the imageName array
  {
    if (isDone)
    {
      // alert('LOAD IMAGE ' + pic_id + ': ' + cleanFilename(imageName[pic_id])+".src -> " + eval(cleanFilename(imageName[pic_id])+".src"));
      if (document.all)
        document.images['pic_after'].src=eval (cleanFilename(imageName[pic_id])+".src");
      else
        document.images['pic_after'].src=eval (cleanFilename(imageName[pic_id])+".src");

      cur_id  = pic_id;
      downloadLink (pic_id);
      opacity('blending', 100, 0, 1000)
      isDone = false;
    }
  }

  function opacity(id, opacStart, opacEnd, millisec) {
      //speed for each frame
      var speed = Math.round(millisec / 100);
      var timer = 0;
  
      //determine the direction for the blending, if start and end are the same nothing happens
      if(opacStart > opacEnd) {
          for(i = opacStart; i >= opacEnd; i--) {
              setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
              timer++;
          }
      } else if(opacStart < opacEnd) {
          for(i = opacStart; i <= opacEnd; i++)
              {
              setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
              timer++;
          }
      }
  }
  
  //change the opacity for different browsers
  function changeOpac(opacity, id) {
      var object = document.getElementById(id).style;
      object.opacity = (opacity / 100);
      object.MozOpacity = (opacity / 100);
      object.KhtmlOpacity = (opacity / 100);
      object.filter = "alpha(opacity=" + opacity + ")";

    if (opacity == 0)
    {
      isDone = true;      
      if (document.all)
        document.images['pic_before'].src=eval (cleanFilename(imageName[cur_id])+".src");
      else
        document.images['pic_before'].src=eval (cleanFilename(imageName[cur_id])+".src");

      changeOpac(100, id)
    }
  }   

  function niftyOnLoad(){
  if(!NiftyCheck())
    return;
  Rounded("div#nifty","all","#000000","#000000","smooth");
  }
  
