var loaded_employee;
var count=1;

$(document).ready(function(){
    
    
        //$("#logos_holder_divisions").append("</ul>");
        $(".employee_btn").click(function(){
           show_employee($("#employee_"+$(this).attr('id').substring(4)));
            //$("#"+$(this).html()).show();
        })
    
    show_employee($(".employee:first"));
    $("#bottom").each(function(){
       push_pos = this.scrollHeight;
        $("#left_spot").css("height",push_pos);
         $("#bottom").css("height",push_pos);
   });
    
    
});

function show_employee(to_load)
{
    if(loaded_employee != null)
    {
        loaded_employee.hide();
    }
    $("#content_area").scrollTop(0);
    to_load.show();
    addScroll(to_load);
    loaded_employee = to_load;
}

function addScroll(mov)
{
    $(".scroll_vert").remove();
    $('#content_area').each(function(){
        //alert(this.scrollHeight);
            if(this.scrollHeight> 530)
            {
                $('#content_area')
                .bind('mousewheel', function(event, delta) {
                    if(delta < 0)
                    {
                        newpos = ($(".handle").position().top) + 30;
                        if(newpos > 530 - ($(".handle").height()))
                            newpos = 530 - ($(".handle").height());
                    }else
                    {
                        newpos = ($(".handle").position().top) - 30;
                        if(newpos < 0)
                            newpos = 0;
                    }

                    $(".handle").css("top", newpos);
                    var percentage = ((newpos*100)/$(".handle").parent().height())/100;
                    $("#content_area").scrollTop($("#content_area").attr("scrollHeight")*percentage);
                    return false;
                });

                $(this).parent().prepend("<div class='scroll_vert height_350'><div class='handle hide'></div></div>");
                $(".handle").css("height",(520*((520*100)/this.scrollHeight)/100));
            $('.handle').draggable({ axis: 'y', containment: 'parent', cursor: 'pointer', scroll: true, drag: function(event, ui){
                    var percentage = ((ui.position.top*100)/$(this).parent().height())/100;
                    $("#content_area").scrollTop($("#content_area").attr("scrollHeight")*percentage);
                }
             });
        }
            
    });
}