function $(id)   { return document.getElementById(id); }

function ie_fix_width()
{ 
  var id_conteiners = [ 'outer', 'couter' ];

  for (var i in id_conteiners) 
  {
    var conteiner = id_conteiners[i];
   
    if( $(conteiner) )
    {
      if (/MSIE 7.+Win/.test(navigator.userAgent))
      {
        sObj = document.getElementsByTagName("body")[0].style; 
        
        if( document.documentElement.clientWidth > 1024 )
          $('conteiner').style.width = "1024px";
      }

      if (/MSIE 6.+Win/.test(navigator.userAgent))
      {
        sObj = document.getElementsByTagName("body")[0].style; 
        sObj.width = (document.documentElement.clientWidth < 1000 ) ? "1024px" : "100%"; 

        if( $('conteiner') )
          if( document.body.clientWidth < 1024 )
            $('conteiner').width = "100%" ;
          else
            $('conteiner').style.width = "1024px";

        if( $('private') )
          if( document.documentElement.clientWidth < 1100 )
            $('private').style.width = "720px";
          else
            $('private').style.width = "750px";
      }

      if (/MSIE 5.+Win/.test(navigator.userAgent))
      {
        sObj = document.getElementsByTagName("body")[0].style; 

        if( document.body.clientWidth < 1024 && $('conteiner') )
          $('conteiner').width = "100%" ;
        else
          $('conteiner').style.width = "1024px";

        if( document.documentElement.clientWidth < 1100 && $('private') )
          $('private').style.width = "720px";
        else
          $('private').style.width = "750px";
      }
    }
  }
} 

if( window.attachEvent && navigator.userAgent.indexOf("Opera")==-1 ) 
{
  window.attachEvent("onload",   ie_fix_width);
  window.attachEvent("onresize", ie_fix_width);
}

onload = function ()
{
  if (/Safari/.test(navigator.userAgent) && $('couter') )
  {
    sObj = document.getElementsByTagName("body")[0].style; 
    
    if( document.documentElement.clientWidth > 1024 )
      $('couter').style.width = "1024px";
  }

  if( $('couter') )
  {
    if (/MSIE/.test(navigator.userAgent))
      $('couter').style.display = 'block';
    else
      $('couter').style.display = 'table';
  }

  if( screen.width == 1024 && $('couter') )
    $('couter').style.width = "100%";


  init_scrollbars();
}

function sf( s, id, w, h, t )
{
  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 scrOfX = 0, scrOfY = 0;

  if(typeof(window.pageYOffset) == 'number') 
  {
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  w += 60;
  h += 60;

  var wc = parseInt((cWidth-w)/2)  + scrOfX ;
  var hc = parseInt((cHeight-h)/2) + scrOfY ;

  document.getElementById('popup').style.top     = hc + "px"; 
  document.getElementById('popup').style.left    = wc + "px"; 
  document.getElementById('popup').style.width   = w + "px"; 
  document.getElementById('popup').style.height  = h + "px"; 
  document.getElementById('popup').style.display = 'block';

  document.getElementById('pimg').style.display = 'none';

  var isrc = 'http://'+window.location.host+'/p/'+s+'/'+id+'.img';

  if( document.getElementById('pimg').src != isrc )
  {
    document.getElementById('pimg').onload = function() { this.style.display = 'block' }
    document.getElementById('pimg').src   = '/p/'+s+'/'+id+'.img';
  }
  else
    document.getElementById('pimg').style.display = 'block';

  document.getElementById('pimg').title = t ;

  return false ; 
}

function hf()
{
  document.getElementById('popup').style.display = 'none';
}


function init_scrollbars()
{
  if( $('cdata') )
  {
    var scrollArea = new dw_scrollObj('content', 'cdata', null);
   
    scrollArea.setUpScrollbar("drag-bar", "drag-area", "v", 1, 1);

    // buttons events 
/*    $('scroll-bup').onmouseup   = function() { dw_scrollObj.resetSpeed('content')      } 
    $('scroll-bup').onmousedown = function() { dw_scrollObj.doubleSpeed('content')     } 
    $('scroll-bup').onmouseover = function() { dw_scrollObj.initScroll('content','up') }
    $('scroll-bup').onclick     = function() { return false }
    $('scroll-bup').onmouseout  = function() { dw_scrollObj.stopScroll('content')      }

    if( $('scroll-bdown').childNodes[0].nodeName == 'IMG' )
      $('scroll-bdown').childNodes[0].onfocus = function() { this.blur() }

    $('scroll-bdown').onmouseup   = function() { dw_scrollObj.resetSpeed('content')      } 
    $('scroll-bdown').onmousedown = function() { dw_scrollObj.doubleSpeed('content')     } 
    $('scroll-bdown').onmouseover = function() { dw_scrollObj.initScroll('content','down') }
    $('scroll-bdown').onclick     = function() { return false }
    $('scroll-bdown').onmouseout  = function() { dw_scrollObj.stopScroll('content')      }
    if( $('scroll-bdown').childNodes[0].nodeName == 'IMG' )
      $('scroll-bdown').childNodes[0].onfocus = function() { this.blur() }
  */
  }
}

