// adding a useless variable within a comment to force a change:  
$(document).ready(function () {
    var offerHolders = $("div.rotate div.offer-holder"),
    rotateControls = $("div.rotate-contols"), adPrev, adNext, adIndicators,
    currentIdx = 0,
    rotTimer = false,
    timedRotation = true;
    /*
    function rotate() {
    var i = $("div.rotate div.offer-holder:visible").prevAll("div").length + 1;
    i = i % offerHolders.length;
    if (offerHolders.length > 1) {
    offerHolders.animate({ "opacity": "0" }, 100).eq(i).animate({ "opacity": "1" }, 1000);
    var speed = offerHolders.eq(i).find('.lblSeconds').text();
    setTimeout(rotate, (parseInt(speed) * 1000));
    offerHolders.hide().eq(i).show();
    }
    };
    rotate();
    */
    // create rotations
    function rotateTo(i) {
        currentIdx = i;
        if (rotTimer) { clearTimeout(rotTimer); rotTimer = false; }
        if ($(".ie7orLess").length > 0) { offerHolders.hide().eq(i).show(); }
        else { offerHolders.animate({ "opacity": "0" }, 100).eq(i).animate({ "opacity": "1" }, 1000); }
        var speed = offerHolders.eq(i).find('.lblSeconds').text();
        if (timedRotation) { rotTimer = setTimeout(rotate, (parseInt(speed) * 1000)); }
        offerHolders.hide().eq(i).show();
        // adjust indicators
        adIndicators.find("img").attr({ "src": "Images/Homepage/ob-indicator-off.png" });
        adIndicators.eq(i).find("img").attr({ "src": "Images/Homepage/ob-indicator-on.png" });
        // rollovers
        adIndicators.hover(
            function () { $(this).find("img").attr({ "src": "Images/Homepage/ob-indicator-on.png" }); },
            function () { $(this).find("img").attr({ "src": "Images/Homepage/ob-indicator-off.png" }); }
        );
        adIndicators.eq(i).unbind("mouseenter mouseleave");
    };
    function rotate() {
        currentIdx += 1;
        if (currentIdx >= offerHolders.length) { currentIdx = 0; }
        rotateTo(currentIdx);
    };
    // initialize ads
    offerHolders.hide().eq(currentIdx).show();
    // build offer pagination if more than one offer
    if (offerHolders.length > 1) {
        // create ad indicators
        offerHolders.each(function (index) {
            var adIndicator = $('<a href="#" class="ad-indicator"><img src="Images/Homepage/ob-indicator-off.png" /></a>');
            rotateControls.append(adIndicator);
            adIndicator.click(function () { timedRotation = false; rotateTo(index); return false; });
        });
        adIndicators = $("a.ad-indicator");
        // previous / next buttons
        adPrev = $('<a href="#"><img src="Images/Homepage/ob-slide-left.png" /></a>');
        adNext = $('<a href="#"><img src="Images/Homepage/ob-slide-right.png" /></a>');
        adPrev.click(function () {
            timedRotation = false;
            currentIdx -= 1;
            if (currentIdx < 0) { currentIdx = (offerHolders.length - 1); }
            rotateTo(currentIdx);
            //if (currentIdx > 0) { rotateTo(currentIdx - 1); }
            return false;
        });
        adNext.click(function () {
            timedRotation = false;
            currentIdx += 1;
            if (currentIdx >= offerHolders.length) { currentIdx = 0; }
            rotateTo(currentIdx);
            //if (currentIdx < (offerHolders.length - 1)) { rotateTo(currentIdx + 1); }
            return false;
        });
        rotateControls.prepend(adPrev);
        rotateControls.append(adNext);
        // start rotations
        rotateTo(0);
    }
    // set up restrictions
    $(".linkItem").each(function () {
        var link = $(this);
        if (link.attr("href") === "restriction") {
            link.click(function () {
                link.parent().find(".ob-restrict-holder").toggle();
                if (rotTimer) { clearTimeout(rotTimer); rotTimer = false; }
                timedRotation = false;
                return false;
            });
        }
    });
});
function restrictWindow(obj) {
    $(obj).parent().parent().find(".ob-restrict-holder").toggle();
}
