
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function resizeBody()
{
  if($.browser.msie)
  {    var qwe = 261;
  }
  else
  {    var qwe = 271;
  }
  $('#cont').css('height', (getClientHeight()-qwe)+'px');
  var h1 = parseInt($('#cont').css('height'));
  $('#contdiv').css('height', 0);
  $('#contdiv').css('height', h1+'px');
  $('#contdiv').css('overflow', 'auto');
  if($.browser.msie)
  {
    $('table.righttab').css('height', 0);
    $('table.lefttab').css('height', 0);
  }
  var h3 = parseInt($('td.contentleft').attr('offsetHeight'));
  var h2 = parseInt($('td.contentright').attr('offsetHeight'));
  if(!$.browser.msie)
  {    $('table.righttab').css('height', 0);
    $('table.lefttab').css('height', 0);
  }
  $('table.righttab').css('height', h2+'px');
  $('table.lefttab').css('height', h3+'px');
  if(h3<h2)h3=h2;
  if(h1<h3)h1=h3;
  $('#contdiv').css('height', h1+'px');
}

function getElemPosition(id)
{
  var elem = $('#'+id).get(0);
  var l = 0;
  var t = 0;
  var w = elem.offsetWidth;
  var h = elem.offsetHeihgt;
  while (elem)
  {
    l += elem.offsetLeft;
    t += elem.offsetTop;
    elem = elem.offsetParent;
  }
  return {"l":l,"t":t,"w":w,"h":h};
}

var slblock =
{
  showElems:'',
  contElems:'',
  speed:'',
  interval:'',
  intervalShow:'',
  action:'',
  startInd:'',
  ind:0,
  activeShow:false,
  timeout_id:'',

  apply:function()
  {
	if(this.startInd >= 0)
	{
	  this.ind = this.startInd-1;
	}
	this.show(0);
	/*$(this.showElems).bind(this.action, function(){
	  var index = $(slblock.showElems).index(this);
	  if(slblock.ind == index)
	  {
        var x=1;
        //window.location.href=slblock.getLink(slblock.ind);
	  }
	  else
	  {
	    slblock.ind = index;
	    slblock.show(index);
	    slblock.setPause();
	  }
	});
	$(this.contElems).bind("click", function(){
	  var index = $(slblock.contElems).index(this);
	  /*if(slblock.ind == index)
	  {
        window.location.href=slblock.getLink(slblock.ind);
	  } */
	//});
  },

  getLink:function(ind)
  {
  	return $(this.contElems).eq(ind).children("table:first-child").children("tbody").children("tr:first-child").children("td.main").children("div.more").children("a").attr("href");
  },

  show:function(ind)
  {
	var index = ind;
	$(slblock.contElems).eq(index).slideDown(slblock.speed);
	$(this.contElems).each(function(i){
	  if(i != index)
	  {
	    $(this).slideUp(slblock.speed);
	  }
	});
  },

  slide:function()
  {
  	this.ind++;
  	if(this.ind >= $(this.showElems).size())
  	{
  	  this.ind = 0;
  	}
  	this.show(this.ind);
  },

  slideShow:function()
  {
  	if(this.activeShow)
  	{
  	  this.slide();
  	  this.timeout_id = setTimeout(function(){slblock.slideShow();},this.interval);
    }
  },

  setPause:function()
  {
  	this.activeShow = false;
  	clearTimeout(this.timeout_id);
  	this.timeout_id = setTimeout(function(){slblock.activeShow=true;slblock.slideShow()},this.intervalShow);
  },

  define:function(sh,cnt,speed,act,interval,intervalShow,ind)
  {
    this.showElems = sh;
    this.contElems = cnt;
    this.speed = speed;
    this.action = act;
    this.interval = parseInt(interval)*1000;
    this.intervalShow = parseInt(intervalShow)*1000;
    this.startInd = parseInt(ind);
    this.apply();
    this.activeShow = true;
    //this.slideShow();
  }
};

