var fadeTime = 750;

$(document).ready(function() {
    createLinks();
    setClickListners();
    showInitalSpecials();
});

function createLinks() {
    // Creates the Number Links for the Inn
    var num = 1;
    var size = $("#specialsInn div.contentItem").size();
    while (num <= size && size > 1) {
        $("#specialsInn .specialsRotateLinks").append("<a>" + num + "</a>");
        num++;
    }

    // Creates the Number Links for the Lodge
    var num = 1;
    var size = $("#specialsLodge div.contentItem").size();
    while (num <= size && size > 1) {
        $("#specialsLodge .specialsRotateLinks").append("<a>" + num + "</a>");
        num++;
    }
}

function setClickListners() {
    // Sets the click functionality for the Inn
    $("#specialsInn div.specialsRotateLinks a").click(function() {
        var nextSlideNum = $(this).html();

        $("#specialsInn div.contentItem:visible").fadeOut(fadeTime);
        setTimeout(function() {
        $("#specialsInn div.specialsRotateLinks a:not(:nth-child(" + nextSlideNum + "))").css("color", "#7CBAD0"); //.css("color", "#8FC3CE");
        $("#specialsInn div.specialsRotateLinks a:nth-child(" + nextSlideNum + ")").css("color", "#AAAAAA"); //.css("color", "#CBC8C1");
            $("#specialsInn div.contentItem:nth-child(" + nextSlideNum + ")").fadeIn(fadeTime);
        }, fadeTime + 100);
    });

    // Sets the click functionality for the Lodge
    $("#specialsLodge div.specialsRotateLinks a").click(function() {
        var nextSlideNum = $(this).html();

        $("#specialsLodge div.contentItem:visible").fadeOut(fadeTime);
        setTimeout(function() {
        $("#specialsLodge div.specialsRotateLinks a:not(:nth-child(" + nextSlideNum + "))").css("color", "#7CBAD0"); //.css("color", "#8FC3CE");
            $("#specialsLodge div.specialsRotateLinks a:nth-child(" + nextSlideNum + ")").css("color", "#AAAAAA"); //.css("color", "#CBC8C1");
            $("#specialsLodge div.contentItem:nth-child(" + nextSlideNum + ")").fadeIn(fadeTime);
        }, fadeTime + 100);
    });
}

function showInitalSpecials() {
    // Shows the first element
    $("#specialsInn div.contentItem:first").show();
    $("#specialsInn div.specialsRotateLinks a:first").css("color", "#AAAAAA");
    $("#specialsLodge div.contentItem:first").show();
    $("#specialsLodge div.specialsRotateLinks a:first").css("color", "#AAAAAA");
}
