$(document).ready(function() {
    $("a.lightbox").lightBox({fixedNavigation: false});
    
    //Clients
    $(".klients .client_logo").mouseenter(function(){
        var position = $(this).position();
        var x = position.left;
        var y = position.top;
        var width = $(this).outerWidth();
        var height = $(this).outerHeight();
        var container = $(this).parent().find(".zoom_container");
        var container_img = container.find(".zoom_img");
        var tmp_img = $('<img>').load(function(){
            img_height = parseInt($(this).attr('height'));
            container.css({'left': x - (77 - width / 2) , 'top': y - 16 - (img_height - height) / 2}).fadeIn();
        }).attr('src', container_img.attr('src'));
    });
    $(".klients .zoom_container").mouseleave(function(){$(this).fadeOut();});
});

function select_main_menu(id){
   var obj = document.getElementById(id);
   if(obj){ obj.className = 'active_main_menu'; }
}

function fixedblock(text){
    $('#fixed_block_cont').html(text);
    $('#fixed_block').fadeIn('slow').fixedBox();
}

function check_consult_form(){
    var reg_e = /^[0-9\.a-z_\-]+@[0-9a-z_\-^\.]+\.[a-z]{2,3}$/i;
    var email = document.getElementById('id_cons_email');
    var mes = document.getElementById('id_cons_text');
    var cap = document.getElementById('id_cons_captcha').getElementsByTagName('input')[0];
    if(email.value == '' || mes.value == '' || cap.value == ''){
        fixedblock('Заполните все обязательные поля');
        return false;
    }
    else{
        if(email.value && !reg_e.test(email.value)){
            fixedblock('Введите E-mail вида mailbox@mailbox.ru');
            return false;
        }
        else return true;
    }
}

function unactive_links(id){
    links = document.getElementById(id).getElementsByTagName('li');
    for(var i=0; i<links.length; i++){
        if(!links[i]){ continue; }
        else{ links[i].className = false; }
    }
}

function show_pos(id, obj){
    document.getElementById('yandex_pos').style.display = 'none';
    document.getElementById('rambler_pos').style.display = 'none';
    document.getElementById('google_pos').style.display = 'none';
    unactive_links('links_stat_pos');
    obj.parentNode.className = 'active';
    $('#'+id).fadeIn();
}

function show_glob(id, obj){
    document.getElementById('yandex_glob').style.display = 'none';
    document.getElementById('rambler_glob').style.display = 'none';
    document.getElementById('google_glob').style.display = 'none';
    unactive_links('links_stat_glob');
    obj.parentNode.className = 'active';
    $('#'+id).fadeIn();
}
function light_td_menu(obj){
    obj.style.backgroundImage = "url('/media/images/but_bg_orange.gif')";
    obj.style.backgroundPosition = "left top";
    obj.style.backgroundRepeat = "repeat-x";
    if(obj.className != 'active_td'){
        block = obj.getElementsByTagName('div')[0];
        if(block.className != 'first_div'){ block.style.borderLeft = "1px solid #ffffff"; }
        if(block.className != 'last_div'){ block.style.borderRight = "1px solid #ffffff"; }
        block.style.height = '50px';
    }
    link = obj.getElementsByTagName('a')[0];
    link.style.paddingBottom = '18px';
    link.style.backgroundImage = "url('/media/images/but_arrow_orange.gif')";
    link.style.backgroundPosition = "bottom center";
    link.style.backgroundRepeat = "no-repeat";
    link.style.color = "#ffffff";
}
function unlight_td_menu(obj){
    block = obj.getElementsByTagName('div')[0];
    if (obj.className == 'active_td'){ 
        obj.style.backgroundImage = "url('/media/images/but_bg_blue.gif')";
        obj.style.backgroundPosition = "left top";
        obj.style.backgroundRepeat = "repeat-x";
        link = obj.getElementsByTagName('a')[0].style.backgroundImage = "url('/media/images/but_arrow_blue.gif')";
    }
    else{ 
        obj.style.backgroundImage = "url('/media/images/but_bg_gray.gif')";   
        if(block.className == 'first_div'){
            block.style.borderLeft = 'none';
            block.style.borderRight = '1px solid #b4b3b3';
        }
        else{ 
            if (block.className == 'last_div'){
                block.style.borderLeft = '1px solid #f2f2f2';
                block.style.borderRight = 'none';
            }
            else{ 
                block.style.borderLeft = '1px solid #f2f2f2';
                block.style.borderRight = '1px solid #b4b3b3';
            }
        }
        link = obj.getElementsByTagName('a')[0];
        link.style.paddingBottom = '0px';
        link.style.backgroundImage = "none";
        link.style.color = "#000000";
    }
    block.style.height = '32px';
}

function show_stat_top5(id){
    $('.block_stat_top5').load('/stat/top5/'+id+'/', {},
        function (){ $('.block_stat_top5').fadeIn('slow').fixedBox(); }
	);
}
