$(document).ready(function(){
   $("#shar_plus").hover(
        function(){
            $(this).animate({opacity: 0.0}, 200);
            $("#shar_help").animate({opacity: 1.0}, 500);
            $("#shar_oblako_top").animate({left: "-=15px", top: "-=10px"}, 200);
            $("#shar_oblako_center").animate({left: "-=30px"}, 200);
            $("#shar_oblako_niz").animate({left: "-=15px", top: "+=10px"}, 200);
            $("#shar_oblako_dop_niz").animate({right: "-=15px", top: "+=10px"}, 200);
            $("#shar_oblako_dop_verh").animate({right: "-=15px", top: "-=10px"}, 200);
        },
        function(){
            $(this).animate({opacity: 1.0}, 200);
            $("#shar_help").animate({opacity: 0.0}, 500);
            $("#shar_oblako_top").animate({left: "+=15px", top: "+=10px"}, 200);
            $("#shar_oblako_center").animate({left: "+=30px"}, 200);
            $("#shar_oblako_niz").animate({left: "+=15px", top: "-=10px"}, 200);
            $("#shar_oblako_dop_niz").animate({right: "+=15px", top: "-=10px"}, 200);
            $("#shar_oblako_dop_verh").animate({right: "+=15px", top: "+=10px"}, 200);
        }
    );
   $("#dirigabl_plus").hover(
        function(){
            $(this).animate({opacity: 0.0}, 200);
            $("#dirigabl_help").animate({opacity: 1.0}, 500);
            $("#dirigabl_oblako_top").animate({right: "-=15px", top: "-=10px"}, 200);
            $("#dirigabl_oblako_niz").animate({right: "-=15px", top: "+=10px"}, 200);
            $("#dirigabl_oblako_dop_verh").animate({left: "-=15px", top: "-=10px"}, 200);
            $("#dirigabl_oblako_dop_center").animate({left: "-=15px"}, 200);
            $("#dirigabl_oblako_dop_niz").animate({left: "-=15px", top: "+=10px"}, 200);
        },
        function(){
            $(this).animate({opacity: 1.0}, 200);
            $("#dirigabl_help").animate({opacity: 0.0}, 500);
            $("#dirigabl_oblako_top").animate({right: "+=15px", top: "+=10px"}, 200);
            $("#dirigabl_oblako_niz").animate({right: "+=15px", top: "-=10px"}, 200);
            $("#dirigabl_oblako_dop_verh").animate({left: "+=15px", top: "+=10px"}, 200);
            $("#dirigabl_oblako_dop_center").animate({left: "+=15px"}, 200);
            $("#dirigabl_oblako_dop_niz").animate({left: "+=15px", top: "-=10px"}, 200);
        }
    );
   $("#statuia_plus").hover(
        function(){
            $(this).animate({opacity: 0.0}, 200);
            $("#statuia_help").animate({opacity: 1.0}, 500);
        },
        function(){
            $(this).animate({opacity: 1.0}, 200);
            $("#statuia_help").animate({opacity: 0.0}, 500);
        }
    );
   $("#ship_plus").hover(
        function(){
            $(this).animate({opacity: 0.0}, 200);
            $("#ship_help").animate({opacity: 1.0}, 500);
        },
        function(){
            $(this).animate({opacity: 1.0}, 200);
            $("#ship_help").animate({opacity: 0.0}, 500);
        }
    );
    $("#avtoriz_form_email").click(function(){
        $(this).val("");
    });
    $("#avtoriz_form_email").blur(function(){
        if($(this).val() == ""){
            $(this).val("email");
        }
    });
    $("#avtoriz_form_password").click(function(){
        $(this).val("");
    });
    $("#avtoriz_form_password").blur(function(){
        if($(this).val() == ""){
            $(this).val("password");
        }
    });

    var divs = $(".gallery_divs_im");
    divs.each(function(indx){
        var vs = $(".gallery_div").filter( "#" + $(this).attr("id") );
        var im = $(this).detach();
        im.appendTo(vs);
    });
    image_one = [];
    text_one = [];
    author_one = [];
    n = [];
    $(".gallery_div").each(function(indx){
        //var idn = $(".gallery_div").index($(this));
        n.push(0);
        vs_all = $(this).children("div");
        vs_one = vs_all.eq(0);
        all_length = vs_all.find("img");
        vs_one_t = vs_one.find(".gallery_podpis");
        text_one.push(vs_one_t.text());
        vs_one_i = vs_one.find("img");
        image_one.push(vs_one_i.attr("src"));
        vs_one_a = vs_one.find(".gallery_author");
        author_one.push(vs_one_a.text());
        vs_one_i.before("<div class='page_gallery_all_interfeis' id='"+$(this).attr("id")+"'><div class='page_gallery_lbat' id='"+$(this).attr("id")+"'></div><div class='page_gallery_center'><div class='page_gallery_center_n'><b><span class='nomer_foto' id='"+$(this).attr("id")+"'>1</span></b>/<span>"+all_length.length+"</span></div></div><div class='page_gallery_rbat' id='"+$(this).attr("id")+"'></div></div>");
        vs_not_all = vs_all.slice(1);
        vs_not_all.css("display", "none");
    });
    $(".page_gallery_rbat").click(function(){
        var s = $(this).attr("id");
        var i = $(".gallery_im").filter("#"+s);
        var t = $(".gallery_podpis").filter("#"+s);
        var a = $(".gallery_author").filter("#"+s);
        if( n[s-1] < i.length-1 ){
            n[s-1]++;
            $(".nomer_foto").filter("#"+s).text(n[s-1]+1);
            i.eq(0).attr( "src", i.eq(n[s-1]).attr("src") );
            t.eq(0).text( t.eq(n[s-1]).text() );
            a.eq(0).text( a.eq(n[s-1]).text() );
        }
    });
    $(".page_gallery_lbat").click(function(){
        var s = $(this).attr("id");
        var i = $(".gallery_im").filter("#"+s);
        var t = $(".gallery_podpis").filter("#"+s);        
        var a = $(".gallery_author").filter("#"+s);
        if( n[s-1] > 1 ){
            n[s-1]--;
            $(".nomer_foto").filter("#"+s).text(n[s-1]+1);
            i.eq(0).attr( "src", i.eq(n[s-1]).attr("src") ) ;
            t.eq(0).text( t.eq(n[s-1]).text() );
            a.eq(0).text( a.eq(n[s-1]).text() );
        }else{
            n[s-1] = 0;
            $(".nomer_foto").filter("#"+s).text(1);
            i.eq(0).attr( "src", image_one[s-1] ) ;
            t.eq(0).text( text_one[s-1] );
            a.eq(0).text( author_one[s-1] );
        }
    });

    $("#page_log_in").click(function(){
        $("#avtoriz_obl").css("display", "block");
        $("#avtoriz_obl").animate({opacity: 1.0}, 500);
    });
    $("#avtoriz_formpage_reset").click(function(){
        $("#avtoriz_obl").css("display", "none");
        $("#avtoriz_formpage_password").val("");
        $("#avtoriz_formpage_email").val("");
    });

});
