var IE= (document.all);
var TmpElement;
var SelectedBtn;

var ShrinkMnuElement;
var GrowMnuElement;
var PrevMnuElement;

var ShrinkMnuHeight;
var ShrinkMnuWidth;
var ShrinkMnuHeightMax;
var ShrinkMnuHeightMin;
var ShrinkMnuWidthMax;
var ShrinkMnuFontSize;
var ShrinkMnuFontSizeMax;
var ShrinkMnuCurrZoom;
var ShrinkMnuZoomMin;
var ShrinkMnuZoomMax;
var ShrinkMnuDeltaZoom;

var GrowMnuHeight;
var GrowMnuWidth;
var GrowMnuHeightMax;
var GrowMnuWidthMax;
var GrowMnuFontSize;
var GrowMnuFontSizeMax;
var GrowMnuCurrZoom;
var GrowMnuZoomMin;
var GrowMnuZoomMax;
var GrowMnuDeltaZoom;
var onBtnImg;
var offBtnImg;
var onBtnImg2;
var offBtnImg2;
var langRusOn;
var langRusOff;
var langUkrOn;
var langUkrOff;

function isString(object) 
{
  return typeof object == "string";
}

function $(element) 
{
  if (isString(element))
  {
    element = document.getElementById(element);
  }
  return element;
}


function isUndefined(object) 
{
    return typeof object == "undefined";
} 

function isDefined(object) 
{
    return typeof object != "undefined";
} 
/*
function getStyle(el,styleProp)
{
	
    var x = $(el);
    if (x)
    {
	  if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	  else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	  return y;
    }
    else
        return '';
}
*/
/*
function setOpacity(element, value)
{
    element = $(element);
    element.style.opacity = (value == 1 || value === '') ? '' :
      (value < 0.00001) ? 0 : value;
    return element;
}
*/
/*
function setStyle(element, styles)
{
    element = $(element);
    var elementStyle = element.style, match;
    if (isString(styles)) 
	{
      element.style.cssText += ';' + styles;
      return styles.include('opacity') ?
        element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
    }
    for (var property in styles)
      if (property == 'opacity') setOpacity(element, styles[property]);
      else
        elementStyle[(property == 'float' || property == 'cssFloat') ?
          (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
            property] = styles[property];

    return element;
}
*/
/*
function SetSmnuHeight()
{
  if (SMnuElment)
  {
    if (CurrZoom<=ZoomMax)
    {
      //alert ('SetSmnu Height: '+Height+' '+MaxHeight+' '+DeltaH);
      //alert ('SetSmnu Width: '+Width+' '+MaxWidth+' '+CurrZoom);
      SMnuElment.style.height=Height+'px';
      SMnuElment.style.width=Width+'px';
	  if (SMnuElment.currentStyle)
	  {
	    SMnuElment.style['font-size']=FontSize+'px';
	  }
	  else
	  {
	    SMnuElment.style.fontSize=FontSize+'px';
	  }
      CurrZoom+=DeltaZoom;
      Height=MaxHeight*(CurrZoom/100);
      Width=MaxWidth*(CurrZoom/100);
	  FontSize=FontSizeMax*(CurrZoom/100);
	  
      setTimeout('SetSmnuHeight()', 50);
    }
  }
}
*/
/*
function setDimensions(element, height, width, fontSize, color)
{
  element=$(element);
  element.style.height=height+'px';
  //element.style.width=width+'px';
  element.style.color=color;
  //if (element.currentStyle)
  //{
	//element.style['font-size']=fontSize+'px';
  //}
  //else
  //{
    //element.style.fontSize=fontSize+'px';
  //}
}
*/
function setDimensions2(element, height, color)
{
  element=$(element);
  element.style.height=height+'px';
  element.style.color=color;
}

