/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch(slideTo) {
    var $active = $('#slideshow div.active');
    if ( $active.length == 0 ) $active = $('#slideshow div:last');
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow div:first');
    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    $active.addClass('last-active');
    
    var slideTo = ( slideTo+1 ) ? slideTo : null;
    if ( slideTo != null ) {
    	$next = $('#slideshow div').eq(slideTo);
    }
    
    var theTitle = $next.attr('title');
    
    var i = 0;
    $("#slideButtons a").each(function(index) {
    	if(i == theTitle) {
    		$(this).addClass('active');
    	} else {
    		$(this).removeClass('active');
    	}
    	i++;
    });

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
	//setInterval( "slideSwitch()", 5000 );
    var playSlideshow = setInterval( "slideSwitch()", 5000 );
    // create buttons to move to specific slide
    var $slideButtons = $("#slideButtons a.slideButton");
    $slideButtons.click(function(){
    	var that = $(this);
    	var id = that.attr('rel');
    	
    	$("#slideButtons a").each(function(index) {
    		$(this).removeClass("active");
    	});
    	
    	that.addClass("active");
    	
    	// stop the slideshow, to keep it from trying to overlap our transition
    	clearInterval(playSlideshow);
    	// call the function using the index of the clicked button
    	//slideSwitch( $slideButtons.index(this) );
    	slideSwitch( id );
    	// restart the slideshow
    	// setTimeout( 'playSlideshow = setInterval( "slideSwitch()", 5000 )', 5000);
    });
});


function disableEnterKey(e) {
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}


