﻿
var arrRotatorImage = null;
var arrRotatorId = null;
var arrRotatorName = null;
var arrRotatorUrl = null;
var arrRotatorUrlTarget = null;
//new Array("PROMOS-myCBTS-Cisco.png", "PROMOS-myCBTS-cNotify.png", "PROMOS-myCBTS-MiDesk.png")
var arrRotatorIndex = 0;
var arrRotatorCurrIndex = 0;
var arrRotatorMax = 0;
var rotatorTimeInterval = 7000;
var timerRotator = null;

function doStartRotator(skipOnce) {
    if (!skipOnce) {
       
        doRotatorChange(arrRotatorIndex);
    }
    else {
        skipOnce = false;
    }

    timerRotator = setTimeout("doStartRotator(false)", rotatorTimeInterval);
}


function doRotatorUrl(index) {
    
    location.href = arrRotatorUrl[index];
}

function doRotatorChange(index) {

    var imageId = 'imgRotator';
    //  alert(index);
    if (arrRotatorUrl[index] != '') {
        document.getElementById('divRotatorImage').innerHTML = '<a target="' + arrRotatorUrlTarget[index] + '" href="' + arrRotatorUrl[index] + '"> <img onmouseover="doStopRotator()" onmouseout="doStartRotator(true)" alt="' + arrRotatorName[index] + '"  src="/images/ImgHandler.ashx?id=' + arrRotatorImage[index] + '" border="0" id="imgRotator" /></a>';

    }
    else {
        document.getElementById('divRotatorImage').innerHTML = ' <img onmouseover="doStopRotator()" onmouseout="doStartRotator(true)" alt="' + arrRotatorName[index] + '"  src="/images/ImgHandler.ashx?id=' + arrRotatorImage[index] + '" border="0" id="imgRotator" />';
    }
 
   // document.getElementById('divRotatorImage').innerHTML = "<div onmouseover='doStopRotator()' onmouseout='doStartRotator(true)' style='cursor:pointer' onclick='doRotatorUrl(" + index + ")'>" + document.getElementById('divRotatorImage'+ index).innerHTML  + "</div>";
    var image = document.getElementById(imageId);
    setRotatorOpacity(image, 50);
    image.style.visibility = 'visible';
    rotatorFadeIn(imageId, 50);
  //  document.getElementById('divRotatorNav').innerHTML = GetRotatorNav(index + 1);
    arrRotatorCurrIndex = index;
    arrRotatorIndex = index + 1;
    if (arrRotatorIndex >= arrRotatorMax) {
        arrRotatorIndex = 0;
    }

}

function doStopRotator() {

    if (timerRotator)
        clearTimeout(timerRotator);
}

function doGoToRotatorArrow(index) {

    arrRotatorIndex = arrRotatorCurrIndex + index;
    //alert(arrRotatorCurrIndex   + ' - ' + arrRotatorIndex);
    if (arrRotatorIndex < 0) {
        arrRotatorIndex = arrRotatorMax - 1;
    }
    else if (arrRotatorIndex >= arrRotatorMax) {
        arrRotatorIndex = 0;
    }
    //alert(arrRotatorCurrIndex   + ' - ' + arrRotatorIndex);
    doStopRotator();
    doRotatorChange(arrRotatorIndex);
}

function GetRotatorNav(index) {

    var nav = '';
    var a = 0;
    for (var i = 1; i <= arrRotatorMax; i++) {
        a = i - 1;
        if (index == i) {
            nav += '<a class="selected" href="javascript:doGoToRotator(' + a + ')">' + i + '</a>';
        } else {
            nav += '<a href="javascript:doGoToRotator(' + a + ')">' + i + '</a>';
        }
    }
    nav = '<table align="right" border="0"><tr><td valign="middle" style="padding-top:0px"><span><a href="javascript:doGoToRotatorArrow(-1)"><img src="/images/arrow-left-darkgray.gif"  border="0" alt="" /></a></td><td  valign="middle">' + nav + '</td><td style="padding-top:0px" valign="middle"><span><a href="javascript:doGoToRotatorArrow(1)"><img src="/images/arrow-right-darkgray.gif"  border="0" alt="" /></a></td></tr></table>';
    return nav;
}

function setRotatorOpacity(obj, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    // IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";

    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity / 100;

    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity / 100;

    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity / 100;
}

function rotatorFadeIn(objId, opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
            setRotatorOpacity(obj, opacity);
            opacity += 10;
            window.setTimeout("rotatorFadeIn('" + objId + "'," + opacity + ")", 225);
        }
    }
}

function doGoToRotator(index) {
    doStopRotator();
    arrRotatorIndex = index;
    doRotatorChange(arrRotatorIndex);
}
