var logopened=false;
$(document).ready(function(){
    $('#logbtn').click(function(){
        if(logopened)
        {
            $('#logform').hide('fast');
            $('#logbtn').removeClass('selected');
        }    
        else
        {
            $('#logform').show('fast');
            $('#logbtn').addClass('selected');
        }
        logopened=!logopened;
        return false;
    });
}).click(function(e){
    if(!logopened)
        return;
    e=e||window.event;
    var target=e.target||e.srcElement;
    while(target)
    {
        if(target==$('#logform').get(0))
            return;
        target=target.parentNode;
    }
    $('#logform').hide('fast');
    $('#logbtn').removeClass('selected');
    logopened=false;    
});

$(document).ready(function(){
		$('#topmenu2 li').hover(
		function() {
			$(this).addClass("selected");
			$(this).find('ul').stop(true, true);
			$(this).find('ul').show('fast');
		},
		function() {
			$(this).find('ul').hide('fast');
			$(this).removeClass("selected");
		}
	);
});

$(document).ready(function(){
	var tabContainers = $('#news-arch .tabcont');
		tabContainers.hide().filter(':first').show();
								
		$('#news-arch .tabmenu a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('#news-arch .tabmenu a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		}).filter(':first').click();
});




$(document).ready(function(){ 

	tt=$('.speedbar').text().split(' » ');
	$('.speedbar').html( tt[tt.length-1] );
	$('#pager').css('display','none');
	$('#pager_footer').html( $('#pager').html() );
	
	$.preloadImages("/templates/Missia/images/rss3_on.png", "/templates/Missia/images/rss2_on.png", 
	                             "/templates/Missia/images/butt_right_on.png", "templates/Missia/images/butt_left_on.png");

				   var timetogo = '1';
				   var timer = window.setInterval(function()
				   {
					   if (timetogo <= 0)
					   { 
		//alert($('.maincont').height())  ;

							window.clearInterval(timer);
					   }
					   timetogo--;
				   }, 500);
	

});
$(window).load(function () {
	ShowOrHide2('addcombtn','addcombtn_down', 'addcform');
    setHeightColumns();
});

jQuery.preloadImages = function()
{
 for(var i = 0; i<arguments.length; i++)
 {
  jQuery("<img>").attr("src", arguments[i]);
 }
};

function setHeightColumns() {
	    equalHeight($("#id_data_lcol"),$("#id_data_rcol"));
	// 	уравниваем высоты datacont и его колонок внутри 
	var delta=105;
	if ( $('#datacont ').height()<$('#id_data_lcol').height()+delta ) {
		$('#datacont ').height($('#id_data_lcol').height()+delta);
	} else {
		//$('#id_data_lcol').height($('#datacont ').height());
	}
     	
    // 	уравниваем высоты datacont и правой колонки шаблона
	if ( $('#datacont').height()<$('#rcol').height() ) {
		$('#datacont').height($('#rcol').height());
	} else {
		$('#rcol_bott').css('margin-top',$('#datacont').height()-$('#rcol').height()+'px');
	}
}

function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}

function ShowOrHide2(src,src_class, d1) {
	 //alert('ok');
		var item = $("#" + d1);
		if (item.is(":hidden")) { 
			$("."+src).addClass(src_class);
			item.show('blind',function(){
														var delta=$('#addcform ').height();
				                                        var h1= $('#datacont ').height();
				                                        var h2= $('#rcol ').height();
														$('#datacont ').height( h1+delta );
				                                        $('#rcol_bott').css('margin-top',h1-h2+'px');
				                                        setHeightColumns();
				                                       },1000);
		} else {
			item.hide('blind',function(){
													   var delta=$('#addcform ').height();
													   var h1= $('#datacont ').height();
													   var h2= $('#rcol ').height();
													   $('#datacont ').height( h1-delta );
													   $('#rcol_bott').css('margin-top',h1-h2+'px');
													   setHeightColumns();
													  },1000);
			$("."+src).removeClass(src_class);
		}
}


