// JavaScript Document

$(document).ready(function(){
    initMenu();
    initSlides();
    initEmployees();
});

function initMenu() {
    menuShowCurrent();
    
    $("#menu ul li").hover(function(){
        $(this).addClass("over");
        
        if($(this).find("ul").length > 0){
            menuHideCurrent();
            $(this).find("ul").show();
            $("#header-wrap #submenu-background").show();
        }
    }
    ,function(){
        $(this).removeClass("over");
        
        if($(this).find("ul").length > 0){
            $(this).find("ul").hide();
            $("#header-wrap #submenu-background").hide();
            menuShowCurrent();
        }
    });
    
}

function menuShowCurrent(){
    if($("#menu ul li.current ul").length > 0){
        $("#menu ul li.current ul").show();
        $("#header-wrap #submenu-background").show();
    }
}

function menuHideCurrent(){
    if($("#menu ul li.current ul").length > 0){
        $("#menu ul li.current ul").hide();
        $("#header-wrap #submenu-background").hide();
    }
}

var slideInterval = 7000;
var slideDocElements = ".quotes li";

function initSlides(){
    $(slideDocElements + ":eq(0)").show();
    
    if($(slideDocElements).length > 1)
        slideTime=setInterval('setupSlides()', slideInterval);
}

function setupSlides(){
    changeSlide(slideDocElements, $(slideDocElements).length);
}

var pos = 0;

function changeSlide(elements, numElements){
    var nextPos;
    
    if(pos < numElements - 1)
        nextPos = pos +1;
    else
        nextPos = 0;
    var currentSlide = elements + ":eq(" + pos + ")";
    var newSlide = elements + ":eq(" + nextPos + ")";
    $(currentSlide).fadeOut("slow");
    $(newSlide).fadeIn("slow");
    pos = nextPos;    
}

function initEmployees(){
    $("#content .employee").hover(function(){
        $(this).addClass("over");
    }
    ,function(){
        $(this).removeClass("over");
    });
    
    $("#employees .employee").click(function(){
        window.location = $(this).find(".read-more").attr("href");
    });

    $("#content .employees-brief li").hover(function(){
        $(this).addClass("over");
    }
    ,function(){
        $(this).removeClass("over");
    });

    $("#content .employees-brief li").click(function(){
        window.location = $(this).find(".read-more").attr("href");
    });
}

