﻿
/*** 
Bad copy'n'paste code... but i ran out of time...
***/

function slideSwitch1() {


    var $active = $('#slideshow1 DIV.active');

    if ($active.length == 0) $active = $('#slideshow1 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideshow1 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    var len = $("#slideshow1 > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                    .addClass('active')
                    .animate({ opacity: 1.0 }, 1000, function() {
                        $active.removeClass('active last-active');
                    });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }

}
function slideSwitch2() {


    var $active = $('#slideshow2 DIV.active');

    if ($active.length == 0) $active = $('#slideshow2 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideshow2 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    var len = $("#slideshow2 > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 1.0 }, 1000, function() {
                            $active.removeClass('active last-active');
                        });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }

}
function slideSwitch3() {


    var $active = $('#slideshow3 DIV.active');

    if ($active.length == 0) $active = $('#slideshow3 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideshow3 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    var len = $("#slideshow3 > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 1.0 }, 1000, function() {
                            $active.removeClass('active last-active');
                        });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }

}
function slideSwitch4() {


    var $active = $('#slideshow4 DIV.active');

    if ($active.length == 0) $active = $('#slideshow4 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideshow4 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    var len = $("#slideshow4 > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 1.0 }, 1000, function() {
                            $active.removeClass('active last-active');
                        });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }

}
function slideSwitch5() {


    var $active = $('#slideshow5 DIV.active');

    if ($active.length == 0) $active = $('#slideshow5 DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideshow5 DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    var len = $("#slideshow5 > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 1.0 }, 1000, function() {
                            $active.removeClass('active last-active');
                        });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }

}

$(function() {
    /* Show first ads without waiting for the interval */
    slideSwitch1();
    slideSwitch2();
    slideSwitch3();
    slideSwitch4();
    slideSwitch5();
    /* use different intervals.  Looks better if they don't all change at once */
    setInterval("slideSwitch1()", 12000);
    setInterval("slideSwitch2()", 17000);
    setInterval("slideSwitch3()", 20000);
    setInterval("slideSwitch4()", 15000);
    setInterval("slideSwitch5()", 19000);

});
