﻿
var ptCycleLastInterval = 0;
var ptFadeLastInterval = 0;
var totalItems = 0;
var currentItem = 1;
var nextItem = 1;

function prepareProdTicker() {
    var i = 1;
    var objNav = document.getElementById("div_ProductTickerNav");
    while (document.getElementById("div_ProductTicker" + i)) {
        objNav.innerHTML = objNav.innerHTML + '<a id="a_ProductTickerNav' + i + '" href="javascript:showProdTicker(' + i + ');" title="">' + i + '</a>';
        i++;
    }
    totalItems = i - 1;
    hideProdTickerItems();
    showProdTicker(1);
    ptCycleLastInterval = window.setInterval(showNext, 6000);
}
function showNext() {
    nextItem = currentItem + 1;
    if (nextItem > totalItems) {
        nextItem = 1;
    }
    ptFadeLastInterval = window.setInterval(doFade, 70);
}
function doFade() {
    var objOld = document.getElementById("div_ProductTicker" + currentItem);
    var objNew = document.getElementById("div_ProductTicker" + nextItem);
    objNew.style.display = "block";
    objOld.style.opacity = parseFloat(objOld.style.opacity) - 0.05;
    objNew.style.opacity = parseFloat(objNew.style.opacity) + 0.05;
    if (typeof objOld.style.filter != "undefined") {
        objOld.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + parseFloat(objOld.style.opacity) * 100 + ")";
        objNew.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + parseFloat(objNew.style.opacity) * 100 + ")";
    }
    if (objNew.style.opacity >= 1 || objOld.style.opacity <= 0) {
        window.clearInterval(ptFadeLastInterval);
        objOld.style.display = "none";
        currentItem = nextItem;
        doNavHighlights();
    }
}


function showProdTicker(item) {
    hideProdTickerItems();
    document.getElementById("div_ProductTicker" + item).style.display = "block";
    document.getElementById("div_ProductTicker" + item).style.opacity = 1;
    if (document.getElementById("div_ProductTicker" + item).style.filter) {
        document.getElementById("div_ProductTicker" + item).style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    }
    currentItem = item;
    doNavHighlights();
}
function hideProdTickerItems() {
    var i = 1;
    while (document.getElementById("div_ProductTicker" + i)) {
        document.getElementById("div_ProductTicker" + i).style.display = "none";
        document.getElementById("div_ProductTicker" + i).style.opacity = 0;
        if (document.getElementById("div_ProductTicker" + i).style.filter) {
            document.getElementById("div_ProductTicker" + i).style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
        }
        i++;
    }
}
function doNavHighlights() {
    var i = 1;
    while (document.getElementById("a_ProductTickerNav" + i)) {
        document.getElementById("a_ProductTickerNav" + i).className = "";
        i++;
    }
    document.getElementById("a_ProductTickerNav" + currentItem).className = "a_Current";
}

prepareProdTicker();