﻿var timer;
function slideSwitch(pointer) {
    if ($('#slideshow').children('div').length <= 1)
        return;
    var $active = $('#slideshow DIV.active');

    if ($active.length == 0) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    //process square graphic clicking
    if (pointer != null && pointer > 0) {
        $next = $('#imgContents_' + pointer.toString());
    }
    //    if($active==$next)
    //    {
    //    return;
    //    }
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    //    alert($active.attr('id'));
    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
    //synchronize with square graphic
        $('#squareImgUL>li').removeClass('activeLi');
//        try {
            $('#' + $next.attr('id').replace('imgContents_', 'squareImgLI_')).addClass("activeLi");
//        }
//        catch (err) { 
//    }
}

function switchBanner(pointer) {
    if (timer != null) {
        clearInterval(timer);
    }
    slideSwitch(pointer);
    timer = setInterval("slideSwitch()", 5000)
}

function showBanner(data) {
    if (data == '') {
        $('#bannerImage').css("display","none");
    }
    else
        $('#bannerImage').html(data);
}
