/*
 * By Dylan Wagstaff, http://www.alohatechsupport.net
 */

var $jq = jQuery.noConflict();


function theRotator() {
    // Anzahl der Bilder, Verzögerung
    var num_rotators = 4;
    var time = 6000;

    for (i=1; i<=num_rotators; i++) {
    //Set the opacity of all images to 0
    $jq('div#header_pic_'+i+' ul li').css({
        opacity: 0.0
    });

    //Get the first image and display it (gets set to full opacity)
    $jq('div#header_pic_'+i+' ul li:first').css({
        opacity: 1.0
    });

    //setInterval('rotate('+i+')',(time - i*300));
    setInterval('rotate('+i+')', time);
    }

}

function rotate(number) {
    //Get the first image
    var current = ($jq('div#header_pic_'+number+' ul li.show')?  $jq('div#header_pic_'+number+' ul li.show') : $jq('div#header_pic_'+number+' ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $jq('div#header_pic_'+number+' ul li:first') :current.next()) : $jq('div#header_pic_'+number+' ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({
        opacity: 0.0
    })
    .addClass('show')
    .animate({
        opacity: 1.0
    }, 1500);

    //Hide the current image
    current.animate({
        opacity: 0.0
    }, 1500)
    .removeClass('show');

};

$jq(document).ready(function() {
    //Load the slideshow
    theRotator();
    //initLightbox();
});
