﻿$(document).ready(function() {

    var timer;
    var delay = 1000;
    var faster_delay = 100;
    var maxAds = 10;

    function showAd(adNo) {

        $(".slide").css("visibility", "hidden");
        $(".caption").css("visibility", "hidden");

        $("#image" + adNo).css("visibility", "visible");
        $("#image" + adNo).css("opacity", "0");
        $("#image" + adNo).animate({ "opacity": 1 }, delay, "linear", null);

        $("#caption" + adNo).css("visibility", "visible");

        $("ul.buttons li").removeClass("active");

        $("#button" + adNo).addClass("active");

        clearTimeout(timer);

        if (adNo == maxAds) {
            timer = setTimeout(function() { showAd(1) }, 3000);
        }
        else {
            timer = setTimeout(function() { showAd(adNo + 1) }, 3000);
        }
    }

    function OnLoad(event) {
        clearTimeout(timer);
        timer = setTimeout(function() { showAd(1) }, 3000);
    }

    $('#button1').click(function() { showAd(1); });
    $('#button2').click(function() { showAd(2); });
    $('#button3').click(function() { showAd(3); });
    $('#button4').click(function() { showAd(4); });
    $('#button5').click(function() { showAd(5); });
    $('#button6').click(function() { showAd(6); });
    $('#button7').click(function() { showAd(7); });
    $('#button8').click(function() { showAd(8); });
    $('#button9').click(function() { showAd(9); });
    $('#button10').click(function() { showAd(10); });

    OnLoad();

});