//JavaScript
var md={
    anchors:{
        "index":{shelfID:"home_shelf", order:2},
        "about":{shelfID:"about_shelf", order:0},
        "innovations":{shelfID:"inn_shelf", order:1},
        "video":{shelfID:"video_shelf",order: 3},
        "contacts":{shelfID:"conts_shelf", order:4}       
    },
    fadeInSpeed:500,
    fadeOutSpeed:200,
    moveSpeed:1000
    
};
var CurrentAnchor="index";

$(window).load(function(){

    $(".colba_table").width($("#home_shelf").width() - 97);
    
    var urlAnchor=GetUrlAnchor();
    if(urlAnchor!="") CurrentAnchor=urlAnchor;
    
    $(".anchor_link").click(function(){
        if("#"+CurrentAnchor!=$(this).attr("href")){
            CurrentAnchor=$(this).attr("href").replace("#","");
            InitCurrentShelf();
        }
        
    });
    
    $(window).resize(function(){
        $(".colba_table").width($("#home_shelf").width() - 97);
        
        $('#polkas_container').animate({
            scrollTop:GetShelfTop()
        }, md.moveSpeed);
    });
    
    $(".content_overflow").hide();
    if(CurrentAnchor!="index") $("#"+md.anchors[CurrentAnchor].shelfID+" > div.content_overflow").show();
    
    $('#polkas_container').scrollTop(($("#"+md.anchors[CurrentAnchor].shelfID).height()+$(".polkas_bottom_div").height())*md.anchors[CurrentAnchor].order);
        
});

function InitCurrentShelf(){
        
        $(".content_overflow").fadeOut(md.fadeOutSpeed);
        
        $('#polkas_container').animate({
            scrollTop:GetShelfTop()
        }, md.moveSpeed, function(){
            if(CurrentAnchor!="index")
                $("#"+md.anchors[CurrentAnchor].shelfID+" > div.content_overflow").fadeIn(md.fadeInSpeed);
            
        });
        
}

function GetShelfTop(anchor){
    if(anchor==undefined) anchor=CurrentAnchor;
    return ($("#"+md.anchors[anchor].shelfID).height()+$(".polkas_bottom_div").height())*md.anchors[anchor].order;
}

function GetUrlAnchor() {
    if(window.location.href.split("#")[1]==undefined)
        return "";
    else return window.location.href.split("#")[1];
}
