﻿function showBanner(divId) {
    if (timerId != null)
        clearInterval(timerId);
    var bannerDivs = document.getElementsByClassName('banner');
    for (var i = 0; i < bannerDivs.length; i++) {
        bannerDivs[i].style.display = 'none';
    }
    document.getElementById(divId).style.display = 'inline';
}

function getFileName() {
    var url = document.URL.toString().toLowerCase(),
	i = url.lastIndexOf('/') + 1,
	j = url.indexOf('#', i),
	k = url.indexOf('?', i);

    if (-1 == j) { j = url.length; }
    if (-1 == k) { k = url.length; }

    return "/" + url.substring(i, Math.min(j, k));
}
var timerId = null;
var bannerIndex = -1;

function toggleBanners() {
    var currentPage = getFileName();
    if (currentPage == "/" || currentPage == "/index.asp") {
        var bannerDivs = document.getElementsByClassName('banner');
        if (bannerDivs) {
            bannerIndex += 1;
            if (bannerIndex > (bannerDivs.length - 1)) {
                bannerIndex = 0;
            }
            for (var i = 0; i < bannerDivs.length; i++) {
                bannerDivs[i].style.display = 'none';
                bannerDivs[i].style.width = '786px';
            }
            bannerDivs[bannerIndex].style.display = 'inline';
            bannerDivs[bannerIndex].style.width = '786px';
            if (timerId == null) {
                timerId = setInterval(toggleBanners, 5000);
                //I ROTATING SLIDESHOW
            }
        }
    }
}

document.getElementsByClassName = function(className, parentElement) {
    var children = (document.getElementById(parentElement) || document.body).getElementsByTagName('*');
    var elements = new Array();

    for (var i = 0; i < children.length; i++) {
        if (children[i].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
            elements.push(children[i]);
    }
    return elements;
}
/*@cc_on@*/
/*@if (@_win32)
if (window.attachEvent) {
    window.attachEvent('onload', toggleBanners);
}
@else @*/
window.onload = init;
/*@end
@*/
function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

};

/* for Mozilla */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", toggleBanners, false);
}