var rotator_i = 1;
var rotator_o = 1;
var rotator_c = 0;
var rotator_e = true;
var expert_change = true;

function ShowFullContacts(){

    scrollWidth = $(window).width();
    scrollHeight = $(window).height();
	
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
  
    $('#overlay').css({
        'width':maskWidth,
        'height':maskHeight
    });
	
    //document.getElementById('overlay').className='overlay_on';
	
    //document.getElementById("overlay").style.opacity = 0.6;
    //document.getElementById("overlay").style.filter = "alpha(opacity=60)";
  
    //$('#overlay').fadeIn(1000); 
    //$('#overlay').fadeTo("slow",0.8); 
	
    //document.getElementById("overlay").style.width = scrollWidth;
    //document.getElementById("overlay").style.height = scrollHeight;
	
    var posleft = Math.round(maskWidth / 2) - 900;
    var postop = maskHeight - 600;

    //document.getElementById('modaldiv').style.left = posleft;
    //document.getElementById('modaldiv').style.top = document.body.scrollTop + 100;

    $("#ajaxloginerror").html("");
	
    $("#modaldiv").show();
}

function CloseModalbox(){
    $("#modaldiv").hide();
	
}

function StartRotator(){
    $("div#rotator_e" + rotator_i).show();
    $("div#rotator_b" + rotator_i).addClass('active');
    
    rotator_c = $("div.rotator_container div.rotator_element").length;
    
    setTimeout('NextRotate();',10000);
}

function NextRotate(){
    if(rotator_e){
        rotator_e = false;
        rotator_o = rotator_i;
        rotator_i++;
    
        if(rotator_i>rotator_c)
            rotator_i = 1;
    
        $("div#rotator_e" + rotator_o).fadeOut();
        $("div#rotator_e" + rotator_i).fadeIn(function(){
            rotator_e = true;
        });
        
        /*$("div#rotator_layer").animate({
            marginLeft: ((-711)*(rotator_i-1))
        }, 800 );*/
    
        $("div#rotator_b" + rotator_o).removeClass('active');
        $("div#rotator_b" + rotator_i).addClass('active');
    }
    
    setTimeout('NextRotate();',10000);
    
}

function Vote(id){
    
    var ask = $("#question_container" + id + " input[name=ask]:checked").val();
    
    $.post('/questions/vote/',{
        id:id,
        ask:ask
    },function(data){
        $("#question_container" + id).html(data);
    });
}

function GetCalendar(date){
    $.get('/events/getcalendar/date/' + date + '/', function(data){
        $("#calendar").html(data);
    });
}

function GetCalendarNews(date){
    $.get('/news/getcalendar/date/' + date + '/', function(data){
        $("#calendarnews").html(data);
    });
}

function AddComment(id){
    var name = $.trim($("#comment_name").val());
    var text = $.trim($("#comment_text").val());
    
    if(name == ''){
        $("#comment_error").html('Заполните все поля');
        return;
    }
    
    if(text == ''){
        $("#comment_error").html('Заполните все поля');
        return;
    }
    
    $.post('/news/addcomment/',{
        id:id,
        name:name,
        text:text
    },function(responseText){
        if(responseText == '404'){
            $("#comment_error").html('Новость не найдена');
        }
        else{
            if(responseText == 'null'){
                $("#comment_error").html('Заполните все поля');
            }
            else{
                $("#comments_items").prepend(responseText);
                $("#comment_error").html('');
                $("#comment_name").val('');
                $("#comment_text").val('');
            }
        }
    });
}

function AddCommentChiefeditor(id){
    var name = $.trim($("#comment_name").val());
    var text = $.trim($("#comment_text").val());
    
    if(name == ''){
        $("#comment_error").html('Заполните все поля');
        return;
    }
    
    if(text == ''){
        $("#comment_error").html('Заполните все поля');
        return;
    }
    
    $.post('/chiefeditor/addcomment/',{
        id:id,
        name:name,
        text:text
    },function(responseText){
        if(responseText == '404'){
            $("#comment_error").html('Новость не найдена');
        }
        else{
            if(responseText == 'null'){
                $("#comment_error").html('Заполните все поля');
            }
            else{
                $("#comments_items").prepend(responseText);
                $("#comment_error").html('');
                $("#comment_name").val('');
                $("#comment_text").val('');
            }
        }
    });
}

function SetActiveExpert(id){

    if($(".expert_info #expert" + id).hasClass('expert_active')==false){
        expert_change = false;
        $(".expert_info .experts_item").removeClass('expert_active').hide();
        $(".expert_info #expert" + id).addClass('expert_active').stop().fadeIn(function(){
            expert_change = true;
        });
    }
}

$(function(){
    $("#buttons").hover(function(){
        $("#buttons_text").fadeTo("fast", 0.9);
    },function(){
        $("#buttons_text").fadeOut('fast');
    });
    
    if(location.pathname != '/'){
        $("ul.menu a.menu_link").each(function(){
            if(this.pathname != '/'){
                var link_path = this.pathname;
                if ($.browser.msie){
                    link_path = '/' + link_path;
                }
                var l = link_path.length;
                var loc = location.pathname.substring(0, l);
                if(loc == link_path){
                    $(this).parent().addClass('active');
                }
            }
        });
    }
    
});


