(function ($) {
$( window ).load( function(){
	//start_slides( '.intros div', 4500 );
	
	var speed = 1200;
	
	$('.slide1-1').fadeIn(speed, function(){
		$('.slide1-2').fadeIn(speed, function(){
			$('.slide1-3').fadeIn(speed, function(){
				$('.slide1-4').fadeIn(speed, function(){
					
					window.setTimeout(function(){
						$('.first-slides span').fadeOut(speed, function(){
							
							$('.slide2-1').fadeIn(speed, function(){
								$('.slide2-2').fadeIn(speed, function(){
									$('.slide2-3').fadeIn(speed, function(){
										$('.slide2-4').fadeIn(speed, function(){
											
											window.setTimeout(function(){
												$('.second-slides span').fadeOut(speed, function(){
													
													$('.slide3-1').fadeIn(speed, function(){
														$('.slide3-2').fadeIn(speed, function(){
															$('.slide3-3').fadeIn(speed, function(){
																$('.slide3-4').fadeIn(speed, function(){
																	window.location = $('.skip').attr('href');
																});
															});
														});
													});	
													
												});
											}, speed);
											
										});
									});
								});
							});	
							
						});
					}, speed);
					
				});
			});
		});
	});
	
	//$('#nav li').hover(
	//	function(){ $(this).find('ul').show(); $(this).addClass('hover'); },
	//	function(){ $(this).find('ul').hide(); $(this).removeClass('hover'); }
	//)
	
	$('#nav ul li a:contains(Join)').parent().addClass('join');
	var a = $('#nav ul li a:contains(Event)');
	//$('#nav ul li a:contains(Event)').parent().append('<a class="sub" href="/calendar">Calendar</a>');
	
	var as = $('#nav ul li a').not('#nav ul li ul li a');
	$.each($(as), function () {
		if (/ (?!&)/.test($(this).html().toString())) {
			$(this).html($(this).html().replace(/ (?!&)/, '<br />'));
		} else {
			$(this).css({'line-height': '29px'});
		}
	});
});

function _animate(){
	
}

function start_slides( item, time, callback ) {
	var all_items = $( item ).length;
	if ( all_items < 1 ) return;
	var zindex = all_items;
	var i=0;
	$( item ).each( function(){
		$( this ).css( { 'z-index': zindex } );
		if ( i > 0 ) $( this ).hide();
		zindex--;
		i++;
		var img = new Image();
		img.src = $( this ).attr('src');
	});
	
	var index = 0;
	var next;
	var time = time || 5000;
	var callback = callback || function(){};
	
	var interval = window.setInterval( function(){
		if ( index == all_items ) index = 0;
		next = index + 1;
		
		if ( next == all_items ) next = 0;
		
		$( item + ":eq(" + index + ")" ).fadeOut(1200);
		$( item + ":eq(" + next + ")" ).fadeIn(1200, function(){
			callback( next );
		});
		
		index++;
	}, time);
}
})(jQuery)
