function checkEmail(emailAddress) {
	
	var str = emailAddress;
	if ((str.indexOf(".") > 0) && (str.indexOf("@") > 0) == true) {
		return true;
	} else {
		//window.alert('Please enter a valid email address');
		return false;
	}
}


$(document).ready(function(){

	$.fn.delay = function(time, callback) {
		return this.animate({ opacity: '+=0' }, time, callback);
	}

	// apply some effects immediately

	replaceStyles();
	//equalHeight($(".singles li h4"));
	equalHeight($(".col1.row2 .panel"));

	// balance cols
	
	var paddingWithFooter = 65;
	var paddingWithoutFooter = 21;
	
	/* general balancing */
	
	$(".col12Span .panel").css({'min-height': $(".col3").height()-paddingWithFooter});
	$(".col12Span .panel.no-footer").css({'min-height': $(".col3").height()-paddingWithoutFooter});

	/* home page balancing */

/*	$(".col1.row1 .panel").css({'min-height':$(".col23Span.row1").height()-paddingWithFooter});
	$(".col1.row2 .panel").css({'min-height':$(".col3.row2").height()-paddingWithFooter});
	$(".col2.row2 .panel").css({'min-height':$(".col3.row2").height()-paddingWithFooter});*/

	/* lyrics page balancing */
	$(".panel.lyrics-index").css({'min-height':($(".panel.lyrics").height()-($(".panel.new-releases").height()+paddingWithFooter))});

/*		$('a').not('.lightBox').click(function() {
		var target = $(this).attr('href');
		$('.panelWrapper').animate({opacity:0}, 75, function() {
			window.location = target;
		});
		return false
	});*/

/*	$(".galleries ul li a img").css({opacity: 0.9});

	$(".galleries ul li a img").hover(function() {
		$(this).fadeTo(100, 1);
	}, function() {
		$(this).fadeTo(100, 0.9);
	}
	);*/

	$('#topOfPage').click(function(e) {
		e.preventDefault();
		$('html,body').stop(true).animate({scrollTop:0},500);
	});
	
	// make article title images click through
	$('.articleTitleLink').click(function(e) {
		window.location = $(this).find('a').attr('href');
	});
	
	fadeMessages();
	
});


function fadeMessages() {

	$('.message').wrap('<div class="messageHolder" />');
	$('.message').delay(3000).animate({opacity:0}, 500, function() {
		$('.messageHolder').slideUp();
	});
	


}

function checkLogInForm() {

	var errors = '';
	if (checkEmail(document.logInForm.email.value)==false)
		errors += '- Email\n';
	if (document.logInForm.password.value.length == 0 || document.logInForm.password.value=='Password' || document.logInForm.password.value=='PASSWORD')
		errors += '- Password\n';

	if (errors != '') {
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		return true;
	}

}

function checkBigLogInForm() {

	var errors = '';

	if (checkEmail(document.bigLogInForm.email.value)==false)
		errors += '- Email\n';
	if (document.bigLogInForm.password.value.length == 0 || document.bigLogInForm.password.value == 'Password' || document.bigLogInForm.password.value == 'PASSWORD')
		errors += '- Password\n';

	if (errors != '') {
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;
	} else {
		return true;
	}

}

//

function checkImageUploadForm() {

	var errors = '';

	if (document.imageForm.imageFile.value.length == 0)
		errors += '- Image (in JPEG format)\n';
	if (document.imageForm.imageFile.value.length == 0)
		errors += '- Caption\n';

	if (errors != '') {
		errors = 'Please complete the following:\n\n'+errors;
		window.alert(errors);
		return false;

	} else {

		/*var destination = document.imageForm.postDestination.value;
		//$(".new-image").css({opacity:0});
		//$(".image-form-holder").height($(".image-form-holder").height());
		$(".image-form").animate({opacity:1}, 500, function() {
			$.post(destination, $("#imageForm").serialize(), 	function(data) {
				$(".new-image").html(data);
				//$(".new-image").animate({opacity:1}, 500);
				//$("#add-image-button").animate({opacity:0}, 500);
				//$(".image-form-holder").animate({height: $(".new-image").height()}, 500);
				fadeMessages();
			});
		});*/
		return true;
	}

}

