﻿

// Featured Deals
var rotator;
var disableButtons = true;
var curr_pos = 0;
var max_pos = 0;
var rotator;

function Next() {
    HideAll();

    curr_pos = curr_pos + 3;
    
    if (curr_pos >= max_pos) curr_pos = curr_pos-max_pos;
    
    image1 = curr_pos;
    image2 = (image1 >= (max_pos - 1)) ? 0 : image1 + 1;
    image3 = (image2 >= (max_pos - 1)) ? 0 : image2 + 1;

    ShowImage(image1, 0);
    ShowImage(image2, 1);
    ShowImage(image3, 2);

    clearTimeout(rotator);
}


function Prev() {
    HideAll();

    curr_pos = curr_pos - 3;

    if (curr_pos <= 0) curr_pos = max_pos - 1;

    image1 = curr_pos;
    image2 = (image1 <= 0) ? max_pos - 1 : image1 - 1;
    image3 = (image2 <= 0) ? max_pos - 1 : image2 - 1;

    ShowImage(image1, 2);
    ShowImage(image2, 1);
    ShowImage(image3, 0);

    clearTimeout(rotator);
}


function ShowImage(imagenum, slotnum) {

    curr_div = document.getElementById("good_deal" + imagenum);

    if (curr_div) {
        curr_div.className = "slot" + slotnum
        curr_div.style.visibility = "visible";
    }
}

function HideAll() {

    count = 0;

    while (count < max_pos) {
        curr_div = document.getElementById("good_deal" + count);

        if (curr_div)
            curr_div.style.visibility = "hidden";
        curr_div.className = ""

        count++;
    }

}



function init() {

    //curr_page = 0;

    rotator = setTimeout('RotatePage()', 5000);

    setTimeout('EnableButtons()', 3000);            // disable pre/next button to allow page to load

}

function EnableButtons() {
    disableButtons = false;
}

function RotatePage() {
    Next();

    rotator = setTimeout('RotatePage()', 5000);

}

// offer redirection and display coupon code

function offerRedirect(contentid, couponcode) {


  if (couponcode != "") {
    couponcodeurl = "/DisplayCouponCode.aspx?id=" + contentid;
    window.open(couponcodeurl, "", "width=470,height=380");
    window.location = "/offerRedirect.aspx?id=" + contentid

  }
  else {

    //*** 4092 - open dialog like 'get code' with diff text. Therefore redirected url needs to open in same window like 'get code' does ***
    couponcodeurl = "/ActivatedCouponCode.aspx?id=" + contentid;
    window.open(couponcodeurl, "", "width=470,height=380");
    window.location = "/offerRedirect.aspx?id=" + contentid
    //window.open("/offerRedirect.aspx?id=" + contentid, "", "");
  
  }

}
