
$(document).ready(function(){
    $("#featureBoxes > .box1:first").show();
    $("#featureBoxes > .box2:first").show();
    $("#featureBoxes > .box3:first").show();
    $("#featureBoxes > .box4:first").show();

    $("#featureBoxes").everyTime("10s", "switchBoxes", switchBoxes);
    $("#featureBoxes > .box").hover(
        function(){
            $(this).addClass("hover");
        },
        function(){
            $(this).removeClass("hover");
        });
});

function switchBoxes(){
    if(!$("#featureBoxes > .box1:visible").is(".hover")){
        switchBox(1);
    }
    if(!$("#featureBoxes > .box2:visible").is(".hover")){
        switchBox(2);
    }
    if(!$("#featureBoxes > .box3:visible").is(".hover")){
        switchBox(3);
    }
    if(!$("#featureBoxes > .box4:visible").is(".hover")){
        switchBox(4);
    }
}

function switchBox(boxNumber){
    var fadeTime = 1000;
    var showing = $("#featureBoxes > .box"+boxNumber+":visible");
    if(showing.next().hasClass("box"+boxNumber)){
        showing.next().fadeIn(fadeTime);
        showing.fadeOut(fadeTime);
    } else if(!$("#featureBoxes > .box"+boxNumber+":first").is(":visible")){
        $("#featureBoxes > .box"+boxNumber+":first").fadeIn(fadeTime);
        showing.fadeOut(fadeTime);
    }
}