// JavaScript Document

// Stay Connected
$( function() {
	$( "#stay_connected .title" ).toggle( function() {
		var title = $( this );
		title.siblings( ".content" ).slideDown( 50, function() { title.addClass( "active" ); } );
		console.log( "Toggle!" );
	}, function() {
		var title = $( this );
		title.siblings( ".content" ).slideUp( 50, function() { title.removeClass( "active" ); } );
		console.log( "Toggle!" );
	});
});

// Slideshow
$.slideShow = new Object();
$.slideShow.queue = new Array();
$.slideShow.interval = 10000;
$.slideShow.transition = 1200;
$.slideShow.active = null;
$.slideShow.next = null;

$.slideShow.start = function() {
		$( "div#en_header div#photo img.slideshow" ).each( function( i, e ) {
				$.slideShow.queue.push( $( e ) );
			});
		
		if ( $.slideShow.queue.length > 1 ) {
			$.slideShow.active = $.slideShow.queue.shift().show();
			$.slideShow.queue.push( $.slideShow.active );
			
			window.setTimeout( $.slideShow.loop, $.slideShow.interval );
		}
		else if ( $.slideShow.queue.length == 1 ) {
			$.slideShow.active = $.slideShow.queue.shift().show();
		}
	};

$.slideShow.loop = function() {
		$.slideShow.next = $.slideShow.queue.shift();
		
		$.slideShow.active.fadeOut( $.slideShow.transition );
		$.slideShow.next.fadeIn( $.slideShow.transition );
		$.slideShow.active = $.slideShow.next;
		$.slideShow.queue.push( $.slideShow.active );
		
		window.setTimeout( $.slideShow.loop, $.slideShow.interval );
	};

$( function () { $.slideShow.start(); });
