// JavaScript Document
$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

$(document).ready(function() {
	$('#joinML').click(function(){
		$.post("/assets/php/mlForm.php", function(data){callJoinMl(data);});
		return false;}
		);
	
	$('body').click(function(event){
		if($(event.target).is('#videoBoxBg')){
			destroyVideoArea();
			return false;
		}else
		if($(event.target).is('#closeBtn') || $(event.target).parent().is('#closeBtn')){
			destroyVideoArea();
			return false;
		}
	});
/*	
	$('body').focus(function(event){
		if($(event.target).is('#email')){
			alert("weee");
			if( $(event.target).value == $(event.target).defaultValue )
				$(event.target).value = "";
		}
	});

	$('body').blur(function(event){
		if($(event.target).is('#email')){
			if( !$(event.target).value.length )
				$(event.target).value = $(event.target).defaultValue;
		}
	});
	*/
	$('body').submit(function(event){
		if($(event.target).is('#mlform')){
			$.post("/ext.php",$(event.target).serialize(), function(data){ 
				$('#message').empty().html(data).slideDown(100);
			});
			return false;
		}
	});
});



function callJoinMl(data){
	if($('#videoBox').length > 0){
		}else{
				$('#content').prepend(data);
				$('body').prepend('<div id="videoBoxBg"></div>');
				$('#videoBoxBg').hide().fadeIn();
				$('#contentBox').hide().slideDown();
				$("#email").search();
			}
	}


function destroyVideoArea(){
	$('#videoBoxBg').fadeOut("slow",function(){$('#videoBoxBg').remove();});
	$('#contentBox').slideUp("slow",function(){$('#videoBox').remove();});
}