var MessWin = {
winid:'messwin',
title:'',
body:'',
buttons:'',
zIndex:100,
shadowHeight:5,
shadowOpacity:0.5,
shadowBackground:'#757575',
blockOpacity:0.2,
blockBackground:'#FFFFFF',

init:function(title,body,buttons)
{
  this.title = title;
  this.body = body;
  this.buttons = buttons;
},

create:function()
{
  if(!$('#'+this.winid).length)
  {
    $(document.body).append("<div id='"+this.winid+"'></div>");
  }
  $('#'+this.winid).empty();
  $('#'+this.winid).html("<div /><div /><div />");
  $('#'+this.winid+' div:nth-child(1)').attr('id',this.winid+'_title');
  $('#'+this.winid+' div:nth-child(2)').attr('id',this.winid+'_body');
  $('#'+this.winid+' div:nth-child(3)').attr('id',this.winid+'_buttons');
  $('#'+this.winid+'_title').html(this.title);
  $('#'+this.winid+'_body').html(this.body);
  $('#'+this.winid+'_buttons').html(this.buttons);
  if(!$('#'+this.winid+'_shadow').length)
  {
  	$('#'+this.winid).after("<div />");
  	$('#'+this.winid).next().attr('id',this.winid+'_shadow');
  }
  if(!$('#'+this.winid+'_block').length)
  {
  	$('#'+this.winid).after("<div />");
  	$('#'+this.winid).next().attr('id',this.winid+'_block');
  }
  this.show();
},

show:function()
{
 $('#'+this.winid).css('position','absolute');
 $('#'+this.winid).css('z-index',(this.zIndex+2));
 $('#'+this.winid).show();
 $('#'+this.winid).css('left',(getClientWidth()-parseInt($('#'+this.winid).attr('offsetWidth')))/2);
 $('#'+this.winid).css('top',((getClientHeight()-parseInt($('#'+this.winid).attr('offsetHeight')))/2+document.body.scrollTop));
 $('#'+this.winid+'_shadow').css('position','absolute');
 $('#'+this.winid+'_shadow').css('z-index',(this.zIndex+1));
 $('#'+this.winid+'_shadow').css('width',$('#'+this.winid).attr('offsetWidth'));
 $('#'+this.winid+'_shadow').css('height',$('#'+this.winid).attr('offsetHeight'));
 $('#'+this.winid+'_shadow').css('top',(parseInt($('#'+this.winid).css('top'))+this.shadowHeight));
 $('#'+this.winid+'_shadow').css('left',(parseInt($('#'+this.winid).css('left'))+this.shadowHeight));
 $('#'+this.winid+'_shadow').css('background',this.shadowBackground);
 $('#'+this.winid+'_shadow').css('filter','alpha(opacity='+this.shadowOpacity*100+')');
 $('#'+this.winid+'_shadow').css('-moz-opacity',this.shadowOpacity);
 $('#'+this.winid+'_shadow').css('opacity',this.shadowOpacity);
 $('#'+this.winid+'_shadow').show();

 $('#'+this.winid+'_block').css('position','absolute');
 $('#'+this.winid+'_block').css('z-index',this.zIndex);
 $('#'+this.winid+'_block').css('top',0);
 $('#'+this.winid+'_block').css('left',0);
 $('#'+this.winid+'_block').css('width',getClientWidth());
 $('#'+this.winid+'_block').css('height',getClientHeight());
 $('#'+this.winid+'_block').css('background',this.blockBackground);
 $('#'+this.winid+'_block').css('filter','alpha(opacity='+this.blockOpacity*100+')');
 $('#'+this.winid+'_block').css('-moz-opacity',this.blockOpacity);
 $('#'+this.winid+'_block').css('opacity',this.blockOpacity);
 $('#'+this.winid+'_block').show();
},

showBox:function(title,body,buttons)
{
  this.init(title,body,buttons)
  this.create();
},

hide:function()
{
  $('#'+this.winid).hide();
  $('#'+this.winid+'_shadow').hide();
  $('#'+this.winid+'_block').hide();
}
};


$(document).ready(function () {
$(window).bind("resize", function(){resizeBody();});
$("a.gallery").fancybox();
});

function trOver(id) {
	document.getElementById(id).style.backgroundImage='url(images/button_bg.gif)';

}
