function preloadImages()
  {
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }
  //----------------------------------------------------------------------------
  
  function ShowImgOnCover(w, h, img_url)
  {
    window.scrollTo(0, 0);
    page_h = Math.max(document.body.clientHeight, document.body.scrollHeight);
    page_height = document.body.clientHeight;
    page_width = document.body.clientWidth;

    TheCoverDiv = document.getElementById('cover_div');
    TheMainDiv = document.getElementById('main_div');
    TheMainImg = document.getElementById('main_img');
    TheLoadingImg = document.getElementById('c_loading_img');

    TheCoverDiv.style.width = document.body.scrollWidth + 'px';
    TheCoverDiv.style.height = page_h + 'px';
    TheCoverDiv.style.visibility = "visible";
    TheLoadingImg.style.left = (page_width/2 - 70) + 'px';
    TheLoadingImg.style.top = (page_height/2 - 16) + 'px';
    TheLoadingImg.style.visibility = "visible";
    TheMainDiv.style.visibility = "visible";
    TheMainImg.style.width = w;
    TheMainImg.style.height = h;
    TheMainImg.src = "files/preview.php?file="+escape(img_url)+"&w="+w+"&h="+h+"&b=true";
    TheMainDiv.style.left = (page_width/2 - w/2) + 'px';
    TheMainDiv.style.top = (page_height/2 - h/2) + 'px';
  }
  //----------------------------------------------------------------------------

  function ResizeCover()
  {
    TheCoverDiv = document.getElementById('cover_div');
    if(TheCoverDiv.style.visibility == 'visible')
    {
      page_h = Math.max(document.body.clientHeight, document.body.scrollHeight);
      page_height = document.body.clientHeight;
      page_width = document.body.clientWidth;
      TheMainDiv = document.getElementById('main_div');
      TheMainImg = document.getElementById('main_img');
      TheLoadingImg = document.getElementById('c_loading_img');

      TheCoverDiv.style.width = document.body.clientWidth + 'px';
      TheCoverDiv.style.height = page_h + 'px';
      TheLoadingImg.style.left = (page_width/2 - 70) + 'px';
      TheLoadingImg.style.top = (page_height/2 - 16) + 'px';
      w = parseInt(TheMainImg.style.width);
      h = parseInt(TheMainImg.style.height);
      TheMainDiv.style.left = (page_width/2 - w/2) + 'px';
      TheMainDiv.style.top = (page_height/2 - h/2) + 'px';
    }
  }
  //----------------------------------------------------------------------------

  function HideCover()
  {
    document.getElementById('cover_div').style.visibility = 'hidden'
    document.getElementById('main_div').style.visibility = 'hidden'
    document.getElementById('c_loading_img').style.visibility = 'hidden'
    document.getElementById('main_img').src = 'images/blank.gif';
  }
  //----------------------------------------------------------------------------
  
  function CreateHttpConnection()
  {
    var http_request = false;
    if (window.XMLHttpRequest)
    {
      try {
        http_request = new XMLHttpRequest();
      }
      catch (e)
      {
        http_request = false;
      }
    }
    else
    {
      if (window.ActiveXObject)
      {
        try
        {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
          http_request = false;
        }
      }
      else
      {
        http_request = false;
      }
    }
    return http_request;
  }
  //----------------------------------------------------------------------------
  
  function mOver(mName)
  {
    document.getElementById(mName).style.backgroundImage = 'url(images/bg_m_'+mName+'.gif)';
  }
  //----------------------------------------------------------------------------

  function mOut(mName)
  {
    document.getElementById(mName).style.backgroundImage = '';
  }
  //----------------------------------------------------------------------------

  function mClick(mName)
  {
    window.location.href = mName;
  }
  //----------------------------------------------------------------------------
  
  function CountLetters(theTextarea, max, counter)
  {
    numOfLetters = theTextarea.value.length;
    if(numOfLetters < max)
    {
      window.document.getElementById(counter).innerHTML = (max-numOfLetters);
    }
  }
  //----------------------------------------------------------------------------

  function CheckLetters(theTextarea, max, counter)
  {
    numOfLetters = theTextarea.value.length;
    if(numOfLetters >= max)
    {
      theTextarea.value = theTextarea.value.substring(0, max-1);
      return false;
    }
    else
    {
      window.document.getElementById(counter).innerHTML = (max-numOfLetters);
      return true;
    }
  }
  //----------------------------------------------------------------------------
  
  function start_image_rotator()
      {
        setTimeout("next_img()", next_time);
        if(curr_img < images_count-1)
        {
          next_img2 = curr_img+1;
        }
        else
        {
          next_img2 = 0;
        }
        preloadImages('images/photo_top_'+(next_img2)+'.jpg');
      }
      
      function next_img()
      {
        if(curr_img < images_count-1)
        {
          curr_img++;
        }
        else
        {
          curr_img = 0;
        }
        document.getElementById('photo_top_bottom').src = document.getElementById('photo_top_top').src;
        document.getElementById('photo_top_top').style.opacity = '0';
	      document.getElementById('photo_top_top').style.filter = 'alpha(opacity=0)';
        document.getElementById('photo_top_top').src = 'images/photo_top_'+(curr_img)+'.jpg';
        fade_in(0);
      }
      
      function fade_in(curr_opacity)
      {
        document.getElementById('photo_top_top').style.opacity = curr_opacity/10;
	      document.getElementById('photo_top_top').style.filter = 'alpha(opacity='+(curr_opacity*10)+')';
        if(curr_opacity < 10)
	      {
          setTimeout("fade_in("+(curr_opacity+1)+")", 70);
        }
      }
