
function initSplashMainMarquee() {


    $(".action-select-marquee").click(function() {

        var marqueeID = $(this).attr("marquee");

        var pos = $(this).attr("pos");

        if (pos==0) return;

        moveLeft(pos);

        window.clearInterval(banRotInterval);

        return false;

    })

    $(".action-banner-left").click(function() {
        moveRight();
        window.clearInterval(banRotInterval);
        return false;
    })

    $(".action-banner-right").click(function() {
        window.clearInterval(banRotInterval);
        moveLeft();
        return false;
    })

    banRotInterval = window.setInterval(function() {
        moveLeft()
    }, 5000);
    
}

$(function() {



})

var banRotInterval;

var curimage = 0;

var numofrotations = 1;

function marqueeHasBeenSelected(marqueeID) {
    if (!marqueeID) {
        marqueeID = $("div:first-child", floater$).attr("marquee");
    }
    $("#marquee .buttons .selected").removeClass("selected");
    $("#marquee-button-"+marqueeID).addClass("selected");
}

function moveLeft(counts) {

    if (!counts) {
        counts = 1;
    }

    numofrotations = counts;

    moveLeft_();

}

function moveLeft_() {

    numofrotations--;

    var floater$ = $("#floater");
    var firstchild$ = $("div:first-child", floater$);
    var nextchild$ = $("div:nth-child(2)", floater$);

    marqueeHasBeenSelected(nextchild$.attr("marquee"));

    firstchild$.animate({
        "marginLeft": "-600"
    }, 500, null, function() {
        firstchild$.remove().appendTo(floater$);
        firstchild$.css("marginLeft", "0px");
        var buttons$ = $("#marquee .buttons .action-select-marquee");
        buttons$.each(function() {
            var a$ = $(this);
            var pos = parseInt(a$.attr("pos"));
            pos = pos-1;
            if (pos<0) {
                pos = buttons$.size()+pos;
            }
            a$.attr("pos", pos);
        })

        if (numofrotations==0) {
            return;
        } else {
            moveLeft_();
        }

    })
}

function moveRight() {

    var floater$ = $("#floater");
    var lastchild$ = $("div:last-child", floater$);
    lastchild$.css("marginLeft", "-600px");
    lastchild$.remove().prependTo(floater$);
    var nextchild$ = $("div:first-child", floater$);
    marqueeHasBeenSelected(nextchild$.attr("marquee"));
    lastchild$.animate({
        "marginLeft": "0"
    }, 500, null, function() {
        var buttons$ = $("#marquee .buttons .action-select-marquee");
        buttons$.each(function() {
            var a$ = $(this);
            var pos = parseInt(a$.attr("pos"));
            pos = pos+1;
            if (pos>=buttons$.size()) {
                pos = 0;
            }
            a$.attr("pos", pos);
        })
    })
}

