var idx = 0, work = [
    //{ title: "Memphis Zoo", client: "Speak Creative", preview: "memphiszoo-preview.png", url: "memphiszoo.html", ios: true, android: true, description: "With tons of great information about each exhibit, a map of the zoo showing your location, details on zoo events and more, the Memphis Zoo app allows visitors to get the most out of their trip to the Memphis Zoo." },
    //{ title: "Everchurch 2.0", client: "Speak Creative", preview: "everchurch-preview.png", url: "everchurch.html", ios: true, android: true, description: "Speak Creative asked Enavox to totally rewrite their Everchurch platform. The result? Everchurch 2.0 is a feature-packed native iOS and Android application framework enabling the rapid deployment of church apps." },
    { title: "Tennessee Child Support Calculator", client: "Helix Business Solutions", preview: "child-support-calc-preview.png", url: false, ios: true, android: false, description: "Tennessee uses a complicated formula to calculate child support payments. Enavox created an iPad app for the Jones Law Firm capable of estimating payments and generating the legal documents while in the courtroom." },
    { title: "US Potato Board", client: "Core Ideas", preview: "uspb-preview.png", ios: true, android: true, description: "The US Potato Board needed a mobile app that better enabled communication with industry insiders and potato growers. The US Potato Board app delivers the latest industry news, local events, and audio updates." },
];

$(document).ready(function() {
    if($.browser.msie && parseInt($.browser.version, 10) < 8) {
        alert("Sorry, but your browser is really old and is not supported on this site. If you must use Internet Explorer, please use version 8.0 or later.");
    }

    $("#banner").hide();
    preloadImages();
    updateBanner(false);
    
    $("#arrow-left").click(function() {
        idx = idx - 1 < 0 ? work.length - 1 : idx - 1;
        updateBanner(true);
    });
    
    $("#arrow-right").click(function() {
        idx = idx + 1 > work.length - 1 ? 0 : idx + 1;
        updateBanner(true);
    });
});
    
function updateBanner(fadeOut) {
    var loadContent = function() {
        var w = work[idx];
        $("#banner-top h2").html(w.title);
        $("#banner-top h3").html(w.client);
        $("#banner-top p").html(w.description);
        $("#banner-preview").css("top", $("#banner").height() - 273);
        $("#banner-preview").html('<img src="images/' + w.preview + '" width="350" height="272"/>');
        console.log("URL = " + w.url);
        if (w.url) {
            $("#banner-top a").attr("href", w.url);
            $("#banner-top a").html("Click here to read more");
            $("#banner-top a").css("display", "block");
            $("#banner-box").css("cursor", "pointer");
            $("#banner-preview").css("cursor", "pointer");
            $("#banner-box").on("click.banner", function() { window.location.href = w.url; });
            $("#banner-preview").on("click.banner", function() { window.location.href = w.url; });
        } else {
            $("#banner-top a").css("display", "none");
            $("#banner-box").css("cursor", "default");
            $("#banner-preview").css("cursor", "default");
            $("#banner-box").off("click.banner");
            $("#banner-preview").off("click.banner");
        }
        $("#platform-ios").css("display", w.ios ? "block" : "none");
        $("#platform-android").css("display", w.android ? "block" : "none");
        $("#platform-plus").css("display", w.ios && w.android ? "block" : "none");
    }
    
    var enableLink = function(w) {
    
    }

    if (fadeOut) {
        $("#banner").fadeOut('fast', function() {
            loadContent();
        });
        $("#banner").fadeIn('fast');
    } else {
        loadContent();
        $("#banner").fadeIn('fast');
    }
};

function preloadImages() {
    $(work).each(function() {
        new Image().src = 'images/' + this.preview;
    });
}
