function $(id)    { return document.getElementById(id); }
function sobj(id) { if( $(id) && $(id).id == id ) $(id).style.display='block' }
function hobj(id) { if( $(id) && $(id).id == id ) $(id).style.display='none' }

function ie_min_width()
{ 
  if (/MSIE 6.+Win/.test(navigator.userAgent))
  {
    sObj       = document.getElementsByTagName("body")[0].style; 
    sObj.width = (document.documentElement.clientWidth < 1000 ) ? "1000" : "auto"; 
  }

  if (/MSIE 5.+Win/.test(navigator.userAgent))
  {
    sObj = document.getElementsByTagName("body")[0].style; 

    if( document.body.clientWidth < 1000 )
      document.getElementById("page").style.width = "1000" ;
    else
      document.getElementById("page").style.width = "100%" ;

    fh();
  }
} 

if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) 
{
  window.attachEvent("onload",   ie_min_width);
  window.attachEvent("onresize", ie_min_width);
}

onload   = function() { fh(); prepare(); }
onresize = function() { fh() }

function fh()
{
  var cWidth = 0, cHeight = 0;
  
  if (typeof(window.innerWidth) == 'number') 
  {
    cWidth = window.innerWidth;
    cHeight = window.innerHeight;
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    cWidth = document.documentElement.clientWidth;
    cHeight = document.documentElement.clientHeight;
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    cWidth = document.body.clientWidth;
    cHeight = document.body.clientHeight;
  }
  
  var current_height = cHeight - 40 - 152 - 170 - 152 - 57 ;

  new_current_height = 0;
  if( $('poitems') ) 
    new_current_height = $('poitems').scrollHeight ;

  if( current_height < new_current_height )
    current_height = new_current_height

  if( $('content').className == 'main')
  { 
    $('content').height = current_height ;

    correct_scroller('actual',  current_height);
    correct_scroller('poffers', current_height);
    correct_scroller('exotic',  current_height);
    correct_scroller('iphotos', current_height);
  }
  
  correct_scroller('special', current_height);

  //  top - 40  //  header - 152  //  picture - 170  // footer  - 132  //  bottom - 57
  //  sum - 569

  return false ; 
}

function prepare() 
{ 
  j = 0;
  divs = document.getElementsByTagName('div')

  while( div = divs[j++] )
  {
    if( div.id == 'photos' || div.id == 'fotogallery' || div.id == 'fotogalleries')
    {
      for (i=0; i< div.childNodes.length; i++) 
      {
        node = div.childNodes[i];

        if( node.nodeName != 'DIV' ) continue ;

        if( node.childNodes[0].nodeName == 'IMG' && node.childNodes[0].className != "alone")
        {
          img = node.childNodes[0];

          img.onclick = function() 
          { 
            var re = new RegExp(".*_([0-9]+)\.jpg$","i");
            result = re.exec( this.src );

            if (result == null) return ;

            var type = 'f';

            if( this.parentNode.parentNode.id == 'photos' )
              type = 'c';

            if( this.parentNode.parentNode.className != '')
              type = this.parentNode.parentNode.className ;

            var id = RegExp.$1 ;

            open_photos_window( type, id );

            return false;
          }

          img.onmouseover = function() {  this.className += "iehover" }
          img.onmouseout  = function() {  this.className = this.className.replace(new RegExp("iehover"), "") }
        }

        if( node.childNodes[0].nodeName == 'A' && ( /MSIE 6.+Win/.test(navigator.userAgent) || /MSIE 5.+Win/.test(navigator.userAgent) ) )
        {
          node = node.childNodes[0];

          node.childNodes[0].onmouseover = function() {  this.className += "iehover" }
          node.childNodes[0].onmouseout  = function() {  this.className = this.className.replace(new RegExp("iehover"), "") }
        }
      }
    }

  }
}


function correct_scroller(id, pheight)
{
  if( $(id) )
  {
    if( id != "special" )
    {
      cheight  = pheight - 52 ;

      $( id ).style.height = cheight+"px" ;

      sobj( id );

      if( $(id).scrollHeight > $(id).clientHeight )
        sobj(id+'_scroller');
    }
    else
    {
      if( $(id).scrollHeight > $(id).clientHeight )
        sobj('scroller');
    }
  }
}

function scroll_up(id)   { $(id).scrollTop -= 20; return false }
function scroll_down(id) { $(id).scrollTop += 20; return false }

function scroll_fotos_up()   { $('iphotos').scrollTop -= 76; return false }
function scroll_fotos_down() { $('iphotos').scrollTop += 76; return false }
