var currentFigure = 1;
var timerFigure;
var speedFigure = 200;


$(document).ready(function(){
    var life_timer;
    var show_timer; 
    var all_time = 200;
    
    start_move_fiqures()
    
    $(".open_auth").click(function(){
        $(".auth").toggle();
        return false;
    });
    
    $(".old_lang").click(function(){
        $(".new_lang").toggle();
        return false;
    });
    
    $("#top").click(function(){        
        $("#top_b").show();
        $("#read_b").hide();
        $("#readable").removeClass('activ');
        $("#top").removeClass('activ').addClass('activ');
        return false;
    });
    
    $("#readable").click(function(){        
        $("#top_b").hide();
        $("#read_b").show();
        $("#top").removeClass('activ');
        $("#readable").removeClass('activ').addClass('activ');
        return false;
    });
    
    $(".first").unbind('mouseenter').bind('mouseenter',show_info);	
	
    function show_info(){
        var $this = $(this);
        $('li').removeClass('activ');
            var popup  = $this.children(".nav_block");
            var left_menu  = $this.children(".nav_block").find(".left");
            var right_menu  = $this.children(".nav_block").find(".right");
            var parent = $this.parent(".menu");
            var link =   $this.children("a");
            
            $('.first > a').removeClass('activ');
            link.addClass('activ'); 
            $('.nav_block').css('marginLeft', '0px').hide();
            
            popup.show();
            
            var parent_offset = parent.offset();
            var popup_offset  = popup.offset();
            
            var marginLeft = parseInt(parent_offset.left) - parseInt(popup_offset.left);
            popup.css('marginLeft', marginLeft + 'px');
            
            if(parseInt(left_menu.css('height')) >= parseInt(right_menu.css('height'))){
                
                var menuHeight = parseInt(left_menu.css('height'));               
                right_menu.css('height', menuHeight);
            }
                
    }
    
});

function start_move_fiqures(){
    var divNum = $("#fiqures > .txt").find('div').size();   
    var curr_val;
    var maxHeight = 0;
    for(i = 1; i <= divNum; i++){
        curr_elem = $("#f_" + i);
        curr_val = parseInt(curr_elem.css('height'));
        if(curr_val >= maxHeight){
            maxHeight = curr_val;
        } 
        if(i > 1){
            curr_elem.css('marginLeft', 140); 
        }               
    }
    
    $("#fiqures > .txt").css('height', maxHeight);
    $("#fiqures").css('height', maxHeight);
    move_fiqures(divNum);
}

function move_fiqures(numElem){
        clearInterval(timerFigure);
		$this = $(this);
        var num = numElem;
		timerFigure = setInterval(function(){		  
          var prev = $("#f_" + currentFigure);
          
          currentFigure++;
          if(currentFigure > num){
		      currentFigure = 1;
		  }
          var next = $("#f_" + currentFigure);
          prev.stop().css('marginLeft', '0px').animate({'marginLeft': '-140px'}, 300);
          next.stop().css('marginLeft', '140px').animate({'marginLeft': '0px'}, 300);		  		  
		},7000)
	}
