/**
 * A javascript for creating a slide show of partner logos
 * @author Joakim
 * @version 1.1 (2009-09-25)
 */

/**
 * Make sure the script is called automatically when the document is ready
 */
$(document).ready(function(){

    //Execute the slideShow  
    slideShow();
    
});

/**
 * Initialize the images and if there are more than one, start the slide show.
 */
function slideShow(){
	//Set the opacity of all images to 0
    $('#gallery a').css({ opacity: 0.0 });
    
    //Get the first image and display it (set it to full opacity)
    $('#gallery a:first').css({ opacity: 1.0 });
    
	// Only start the slide show if we have more than one partner
	if ($('#gallery a').length > 2) {
		//Call the gallery function to run the slide show, 6000 = change to next image after 6 seconds
    	setInterval('gallery()', 4500);
			
	} else if($('#gallery a').length > 1) {
		$('#gallery a').css({ opacity: 1.0, display: "block" });
	}
}

/**
 * Handle a transition from one logo to the next
 */
function gallery(){

    //if no IMGs have the show class, grab the first image
    var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));
    
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? current.next() : $('#gallery a:first'));
    
    //Fade out the current image and use a callback to hide it and fade in the next one 
    current.removeClass('show');
    current.animate({
        opacity: 0.0
    }, 1000, null, function(){
        current.css({
            display: 'none'
        });
        
        next.css({
            display: 'inline'
        });
        next.addClass('show');
        next.animate({
            opacity: 1.0
        }, 1000);
        
    });
}