/*
function GrowMenu()
{
  if (GrowMnuElement)
  {
    alert('Grow Menu H:'+GrowMnuHeight+' W:'+GrowMnuWidth);
    GrowMnuElement.style.display='inline';
    GrowMnuElement.style.visibility='visible';
	if (GrowMnuCurrZoom<=GrowMnuZoomMax)
    {
      //alert ('SetSmnu Height: '+GrowMnuHeight+' '+MaxHeight+' '+DeltaH);
      //alert ('SetSmnu Width: '+Width+' '+MaxWidth+' '+CurrZoom);
	  setDimensions(GrowMnuElement, GrowMnuHeight, GrowMnuWidth, GrowMnuFontSize, '#000000');
      GrowMnuCurrZoom+=GrowMnuDeltaZoom;
      GrowMnuHeight=GrowMnuHeightMax*(GrowMnuCurrZoom/100);
      GrowMnuWidth=GrowMnuWidthMax*(GrowMnuCurrZoom/100);
	  GrowMnuFontSize=GrowMnuFontSizeMax*(GrowMnuCurrZoom/100);
	  
      //setTimeout('GrowMenu()', 50);
    }
	else
	{
	  PrevMnuElement=GrowMnuElement;
	  GrowMnuElement=null;
      //alert ('finish grow menu');
	}
  }
}
*/
function RollDown()
{
  if (GrowMnuElement)
  {
    GrowMnuElement.style.visibility='visible';
    if (GrowMnuHeight<=GrowMnuHeightMax)
    {
      //alert('RollDown H:'+GrowMnuHeight+' MH:'+GrowMnuHeightMax);
      setDimensions2(GrowMnuElement, GrowMnuHeight, '#000000');
      GrowMnuHeight+=GrowMnuDeltaZoom;
    }
    else
    {
      PrevMnuElement=GrowMnuElement;
	  GrowMnuElement=null;
      //alert('RollDown finish');
    }
  }
}