//

function checkPasswordReminder() {

	errors = '';

	if (checkEmail(document.membersLogInForm.email.value)==false)
		errors += '- Email Address\n';

	if (errors == '') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		document.membersLogInForm.email.focus();
		return false;
	}



}

//

function checkRegisterForm() {

	errors = '';

	if (document.registerForm.firstName.value.length == 0)
		errors += '- First Name\n';
	if (document.registerForm.lastName.value.length == 0)
		errors += '- Last Name\n';
	
	var sexcheck = '';
	for (i=0; i<document.registerForm.sex.length; i++) {
 		if (document.registerForm.sex[i].checked) {
			sexcheck = document.registerForm.sex[i].value;
		}
	}
	if (sexcheck == '')
		errors += '- Sex\n';
	
	if (document.registerForm.username.value.length == 0)
		errors += '- Username\n';
	
	if (checkEmail(document.registerForm.email.value)==false)
		errors += '- Email Address\n';
		
	if (document.registerForm.confirmEmail.value != document.registerForm.email.value) {
		errors += '- Email Addresses did not match\n';
		document.registerForm.checkEmail.value = '';	
	} else if (document.registerForm.confirmEmail.value.length == 0)
		errors += '- Confirmation Email Address\n';

	if (document.registerForm.password.value.length < 6)
		errors += '- Password\n';

	if (document.registerForm.confirmPassword.value.length < 6 || document.registerForm.confirmPassword.value != document.registerForm.password.value)
		errors += '- Confirm Password\n';

	if (errors == '') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

//

function checkProfileForm() {

	errors = '';

	if (checkEmail(document.profileForm.email.value)==false)
		errors += '- Email address\n';

	if (document.profileForm.password.value.length > 0 && (document.profileForm.password.value.length < 6 || document.profileForm.password.value.length > 30))
		errors += '- Password must be between 6 and 30 characters';
	else if (document.profileForm.password.value.length > 0 && document.profileForm.password.value != document.profileForm.confirmPassword.value)
		errors += '- Passwords do not match\n';

	if (errors=='') {
		return true;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

//

//

function checkCommentForm() {

	errors = '';
	
	if (document.commentForm.commentTitle.value.length == 0) {
		errors += '- Comment Title\n';
		document.commentForm.commentTitle.focus();
	}
	if (document.commentForm.commentText.value.length == 0) {
		errors += '- Comment Text\n';
	}

	if (errors == '') {

		var destination = document.commentForm.postDestination.value;
		$(".new-comment").css({opacity:0});	$(".comments-form-holder").height($(".comments-form-holder").height());
		$(".comments-form").animate({opacity:0}, 500, function() {
			$.post(destination, $("#commentForm").serialize(), 	function(data) {
				$(".new-comment").html(data);
				$(".new-comment").animate({opacity:1}, 500);
				$("#add-comment-button").animate({opacity:0}, 500);
				$(".comments-form-holder").animate(
					{height: $(".new-comment").height()}, 500);
				fadeMessages();
			});
		});
		return false;
	} else {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	}

}

function changeAttendance() {
	var destination = document.attendGig.postDestination.value;
	$.post(destination, $("#attendGig").serialize(), function(data) {
		$(".attending-members-list").html(data);
	});
	return false;
}

function loadContent(elementSelector, sourceURL) {
	$("#"+elementSelector+"").load(sourceURL, '', function() {
		replaceStylesDiv(elementSelector)});
}

function fadePanels() {

	$.fn.delay = function(time, callback) {
		return this.animate({ opacity: '+=0' }, time, callback);
	}

	// fade panels up


}

function replaceStyles() {

	$('div.panel').wrap('<div class="panelWrapper" />');
	$('div.banner').wrap('<div class="panelWrapper" />');

}

function replaceStylesDiv(elementSelector) {}

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}

	});
	group.height(tallest);
}


//------------------------------------------------------------------------------
