var ObjPopupId = '';

function goTo(Url){ document.location.href=Url; }
function obj(Id) { if(Id!='' && document.getElementById(Id)) return document.getElementById(Id); else return false; }
function objStyle(Id) { if(Id!='' && document.getElementById(Id)) return document.getElementById(Id).style; else return false; }
function objHide(Id) { if(Id!='' && document.getElementById(Id)) document.getElementById(Id).style.display='none'; }
function objShow(Id) { if(Id!='' && document.getElementById(Id)) document.getElementById(Id).style.display='block'; }
function isObj(Id) { if(Id!='' && document.getElementById(Id)) return true; else return false; }
function bgChange(Id, ImgSrc) { objStyle(Id).backgroundImage = "url("+ImgSrc+")"; }
function objPopup(Id){
  if( Id!=ObjPopupId ) objHide(ObjPopupId);
  if( objStyle(Id).display=='block' ) objStyle(Id).display='none';
  else  objStyle(Id).display='block';
  ObjPopupId = Id;
}

/**********************/

function menu_left (obj){
  var li = $(obj).getParent();
  var ul = li.getElement('ul');
  if( ul.getStyle('display')=='block' )
    ul.setStyle('display', 'none');
  else
    ul.setStyle('display', 'block');
}

function change_product_foto(Src, SrcBig){
  if( isObj('product_foto') ){
    $('product_foto').src = Src;
    $('product_foto').getParent().href = SrcBig;
  }
}

/********************/

function getOuterSize(Return){
  var w=0, h=0;
  if( typeof( window.innerWidth ) == 'number' ) {
    w = window.innerWidth;
    h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  if(Return=='w') return w;
  else if(Return=='h') return h;
  else return Array(w,h);
}

window.addEvent('domready', function(){
  var OuterSize = getOuterSize();
  var BodyHeight = $('body').getSize().y;

// fit backgrounds
  var BgWidth = ( OuterSize[0]<=1280 ) ? 1280 : 1600;
  var BgHeight = ( BodyHeight<600 ) ? 'small' : 'big';
  bgChange('top', 'images/bg_top'+BgWidth+'.jpg');
  bgChange('container', 'images/bg_'+BgHeight+BgWidth+'.jpg');

// set footert size
  if( isObj('page_footer') ){
    var H = OuterSize[1] - $('page_footer').getPosition().y;
    if( H>0  ) objStyle('page_footer').height = H+'px';
  }
});