function RollUp()
{
  if (ShrinkMnuElement)
  {
    ShrinkMnuElement.style.visibility='visible';
    if (ShrinkMnuHeight>=ShrinkMnuHeightMin)
    {
      //alert('RollUp H:'+ShrinkMnuHeight+' MiH:'+ShrinkMnuHeightMin);
      setDimensions2(ShrinkMnuElement, ShrinkMnuHeight, '#000000');
      ShrinkMnuHeight-=ShrinkMnuDeltaZoom;
    }
    else
    {
      ShrinkMnuElement.style.visibility='hidden';
      setDimensions2(ShrinkMnuElement, ShrinkMnuHeightMin, '#FFFFFF');
      ShrinkMnuElement=null;
      //alert('RollUp Finish');
    }
  }
}
/*
function ShrinkMenu()
{
  if (ShrinkMnuElement)
  {
    //alert('ShrinkMenu H:'+ShrinkMnuHeight+' W:'+ShrinkMnuWidth+' Z:'+ShrinkMnuCurrZoom);
    if (ShrinkMnuCurrZoom>=ShrinkMnuZoomMin)
	{
	  setDimensions(ShrinkMnuElement, ShrinkMnuHeight, ShrinkMnuWidth, ShrinkMnuFontSize, '#000000');
      ShrinkMnuCurrZoom-=ShrinkMnuDeltaZoom;
      ShrinkMnuHeight=ShrinkMnuHeightMax*(ShrinkMnuCurrZoom/100);
      ShrinkMnuWidth=ShrinkMnuWidthMax*(ShrinkMnuCurrZoom/100);
	  ShrinkMnuFontSize=ShrinkMnuFontSizeMax*(ShrinkMnuCurrZoom/100);
	  
      //setTimeout('ShrinkMenu()', 50);
	}
	else
	{
	  ShrinkMnuElement.style.visibility='hidden';
      //alert ('dims set to zeros');
	  setDimensions(ShrinkMnuElement, 0, 0, 0, '#FFFFFF');
	  ShrinkMnuElement=null;
	}
	
  }
}
*/
/*
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
*/
/*
function getClientHeight()
{
  
  //return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
  
  //var windowHeight;
  //if(window.innerHeight)
  //{ 
//	windowHeight=window.innerHeight; 
  //} else if(document.documentElement && document.documentElement.clientHeight)
  //{ 
//	windowHeight=document.documentElement.clientHeight; 
  //} else if(document.body)
  //{ 
	//windowHeight=document.body.clientHeight; 
  //}
  //return windowHeight
  
  
  //var documentHeight;
  //if(document.height) // Mozilla, Opera...
  // documentHeight = document.height;
  //else // IE
  // documentHeight = document.body.scrollHeight;
  // return documentHeight;
   
   
   //var documentHeight;
   //documentHeight = document.documentElement.clientHeight; // FF, Safari, IE
   //if(documentHeight < document.body.scrollHeight) // Opera
   //  documentHeight = document.body.scrollHeight;
   //return documentHeight;
   
   
   var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
 winWidth = window.innerWidth;
 winHeight = window.innerHeight;
} else {
 if (d.documentElement && 
  typeof d.documentElement.clientWidth!='undefined' && 
   d.documentElement.clientWidth!==0) {
  winWidth = d.documentElement.clientWidth;
  winHeight = d.documentElement.clientHeight;
 } else {
  if (d.body && 
   typeof d.body.clientWidth!='undefined') {
   winWidth = d.body.clientWidth;
   winHeight = d.body.clientHeight;
  }
 }
}

return winHeight;
}
*/
function getWindowHeight() 
{
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&document.documentElement.clientHeight) {
      windowHeight=document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function setContentSize()
{
  var h, h_old;
  var headerTR, logoTR, contentTR, footerTR, contentTable;
  var headerTR_h, logoTR_h, contentTR_h, footerTR_h;

  
  headerTR=$('headerTR');
  logoTR=$('logoTR');
  contentTR=$('contentTR');
  footerTR=$('footerTR');
  contentTable=$('contentTable');
  
  if (headerTR)
  {
    if(headerTR.offsetHeight)
    {
      headerTR_h=headerTR.offsetHeight;
    }
    else if(headerTR.style.pixelHeight)
    {
      headerTR_h=headerTR.style.pixelHeight;
    } 
    
  }
  
  if (logoTR)
  {
    if(logoTR.offsetHeight)
    {
      logoTR_h=logoTR.offsetHeight;
    }
    else if(logoTR.style.pixelHeight)
    {
      logoTR_h=logoTR.style.pixelHeight;
    } 
    
  }
  
  if (contentTR)
  {
    if(contentTR.offsetHeight)
    {
      contentTR_h=contentTR.offsetHeight;
    }
    else if(contentTR.style.pixelHeight)
    {
      contentTR_h=contentTR.style.pixelHeight;
    } 
    
  }
  
  if (footerTR)
  {
    if(footerTR.offsetHeight)
    {
      footerTR_h=footerTR.offsetHeight;
    }
    else if(footerTR.style.pixelHeight)
    {
      footerTR_h=footerTR.style.pixelHeight;
    } 
    
  }
  
  //alert('headerTR_h:'+headerTR_h);
  //alert('logoTR_h:'+logoTR_h);
  //alert('contentTR_h:'+contentTR_h);
  //alert('footerTR_h:'+footerTR_h);
  
  h=getWindowHeight();
  
  //alert('h: '+h);
  
  if (contentTR)
  {
    h_old=h-headerTR_h-logoTR_h-footerTR_h;
    //alert('h_old: '+h_old);
    
    if(contentTable)
    {
      h_old=h_old-20;
      contentTable.style.height=h_old+20+'px';
      //alert('h_old: '+h_old);
    }
    
    contentTR.style.height=h_old+'px';
  }
  /*
  if (headerTR)
  {
    if(headerTR.offsetHeight)
    {
      headerTR_h=headerTR.offsetHeight;
    }
    else if(headerTR.style.pixelHeight)
    {
      headerTR_h=headerTR.style.pixelHeight;
    } 
    
  }
  
  if (logoTR)
  {
    if(logoTR.offsetHeight)
    {
      logoTR_h=logoTR.offsetHeight;
    }
    else if(logoTR.style.pixelHeight)
    {
      logoTR_h=logoTR.style.pixelHeight;
    } 
    
  }
  
  if (contentTR)
  {
    if(contentTR.offsetHeight)
    {
      contentTR_h=contentTR.offsetHeight;
    }
    else if(contentTR.style.pixelHeight)
    {
      contentTR_h=contentTR.style.pixelHeight;
    } 
    
  }
  
  if (footerTR)
  {
    if(footerTR.offsetHeight)
    {
      footerTR_h=footerTR.offsetHeight;
    }
    else if(footerTR.style.pixelHeight)
    {
      footerTR_h=footerTR.style.pixelHeight;
    } 
    
  }
  
  alert('headerTR_h:'+headerTR_h);
  alert('logoTR_h:'+logoTR_h);
  alert('contentTR_h:'+contentTR_h);
  alert('footerTR_h:'+footerTR_h);
  */
}

function onResize()
{
  setContentSize();
}

function OnLoad()
{
  
  setContentSize();
  
  onBtnImg = new Image();
  onBtnImg.src='imgs/btn_bg_on.gif';
  
  offBtnImg = new Image();
  offBtnImg.src='imgs/btn_bg_off.gif';
  
  langRusOn= new Image();
  langRusOn.src='imgs/rus_on.gif';
  langRusOff= new Image();
  langRusOff.src='imgs/rus_off.gif';
  
  langUkrOn= new Image();
  langUkrOn.src='imgs/ukr_on.gif';
  langUkrOff= new Image();
  langUkrOff.src='imgs/ukr_off.gif';
  
  
}

function OnLoad2()
{
  setContentSize();
  
  onBtnImg = new Image();
  onBtnImg.src='imgs/btn2_on.gif';
  
  offBtnImg = new Image();
  offBtnImg.src='imgs/btn2_off.gif';
  
  langRusOn= new Image();
  langRusOn.src='imgs/rus_on.gif';
  langRusOff= new Image();
  langRusOff.src='imgs/rus_off.gif';
  
  langUkrOn= new Image();
  langUkrOn.src='imgs/ukr_on.gif';
  langUkrOff= new Image();
  langUkrOff.src='imgs/ukr_off.gif';
  
  
}

function HighlightButton(el)
{
  //alert('HighlightButton');
  el=$(el);
  if (SelectedBtn!=el)
  {
    el.style.color='#000000';
    el.style.background='url(imgs/btn_bg_on.gif)';
  }
}

function DownlightButton(el)
{
  //alert('DownlightButton');
  el=$(el);
  if (SelectedBtn!=el)
  {
    el.style.color='#FFFFFF';
    el.style.background='url(imgs/btn_bg_off.gif)';
  }
}

function HighlightButton2(el)
{
  //alert('HighlightButton');
  el=$(el);
  if (SelectedBtn!=el)
  {
    el.style.color='#000000';
    el.style.background='url(imgs/btn2_on.gif)';
  }
}

function DownlightButton2(el)
{
  //alert('DownlightButton');
  el=$(el);
  if (SelectedBtn!=el)
  {
    el.style.color='#FFFFFF';
    el.style.background='url(imgs/btn2_off.gif)';
  }
}
/*
function GrowNew(element, steps, h, w, fs)
{
	//alert('GrowNew');
	GrowMnuElement=element;
	GrowMnuHeight=0;
	GrowMnuWidth=w;
	GrowMnuHeightMax=h;
	GrowMnuWidthMax = w;
	GrowMnuFontSize=fs;
	GrowMnuFontSizeMax= fs;

	GrowMnuCurrZoom=0;
	GrowMnuZoomMax=100;
	GrowMnuDeltaZoom=(GrowMnuZoomMax-GrowMnuCurrZoom)/steps;
	TmpElement=element;
    //alert('GrowNew HM:'+GrowMnuHeightMax+' WM:'+GrowMnuWidthMax);
	//GrowMenu();
    
}
*/
function RollDownNew(element, steps, h)
{
  GrowMnuElement=element;
  GrowMnuHeight=8;
  GrowMnuHeightMax=h;
  GrowMnuCurrZoom=0;
  GrowMnuZoomMax=100;
  GrowMnuDeltaZoom=(GrowMnuHeightMax-GrowMnuHeight)/steps;
  TmpElement=element;
  
}
/*
function ShrinkPrev(element, steps)
{
	//alert ('shrinkprev');
    ShrinkMnuElement=$(element);
	ShrinkMnuHeightMax=ShrinkMnuElement.offsetHeight;
    ShrinkMnuHeight=ShrinkMnuHeightMax;
	ShrinkMnuWidthMax = ShrinkMnuElement.offsetWidth;
    ShrinkMnuWidth=ShrinkMnuWidthMax;
    //alert ('shrinkprev - getted dims');
	ShrinkMnuFontSizeMax= getStyle(ShrinkMnuElement, 'fontSize');
      if (ShrinkMnuFontSizeMax=='')
      {
        ShrinkMnuFontSizeMax=getStyle(ShrinkMnuElement, 'font-size');
      }
      ShrinkMnuFontSizeMax=ShrinkMnuFontSizeMax.split('px')[0];
      
      ShrinkMnuFontSize=ShrinkMnuFontSizeMax;
    //alert ('shrinkprev - getted fontsize');
	ShrinkMnuCurrZoom=100;
	ShrinkMnuZoomMax=100;
	ShrinkMnuZoomMin=0;
	ShrinkMnuDeltaZoom=(ShrinkMnuZoomMax-ShrinkMnuZoomMin)/steps;
	//ShrinkMenu();
    //alert ('finish shrinkprev');
}
*/
function RollUpPrev(element, steps, h)
{
  ShrinkMnuElement=$(element);
  ShrinkMnuHeightMax=ShrinkMnuElement.offsetHeight;
  ShrinkMnuHeight=ShrinkMnuHeightMax;
  ShrinkMnuHeightMin=8;
  ShrinkMnuCurrZoom=100;
  ShrinkMnuZoomMax=100;
  ShrinkMnuZoomMin=0;
  ShrinkMnuDeltaZoom=(ShrinkMnuHeightMax-ShrinkMnuHeightMin)/steps;
  
}
function AnimateMnu()
{
  if (GrowMnuElement)
  {
    //alert ('animate RollDown');
    //GrowMenu();
    RollDown();
    
  }
  
  if (ShrinkMnuElement)
  {
    //alert ('animate RollUp');
    //ShrinkMenu();
    RollUp();
  }
  
  if ((ShrinkMnuElement)||(GrowMnuElement))
  {
    setTimeout('AnimateMnu()', 30);
  }
}

function SetBtnOn(element)
{
  element=$(element);
  element.style.color='#000000';
  element.style.background='url(imgs/btn_bg_on.gif)';
  
  SelectedBtn=element;
}

function SetBtnOff(element)
{
  element=$(element);
  if (element)
  {
    element.style.color='#FFFFFF';
    element.style.background='url(imgs/btn_bg_off.gif)';
  }
  SelectedBtn=null;
  
}

function SetBtnOn2(element)
{
  element=$(element);
  element.style.color='#000000';
  element.style.background='url(imgs/btn2_on.gif)';
  
  SelectedBtn=element;
}

function SetBtnOff2(element)
{
  element=$(element);
  if (element)
  {
    element.style.color='#FFFFFF';
    element.style.background='url(imgs/btn2_off.gif)';
  }
  SelectedBtn=null;
  
}

function MnuClick(element, btn_el, h, w, fs)
{
  var steps=30;
  
  //alert('MnuCLick '+element);
  
  element=$(element);
  btn_el=$(btn_el);
  
  if (PrevMnuElement)
  {
    //we have growed meu -shrik it
    //alert ('PrevMnuElement is defined');
    
    //alert('roll up prev');
	//ShrinkPrev(PrevMnuElement, steps);
    RollUpPrev(PrevMnuElement, steps);
    
    if (element)
    {
      //we have new submnu
      
      if (PrevMnuElement!=element)
      {
        //alert('roll down new');
	    //GrowNew(element, steps, h, w, fs);
        RollDownNew(element, steps, h);
      }
      else
      {
        //alert('null prev');
	    PrevMnuElement=null;
      }
      
    } //if (element)
    else
    {
      //we dont have new submnu
      //alert('null prev');
	  PrevMnuElement=null;
    }
	
  }
  else
  {
    //alert ('PrevMnuElement is UNdefined');
    if (element)
    {
      //alert ('rolldown new');
	  //GrowNew(element, steps, h, w, fs);
      RollDownNew(element, steps, h);
    }
  }
  
  if (btn_el)
  {
    //alert('set buttons')
    if (btn_el!=SelectedBtn)
    {
      SetBtnOff(SelectedBtn);
      SetBtnOn(btn_el);
    }
    else
    {
      SetBtnOff(SelectedBtn);
    }
    
  }
  
  
  AnimateMnu();
}
/*
function MnuClick_old(element, btn_el, h, w, fs)
{
  var steps=60;
  
  //alert('MnuCLick '+element);
  
  element=$(element);
  btn_el=$(btn_el);
  
  if (PrevMnuElement)
  {
    //we have growed meu -shrik it
	if (PrevMnuElement!=element)
	{
	  //alert('shrink prev');
	  ShrinkPrev(PrevMnuElement, steps);
      if (element)
      {
        //alert('grow new');
	    GrowNew(element, steps, h, w, fs);
      }
	}
	else
	{
	  //alert('shrink prev null prev');
	  ShrinkPrev(PrevMnuElement, steps);
      //alert('null prev');
	  PrevMnuElement=null;
	  
	}
	
  }
  else
  {
    if (element)
    {
      //alert ('grow new');
	  GrowNew(element, steps, h, w, fs);
    }
  }
  
  if (btn_el)
  {
    //alert('set buttons')
    if (btn_el!=SelectedBtn)
    {
      SetBtnOff(SelectedBtn);
      SetBtnOn(btn_el);
    }
    else
    {
      SetBtnOff(SelectedBtn);
    }
    
  }
  
  
  AnimateMnu();
}
*/
function MnuClick2(element, btn_el, h, w, fs)
{
  var steps=30;
  
  //alert('MnuCLick '+element);
  
  element=$(element);
  btn_el=$(btn_el);
  
  if (PrevMnuElement)
  {
    //we have growed meu -shrik it
    //alert ('PrevMnuElement is defined');
    
    //alert('roll up prev');
	//ShrinkPrev(PrevMnuElement, steps);
    RollUpPrev(PrevMnuElement, steps);
    
    if (element)
    {
      //we have new submnu
      
      if (PrevMnuElement!=element)
      {
        //alert('roll down new');
	    //GrowNew(element, steps, h, w, fs);
        RollDownNew(element, steps, h);
      }
      else
      {
        //alert('null prev');
	    PrevMnuElement=null;
      }
      
    } //if (element)
    else
    {
      //we dont have new submnu
      //alert('null prev');
	  PrevMnuElement=null;
    }
	
  }
  else
  {
    //alert ('PrevMnuElement is UNdefined');
    if (element)
    {
      //alert ('rolldown new');
	  //GrowNew(element, steps, h, w, fs);
      RollDownNew(element, steps, h);
    }
  }
  
  if (btn_el)
  {
    //alert('set buttons')
    if (btn_el!=SelectedBtn)
    {
      SetBtnOff2(SelectedBtn);
      SetBtnOn2(btn_el);
    }
    else
    {
      SetBtnOff2(SelectedBtn);
    }
    
  }
  
  
  AnimateMnu();
}

function HighlightLangUkr()
{
  el=$('langUkrImg');
  if (el)
  {
    el.src=langUkrOn.src;
  }
}

function DownlightLangUkr()
{
  el=$('langUkrImg');
  if (el)
  {
    el.src=langUkrOff.src;
  }
}

function HighlightLangRus()
{
  el=$('langRusImg');
  if (el)
  {
    el.src=langRusOn.src;
  }
}

function DownlightLangRus()
{
  el=$('langRusImg');
  if (el)
  {
    el.src=langRusOff.src;
  }
}


