/* Javascript written by Tyler Mulligan of Salter>Mitchell */
$(document).ready(function() {

	// Tabs
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	
	$('.tab').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('.tab').removeClass('selected');
			$(this).addClass('selected');
			return false;
	}).filter(':first').click();

	$("#to_billboards").corner("cc:#404041 top 5px");
	$("#to_video").corner("cc:#404041 top 5px");

	// Setup validation
	$("#invite_a_teacher").validate({
		errorLabelContainer: $("#errors")
	});
	// Clear box on first click
	$("#teacher_email").click(function(){
		if ($(this).val()=="Enter Teacher's Email") {
			$(this).val("");
		}
	});
	// On submit, check if it's a valid email
	$("#send_email").click(function(){
		// Make sure the email box is valid
		if ($("#invite_a_teacher").valid()) {
			// Get URL
			var url = $(this).attr("href");
			// Initiate Colorbox
			$.fn.colorbox({
				href:url+"/"+$("#teacher_email").val(),
				open:true,
				iframe:true,
				height:390,
				intialHeight:100,
				width:640,
				initialWidth:400
			});
		}
		return false; // return false to not activate the link
	});
	// Disable enter for submiting
	$('#invite_a_teacher').bind("keypress", function(e) {
		$("#send_email").removeClass("click_me");
		if (e.keyCode == 13) {
			$("#send_email").addClass("click_me");
			return false;
		}
	});
	// Billboards
	$("a[rel='billboards']").colorbox();
});

