

$(document).ready( function() {

	//	Setup hovers
	hoverHighlight("#youtube");
	hoverHighlight("#viewClips");
	hoverHighlight("#membersLogout");
	hoverHighlight(".htmlClipTitle");

	//	Setup Members Section Sliders
	slideToggle("#youtube", "#youtubeSection");

	//	Setup video clip sliders
	slideToggle(".htmlClipTitle", ".htmlClipFlyout");

	//	Setup logout button destination
	$("#membersLogout").click( function() {
		window.location = "/?p=logout";
	});

	//	Setup view all clips button destination
	$("#viewClips").click( function() {
		window.location = "/?p=clips";
	});

	//	Trap add youtube form
	$("#formAddYouTube").submit( validateForm );
});

function slideToggle(elm1, elm2) {
	$(elm1).toggle(
		function(e) {
			$(e.target).next(elm2).slideDown( "fast" );
		},
		function(e) {
			$(e.target).next(elm2).slideUp("fast");
		});
}

function validateForm() {
	if( !$("#clipTitle").val() ) {
		return error("You have not specified a title");
	}

	if( !$("#clipCode").val() ) {
		return error("You have not specified embed code");
	}

	if( !$("#clipDescription").val() ) {
		return error("You have not specified a description");
	}

	return true;
}

function error(msg) {
	//	Show this error
	$("#errorBoxError").html(msg);

	//	Flash the error box
	$("#errorBox").fadeIn(200).delay(300).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);

	return false;
}

function hoverHighlight(elm) {
	$(elm).hover(
		function() {
			$(this).addClass("highlight");
		},
		function() {
			$(this).removeClass("highlight");
		}
	);
}

