﻿adCount = 0

if (!Array.prototype.reduce) {
    Array.prototype.reduce = function (fun /*, initial*/) {
        var len = this.length;
        if (typeof fun != "function")
            throw new TypeError();

        // no value to return if no initial value and an empty array
        if (len == 0 && arguments.length == 1)
            throw new TypeError();

        var i = 0;
        if (arguments.length >= 2) {
            var rv = arguments[1];
        }
        else {
            do {
                if (i in this) {
                    rv = this[i++];
                    break;
                }

                // if array contains no values, no initial value to return
                if (++i >= len)
                    throw new TypeError();
            }
            while (true);
        }

        for (; i < len; i++) {
            if (i in this)
                rv = fun.call(null, rv, this[i], i, this);
        }

        return rv;
    };
}

function formatDollar(num) {
    var p = num.toFixed(2).split(".");
    return "$" + p[0].split("").reverse().reduce(function (acc, num, i, orig) {
        return num + (i && !(i % 3) ? "," : "") + acc;
    }, "") + "." + p[1];
}

function setCurrentJackpot() {
    currentJackpot = (POC + SOB + BlackBeards + FF + BB + S7) / 100;
    $("#ab3-currentjackpot").text(formatDollar(currentJackpot));
}

$(document).ready(function () {
    setInterval("rotateAds()", 3000);
    setInterval("setCurrentJackpot()", 1000);    
    $(".offer-testimon-btn").click(function () {
        var p = $("#offer-testimon-scroll2").css('background-position');
        if (typeof (p) === 'undefined') {
            p = $("#offer-testimon-scroll2").css('background-position-x') + ' ' + $("#offer-testimon-scroll2").css('background-position-y');
        }
        if (p == "0% 0%" || p == "0px 0px") {
            $("#ab2-testimon-you").hide();
            $("#offer-testimon-scroll2").animate({ backgroundPosition: "-713px 0px" }, 250);
        }
        else if (p == "-713px 0%" || p == "-713px 0px") {
            $("#ab2-testimon-you").show();
            $("#offer-testimon-scroll2").animate({ backgroundPosition: "0px 0px" }, 250);
        }
    });
    $("#ab2-testimon-you").hover(function () {
        $("#ab2-testimon-playnow").show();
    }, function () {
        $("#ab2-testimon-playnow").hide();
    });

    $("#ab2-testimon-playnow").mouseover(function () {
        $("#ab2-testimon-playnow").show();
    });
    $("#ab3-ticker-left").click(function () {
        $(".ab3-ticker").hide();
        var p = $("#ab3-progressives").css('background-position');
        if (typeof (p) === 'undefined') {
            p = $("#ab3-progressives").css('background-position-x') + ' ' + $("#ab3-progressives").css('background-position-y');
        }
        if (p == "0% 0%" || p == "0px 0px") {            
            $("#ab3-progressives").animate({ backgroundPosition: "-685px 0px" }, 250, function () { $(".ab3-ticker-s7").show(); });            
        }
        else if (p == "-140px 0%" || p == "-140px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "0px 0px" }, 250, function () { $(".ab3-ticker-poc").show();});
        }
        else if (p == "-275px 0%" || p == "-275px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-140px 0px" }, 250, function () { $(".ab3-ticker-sob").show(); });            
        }
        else if (p == "-410px 0%" || p == "-410px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-275px 0px" }, 250, function () { $(".ab3-ticker-booty").show(); });            
        }
        else if (p == "-550px 0%" || p == "-550px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-410px 0px" }, 250, function () { $(".ab3-ticker-ff").show(); });            
        }
        else if (p == "-685px 0%" || p == "-685px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-550px 0px" }, 250, function () { $(".ab3-ticker-bb").show(); });            
        }
    });
    $("#ab3-ticker-right").click(function () {
        $(".ab3-ticker").hide();
        var p = $("#ab3-progressives").css('background-position');
        if (typeof (p) === 'undefined') {
            p = $("#ab3-progressives").css('background-position-x') + ' ' + $("#ab3-progressives").css('background-position-y');
        }
        if (p == "0% 0%" || p == "0px 0px") {
            //sob
            $("#ab3-progressives").animate({ backgroundPosition: "-140px 0px" }, 250, function () { $(".ab3-ticker-sob").show(); });            
        }
        else if (p == "-140px 0%" || p == "-140px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-275px 0px" }, 250, function () { $(".ab3-ticker-booty").show(); });            
        }
        else if (p == "-275px 0%" || p == "-275px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-410px 0px" }, 250, function () { $(".ab3-ticker-ff").show(); });            
        }
        else if (p == "-410px 0%" || p == "-410px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-550px 0px" }, 250, function () { $(".ab3-ticker-bb").show(); });            
        }
        else if (p == "-550px 0%" || p == "-550px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "-685px 0px" }, 250, function () { $(".ab3-ticker-s7").show(); });            
        }
        else if (p == "-685px 0%" || p == "-685px 0px") {
            $("#ab3-progressives").animate({ backgroundPosition: "0px 0px" }, 250, function () { $(".ab3-ticker-poc").show(); });            
        }
    });

    if (isFlashEnabled()) {
        $("#ab3-offer").hide();
        if (typeof (offerFlash) != "undefined")
            $("#ab3-offer-flash").html(offerFlash);
        if (typeof (threeDIconsFlash) != "undefined")
            $("#ab3-playicons-flash").html(threeDIconsFlash);

    }
    else {
        $("#ab3-offer-flash").hide();
        $("#ab3-playicons-flash").hide();
    }
});

function rotateAds() {
    adCount++;
    switch(adCount)
    {
        case 0:
            $("#ab3-rotator-img").fadeOut('slow', function () { $("#ab3-rotator-img").css("background-image", "url(../app_themes/site/images/ad001-ab3.png)").fadeIn(); });
            break;
        case 1:
            $("#ab3-rotator-img").fadeOut('slow', function () { $("#ab3-rotator-img").css("background-image", "url(../app_themes/site/images/ad002-ab3.png)").fadeIn(); });
            break;
        case 2:
            $("#ab3-rotator-img").fadeOut('slow', function () { $("#ab3-rotator-img").css("background-image", "url(../app_themes/site/images/ad003-ab3.png)").fadeIn(); });
            break;
    }    
    if (adCount == 2)
        adCount = -1;
}

