$(function() {
	$( "#logindialog" ).dialog({autoOpen: false,show: 'fade',hide: 'fade',width: 310});
	$( "#calendardialog" ).dialog({autoOpen: false,show: 'fade',hide: 'fade',width: 310});
	$( "#calculdialog" ).dialog({autoOpen: false,show: 'fade',hide: 'fade',width: 310});
	$( "#linkdialog" ).dialog({autoOpen: false,show: 'fade',hide: 'fade',width: 400});
	$('#loginlink').click(function(){$('#logindialog').dialog('open');return false;});
	$('#calendar').click(function(){$('#calendardialog').dialog('open');return false;});
	$('#calcul').click(function(){$('#calculdialog').dialog('open');return false;});
    $('#showlink').click(function(){$('#linkdialog').dialog('open');return false;});
});


$(document).ready(function(){
	
//sub menu	
		$('#topmenu li.sublnk,#curmenu li.sublnk,#topnews li.sublnk,#clb li.sublnk').hover(
         function() {$(this).addClass("selected");$(this).find('.sub').stop(true, true);$(this).find('.sub').show('slow');},
		  function() {$(this).find('.sub').hide('slow');$(this).removeClass("selected");
    });
//sub menu

//top icon
 $(".m-icon .icon,.d-c .icon,.iconr").hover(function(){ $(this).animate({  backgroundColor: "#6e8a39", }, "slow" );
 },function(){$(this).animate({ backgroundColor: "#84a645",}, "slow" );});	
//top icon End

//top вход open ID
 $(".v-r .icon").hover(function(){ $(this).animate({  backgroundColor: "#0066cc",color: "#fff" }, "slow" );
 },function(){$(this).animate({  backgroundColor: "#069fff", color: "#003366" }, "slow" );});	
//top вход open ID End

//search
	$(".s-r .btn,.v .icons").hover(function(){ $(this).animate({  backgroundColor: "#151e29"}, "slow" );
    },function(){$(this).animate({  backgroundColor: "#202f3f" }, "slow" );});	
	$(".s-r .txt").click(function(){ $(this).animate({  backgroundColor: "#fff", color: "#000" }, "slow" );});
	$('body').click(function() {$(".s-r .txt").animate({ backgroundColor: "#202f3f", color: "#fff" }, "slow" ); });
	$('.s-r .txt').click(function(event){ event.stopPropagation();}); 	  
//search End

//link menu
var url=document.location.href;
 $.each($(".g-m a.h"),function(){
  if(this.href==url){$(this).addClass('act');};
 });
//link menu End

//слайдеры
$('#s1').bxSlider({ displaySlideQty: 5,moveSlideQty: 1,auto: false});
$('#s2').bxSlider({ displaySlideQty: 2,moveSlideQty: 2,auto: false,pager: true});
$('#s3').bxSlider({ displaySlideQty: 1,moveSlideQty: 1,auto: false,pager: true});
//слайдеры End

//s1
show_curr = function(){ $('.hidden').hide();$(this).next().addClass("activ").show();$('.block_close').bind('click', hide_curr);}
hide_curr = function(){$('.hidden').hide();}
$('.hover').bind('click', show_curr);

//s1 End

//bl
var nonno = $(".bl").map(function(indx, element){
  return $(".r-l-b:eq(0)",this).addClass("one");
});
//bl End

//window
$('#loginlink,#calendar,#calcul,#showlink').click(function(){
		$('.darks').fadeIn(200);
});
$('.ui-icon-closethick, .dark').click(function(){
		$('.darks').fadeOut(200);
});	

//window End

//gotop
$(".wrapper").append('<div id="gotop"><a href="#"/></a></div>');
	$("#gotop").hide();
	$(function () {$(window).scroll(function () {	if ($(this).scrollTop() > 100) {	$('#gotop').fadeIn();} else {	$('#gotop').fadeOut();}});
	$('#gotop a').click(function () {$('body,html').animate({scrollTop: 0}, 800);return false;});
	});	
//gotop End	

//вкладки
$('#tab,#tab2,#tab3,#tab4,#tab5,#tab6,#com').ttabs();
$('#tab2 .t-c-l,#tab3 .t-c-l').addClass('mar');
$('#tab2 .mar .b-1-l:eq(1),#tab3 .mar .b-1-l:eq(1),#tab4 .b-1-t:eq(2)').addClass('marg');
$('#tab2 .b-1-r:even,#tab3 .b-1-r:even').addClass('even');

var ml = $(".ml").map(function(indx, element){
  return $(this).parent().parent().hover(function(){$(this).find('.ml').slideDown('slow');
  },function(){$(this).find('.ml').slideUp('slow');});
});

$('.cat').append('<div class="add block"></div>');
	$('.cat .add').each(function() {
		var trigger = $(this), state = false, el = trigger.parent().find('.cat-cont');
		$(this).parent().hover(function(){$(this).find('.add').fadeIn(); },function(){$(this).find('.add').fadeOut();});
		$(this).parent().mousemove(function(){$(this).find('.add').fadeIn();});
		trigger.click(function(){
			state = !state;
			el.slideToggle();
			trigger.parent().toggleClass('inactive');
		});
	});

//вкладки End

$('.mass_comments_action .bbcodes').css('float:none;');
var str = $('.post .p-cat:eq(0)').text();
$('.ct h1').html(str);
$('.post').find('.p-cat').hide();
$('.p1').prepend($('.post:eq(0)')).find(".post").removeClass("post").addClass("b-1-l").find(".d-t").hide();
$('.p2').prepend($('.post:eq(0)')).find(".post").removeClass("post").addClass("b-1-l").find(".d-t").hide();
$('.p3').prepend($('.post:eq(0), .post:eq(1), .post:eq(2)')).find(".post").removeClass("post").addClass("blink").find(".d-t, .p-c").hide();


});

function changeFontSize(element,step)
{
step = parseInt(step,10);
var el = document.getElementById(element);
var curFont = parseInt(el.style.fontSize,10);
el.style.fontSize = (curFont+step) + 'px';
}

//плагин для работы вкладок
jQuery.fn.ttabs = function(options){

    var options = jQuery.extend({

        activeClass: 'selected' // Класс активной вкладки

    },options);

    return this.each(function() {
        $(this).find('.tabcont').hide().filter(':first').show();
        $(this).find('.tabcont:first').show(0);
        $(this).find('.tabmenu .h:first').addClass(options.activeClass);

        $(this).find('.tabmenu .h').click(
            function () {
                $(this).parent().parent().find('.cat-cont .tabcont').hide();
                var numEl= $(this).index();
                $(this).parent().parent().find('.cat-cont .tabcont').eq(numEl).show();
                $(this).parent().find('.h').removeClass(options.activeClass);
                $(this).addClass(options.activeClass);
            }
        );
    });
};
//плагин для работы вкладок END

