﻿/// <reference path="../jquery-1.3.2.min-vsdoc.js" />
var r = setInterval('rotate()', 1000000);
function theRotator() {
    //Set the opacity of all images to 0
    $('div#PicRotator ul li img').css({ opacity: 0.0 });
    $('div#PicRotator ul li span').css({ opacity: 0.0 });
    clearInterval(r);
    r = setInterval('rotate()', 6000);
    

    //Get the first image and display it (gets set to full opacity)
   $('div#PicRotator ul li:first img').css({ opacity: 1.0 });
   $('div#PicRotator ul li:first span').css({ opacity: 0.0 }).addClass('mo');
   
   $('div#PicRotator').mouseenter(
        function(tag) {
                $('div#PicRotator ul li.show span')
                .css({ opacity: 0.0 })
                .animate({ opacity: 0.9 }, 1000);
                clearInterval(r);
        });
        $('div#PicRotator').mouseleave(
        function(tag) {
            $('div#PicRotator ul li span')
                .animate({ opacity: 0.0 }, 1000)
            clearInterval(r);
            r = setInterval('rotate()', 6000);
        });
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
}

function rotate() {
    //Get the first image
    var current = ($('div#PicRotator ul li.show') ? $('div#PicRotator ul li.show') : $('div#PicRotator ul li:first'));
    var curimg = current.find('img');
    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#PicRotator ul li:first') : current.next()) : $('div#PicRotator ul li:first'));
    var nextimg = next.find('img');
    //Set the fade in effect for the next image, the show class has higher z-index
    next.addClass('show');
    next.find('span').addClass('mo').css({ opacity: 0.0 })
	            
                
    nextimg.css({ opacity: 0.0 })
	    .animate({ opacity: 1.0 }, 1000);

    //Hide the current image
    current.removeClass('show');
    curimg.find('img').animate({ opacity: 0.0 }, 1000);
    current.find('span').removeClass('mo').css({ opacity: 0.0 })
	
	

}

$(document).ready(function() {
    //Load the slideshow
    theRotator();
});
