$(document).ready(function() {
//	HEADER FUNCTIONS --------------------------------------

//	Animated header assembly
	$('#navigationBack').delay(250).animate({width: 950}, {duration: 'slow', easing:'easeInOutExpo', queue: false });
	$('#navigation').delay(750).fadeIn(1000);
	$('#csDotCom').delay(1250).animate({marginTop:'245px'}, {duration: 'slow', easing:'easeOutBounce'});

//	Create menu blob
  $('<div id="navigationBlob"></div>').css({
		width: $('#navigation li:first a').width(), 
		height: 5
	}).appendTo('#navigation').hide();
				
//	Control for menu blob
  $('#navigation a').hover(function(){
//	MouseOver Function
		$('#navigationBlob').show();
		$('#navigationBlob').animate({width: $(this).width(), left: $(this).position().left},{duration:'slow', easing:'easeOutBounce', queue:false});
			},function() {
//	MouseOut Function
				var leftPosition = $('#navigation li:first a').position().left;
				$('#navigationBlob').stop(true).animate({width: -5}, {duration:'slow', easing:'easeOutCirc', queue: false }).animate({left: leftPosition}, 'fast' ) });

//	Activate header's scrolling pics
	rotatePics(1);
	
//  Zebra Stripe Schedule
	$("#schedule tr.schedule_items:even").addClass("stripe");
	
//	MUSIC PAGE FUNCTIONS -----------------------------------
	
//	Controls for album name selectors
	$('#selectorMIM').hover(function(){$('#nameMakeItMine').fadeIn({duration:'fast'});}, function(){$('#nameMakeItMine').hide()});
	$('#selectorNorth').hover(function(){$('#nameNorth').fadeIn({duration:'fast'});}, function(){$('#nameNorth').hide()});
	$('#selectorRAOB').hover(function(){$('#nameRAOB').fadeIn({duration:'fast'});}, function(){$('#nameRAOB').hide()});
	
//	Show / Hide buttons: Album Infos
	$('#showMIMCredits').click(function() {$('#mimCredits').animate({'height':'toggle'}, 'slow', 'easeOutBounce');});
	$('#showNorthCredits').click(function() {$('#northCredits').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	$('#showRAOBCredits').click(function() {$('#raobCredits').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
/*	$('#showVault').hover(function(){$(this).css({color:'#ffffff'});}, function(){$(this).css({color:'#000000'})}).click(function() {$('#theVault').animate({'height':'toggle'}, 'slow', 'easeOutBounce')}); */
	
//	Show / Hide buttons: Make It Mine Songs
	$('#showSongMakeItMine').click(function() {$('#songMakeItMine').animate({'height':'toggle'}, 'slow', 'easeOutBounce');});
	$('#showSongPrettyBoy').click(function() {$('#songPrettyBoy').animate({'height':'toggle'}, 'slow', 'easeOutBounce');});
	
//	Show / Hide buttons: North Songs
	$('#showSongBound').click(function() {$('#songBound').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	
//	Show / Hide buttons: RAOB Songs
	$('#showSongPity').click(function() {$('#songPity').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	$('#showSongMissAlice').click(function() {$('#songMissAlice').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});

//	Show / Hide buttons: The Vault Songs
	$('#showVault').click(function() {$('#theVault').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	$('#showSongLittleLieITM').click(function() {$('#songLittleLieITM').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	
//	PRESSKIT PAGE FUNCTIONS ---------------------------------
	$('#showVenues2009').click(function() {$('#venues2009').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	$('#showVenues2010').click(function() {$('#venues2010').animate({'height':'toggle'}, 'slow', 'easeOutBounce')});
	
//Contact submit button
	$('#contact_submit').click(function() {
		//contact_name contact_email contact_message 
		var is_valid = true;
		
		$('.error_message').hide();
		
		if ($('#contact_name').val() == '') {
			$('#contact_name_error').show();
			is_valid = false;			
		} else {
			if ($('#contact_email').val() == '') {
				$('#contact_email_error').show();
				is_valid = false;
			} else {
				if (!validateEmail($('#contact_email').val())) {
					$('#contact_email_error').show();
					is_valid = false;
				} else {
					if ($('#message_content').val() == '') {
						$('#contact_message_error').show();
						is_valid = false;
					}
				}
			}
		}

		if (is_valid) {
		
			$.post("/email.php", {   contact_name: $('#contact_name').val(), 
									contact_email: $('#contact_email').val(),
										subject: $('#subject').val(),
								  message_content: $('#message_content').val()
								  },
				function(data) {
					$('#message_sent').show().delay(2000).fadeOut(2000);
					$('#contact_name').val(''); 
					$('#contact_email').val('');
					$('#subject').val('');
					$('#message_content').val('');
				});
		}
		
	});
});

//Email validation code
function validateEmail($email) 
{
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if( !emailReg.test( $email ) ) {
        return false;
    } else {
        return true;
    }
}




function rotatePics(currentPic) 
{
	var numberOfPics = $('#headerScrollingPics img').length;
	currentPic = currentPic % numberOfPics;
	
	$('#headerScrollingPics img').eq(currentPic).fadeOut(function() {
		//re-order the z-index
		$('#headerScrollingPics img').each(function(i) {
			$(this).css('z-index', ((numberOfPics - i) + currentPic) % numberOfPics);
													});
		$(this).show();
		$('#headerScrollingPics').delay(2700).fadeIn();
	setTimeout(function() {
		if($('#headerScrollingPics img.headerInitialPic')) {
			 $('#headerScrollingPics img.headerInitialPic').remove();
			 }
		rotatePics(++currentPic);}, 5000);
	});
}

