var intro_skipped=0;
var menu_is_visible=0;
var menu_is_fading=0;

var speed_intro=2000;
var speed_show_intro=2000;
var speed_show_content=2000;
var speed_show_progress_circle=1000;
var speed_show_menu=2000;
var speed_switch_menu=500;

/*var speed_intro=1;
var speed_show_intro=1;
var speed_show_content=1;
var speed_show_progress_circle=1;
var speed_show_menu=1;
var speed_switch_menu=1;*/

function show_menu_posled(ll) {
    if (menu_is_fading && menu_is_visible) return;
    menu_is_fading=1;
    if (menu_is_visible) {
       //alert("Start fade out on "+lang);
       $(".menu_"+lang+" a").fadeOut(speed_show_menu, function () {
          menu_is_visible=0;
          //alert("Fade out done");
          show_menu(ll);
       });
       return;
    }
    menu_is_visible=1;
    lang=ll;
    //alert("Show "+lang);
    $(".menu_"+lang+" a").fadeIn(speed_show_menu, function () {
       menu_is_fading=0;
    });
}

function show_menu(ll) {
    if (menu_is_fading) return;
    if (lang==ll && menu_is_visible) return;
    menu_is_fading=1;
    if (ll=="ru") {
       if (!menu_is_visible) {
          $(".menu_ru a").fadeIn(speed_switch_menu, function() {
             menu_is_fading=0;
          });
       }
       else {
          //alert("wtf?");
          $(".menu_ru a").show();
          $(".menu_en a").fadeOut(speed_switch_menu, function() {
             menu_is_fading=0;
          });
       }
    }
    else {
       //alert("huh?");
       $(".menu_en a").fadeIn(speed_switch_menu, function () {
          $(".menu_ru a").hide();
          menu_is_fading=0;
       });
    }
    lang=ll;
    menu_is_visible=1;
}

function main_fadeout_done() {
    show_menu(lang);
}

function _main_fadeout_done() {
    $("#content").html('<div id="progress_circle"></div>');
    img=$(document.createElement("img"));
    img.attr("id", "img_progress_circle");
    img.load(function () {
        $("#img_progress_circle").fadeIn(speed_show_progress_circle, function () {
            $.ajax({
	            url: "/"+lang+"/main/",
	            type: "GET",
	            data: "ajax=1",
	            success : function (v) {
	                //alert(v);
	                $("#img_progress_circle").fadeOut(speed_show_progress_circle, function () {
	                    $("#content").hide();
                        $("#content").html(v);
                        $("#content").fadeIn(speed_show_content, function () {
                            if ($.browser.msie) this.style.removeAttribute('filter');
                        });
	                });
	            }
            });
        });
    });
    img.attr('src', "/images/progress-circle.gif");
    img.appendTo("#progress_circle");
}

function skip_intro(selected_language) {

    if (intro_skipped) {
      show_menu(selected_language)
      return;
    }

    intro_skipped=1;

    lang = selected_language;

    css = {
        background:       "#000000",
        opacity:          0
    };
    
    $("#bg_mT").css(css);
    $("#bg_mT").css('display', 'block');
    $(".d_mask").css(css);
    
    $(".d_mask").animate({
        opacity: 0.85
        },
    speed_intro);
    
    $(".intro_fade").animate({
        opacity: 0
        },
    speed_intro, function() {
    });
    
    $("#bg_mT").animate({
        opacity: 0.95
        },
    speed_intro, main_fadeout_done);
    
}

$(document).ready(function() {

    lang="";
    $("#blank_page").animate({
        opacity: 0
        },
    speed_show_intro, function() {
        $(this).remove();
    });
    
});

