$(function () {
	
    //simple_tooltip(".tooltip_link a","tooltip");
    
    $('.hovered').hover(function () {
        $(this).addClass('hover');
    },
    function () {
        $(this).removeClass('hover'); 
    });
    
    if(!($(".main_menu li").hasClass("open"))) {
    	$(".main_menu li:first").addClass("open");
    }
    
    $('.main_menu li h2').click(function() {
    	
    	var checkElement = $(this).next();
    	
    	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    		return false;
    	}
    	
    	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
    		$('#slide_menu ul:visible').slideUp(0,function() {
	            $($(this).prev()).parent("li").removeClass('open');
	            //var t = $(".colleft").height() + ',' + $("#right_block").height();
	    		//alert(t);
	            
	        });
    		$($(this)).parent("li").addClass('open');
    		checkElement.slideDown('slow',function() {
    				FloatHeight();
    		});
    		    		
    		return false;
    	}
    	
    });
    
    $('.lightBox').lightBox();
    
    //всплывающие подсказки на заголовках
	/*function simple_tooltip(target_items, name){
        $(target_items).each(function(i){
            $("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
            var my_tooltip = $("#"+name+i);

            $(this).removeAttr("title").mouseover(function(){
                my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
            }).mousemove(function(kmouse){
                my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
            }).mouseout(function(){
                my_tooltip.fadeOut(400);
            });
        });
    }*/
    
    FloatHeight();  
    
    //выравнивание колонок
    function FloatHeight(){
    	var rightCol = $("#right_block").height();
        var ifMain = $(".search_fonts").height() + $("#breadcrumbs").height() + 10;
        var bgHeight = $(".floatHeight .section_content").height();
        
        if($("div").is("#gallery")) {
        	ifMain = ifMain + $("#gallery").height();
        }
        var leftCol = $(".colleft").height() - ifMain;
        if(rightCol > leftCol && rightCol != 0) {
	        if(bgHeight < rightCol) {
	            $(".floatHeight .grey_bg").css({height: rightCol });
	            return false;
	        }
        } else {
	        if(bgHeight < leftCol) {
	            $(".floatHeight .grey_bg").css({height: leftCol });
	            return false;
	        }
        }
        $(".floatHeight .grey_bg").css({height: 'auto' });
    }
    
    //карусель
    
    //$('.images').html($('.data:first').html());
    
    /*$('#mycarousel').jcarousel({
        animation: 600,
        wrap: 'both',
        itemFirstInCallback:  mycarousel_itemFirstInCallback
    });*/
    
    $('.sl').each(function () {

		if ($('.slider ul li', this).length >= 5) {
			
			$('.next, .prev', this).css('display','block');
			
			$('.slider', this).css('left', '-5000');
			
			$('.slider', this).jCarouselLite({
	    		btnNext: $('.next', this),
	    		btnPrev: $('.prev', this),
	    		circular: true,
	    		visible: 4
			});
			
			$('.slider a', this).lightBox();
		}
		
		else {
			
			$('.slider_one a', this).lightBox();
			
			$('.slider a', this).lightBox();
		}
	});
	
	$('ul.only_video li img').click(function() {
		$('ul.only_video li img.active').removeClass('active');
		$(this).addClass('active');
	});
	
	$('.jcarousel-next').click(function() {
		$('.announce .active').fadeOut('normal',function() {
			$('.announce .active').removeClass('active');
        });
	});
	
    $('.jcarousel-prev').click(function() {
    	$('.announce .active').fadeOut('normal',function() {
			$('.announce .active').removeClass('active');
        });
    });
    
	function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
		//$('.announce .active').removeClass('active');
        //$($('.announce .heading').get(idx-1)).addClass('active');
		//$('.announce .active').delay(500).fadeIn(1000);		
		
		$($('.announce .heading').get(idx-1)).addClass('active');
		$('.announce .active').fadeIn('normal');
		
		$('.day p.active').removeClass('active');
		$($('.day p').get(idx-1)).addClass('active');
		
		/*$('.jcarousel-item img.active').removeClass('active');
		$($('.jcarousel-item img').get(idx-1)).addClass('active');
		$('.jcarousel-item img.active').css('display','block');*/
	}
	
	$(".banners").scrollable({
		items:'.items',
		horizontal:true,
		keyboard: false,
		size: 4,
		easing: "linear"
		});
	
	var $scroll_api = $(".banners").data("scrollable");
	$("a.nxt").mouseover(function(){
		$scroll_api.move(1, 1000);	
	});
	$("a.prv").mouseover(function(){
		$scroll_api.move(-1, 1000);		
	});
	
	var docFont = $.cookie("docFont");
    //alert("Cookie docFont: " + docFont);
    $('body').css('font-size', docFont);
	/*if (docFont) {
    	var oldFontSize = parseInt(docFont);
    	$('body').css('font-size', oldFontSize);
	}*/
    
    // сброс шрифта
    var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
        $('body').css('font-size', originalFontSize);
        $('.header_strip .lang').css('left','90px');
        $.cookie("docFont", originalFontSize, {path: "/"});
        FloatHeight();
    });
    
    // увеличение шрифта
    $(".increaseFont").click(function(){
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*1.2;
        $('body').css('font-size', newFontSize);
        $('.header_strip .lang').css('left','0');
        $(".floatHeight .grey_bg").css({height: 'auto' });
      	$.cookie("docFont", newFontSize, {path: "/"});
        FloatHeight();  
        return false;
    });
    
    // уменьшение шрифта
    $(".decreaseFont").click(function(){
        var currentFontSize = $('body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*0.8;
        $('body').css('font-size', newFontSize);
        $(".floatHeight .grey_bg").css({height: 'auto' });
        $('.header_strip .lang').css('left','90px');
        $.cookie("docFont", newFontSize, {path: "/"});
        FloatHeight();
        return false;
    });
    
    //бегущая строка
    //$("ul#ticker").liScroll();
    //$('.vertical_scroller').SetScroller({velocity: 50, direction: 'vertical'});
    //if ($('.vertical_scroller ul li').length >= 2) {
	    $(".scrollingtext").jCarouselLite({  
	    	vertical: true,  
	        visible: 1,  
	    	auto:5000,  
	    	speed:1000  
	   	});
    //}
	
});
