function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
	  return true;
	}
}


//Close flash container
function closeFlashConater (){

	$("#flashContainer").overlay().close();
	
	$("ul#slides").cycle({
		fx: 'fade',
		pause: 1,
		prev: '#prev',
		next: '#next'
	
	});

}

// JavaScript Document
$(document).ready(function(){
						   
						   
						   
	//Window Resize
	var $windowHeight = $(window).height();
	$windowHeight = $windowHeight - (49+ 35);
	//alert($windowHeight);
	
	$("#container").height($windowHeight);
	
				
	if($windowHeight < 500)
					$windowHeight = 500;
	$("#container").height($windowHeight);
	
	$("body").css("visibility","visible");
	
	//Hide Slide show images
	$("#slideshow").css("overflow", "hidden");
	
	//Home Page Slide show for keysWords
	$("#slideshowKeywords").cycle({
		random: 2, 
		fx: 'fade',
		pause: 1
	});
	
  	//INT Flash INTRO
	if(jQuery.url.param("flashintro")=="false"){
			$("ul#slides").cycle({
				fx: 'fade',
				pause: 1,
				prev: '#prev',
				next: '#next'
		
			});
	}else{
		// select the overlay element - and "make it an overlay"
		$("#flashContainer").overlay({
		
			// custom top position

			mask: {
		
				color: '#fff',
				
				opacity:1,
				
				// load mask a little faster
				loadSpeed: 0,
				
				closeSpeed:	2000,
		
				// very transparent
				
				zIndex : 9999
			},
		
			// disable this for modal dialog-type of overlays
			closeOnClick: false,
		
			// load it immediately after the construction
			load: true
		
		});

		flashembed("#flashContainer", {src: "_lib/swf/flashintro.swf",version: [6, 20], 
					onFail: function() {
						closeFlashConater ();
					} 																		
		});
		

		
	}//end of else
	
	/*Rezie functions*/
	$(window).resize(function() {
				
				var $windowHeight = $(window).height();
				$windowHeight = $windowHeight - (49 + 35);
				

				if($windowHeight < 500)
					$windowHeight = 500;
				$("#container").height($windowHeight);
			
	
	
	});


	$("#logo").click(function()
	{
		window.location = 'index.php'
	});
	
		
	var triggers = $(".dialogtigger").overlay({

		// some mask tweaks suitable for modal dialogs
		mask: {
			color: '#ccc',
			loadSpeed: 200,
			opacity: 0.8
		},
	
		closeOnClick: true
	});


	//Sending to cake
	$("#sendemailinfo").click(function(){				   
			
			
			var email = $("#email").val(); 
	
			var emailok = validate(email);
			
			
		   	if(emailok==true){
				
				
			$.ajax({
					type: 'GET',
					url: "include/to-cake-mail.php",
					data: {email: email},
					success: function(response) { /*alert(response)*/ },
					error: function(xhr, type, exception) { /*alert("Error: " + type);*/ }
				})
				   
				
				$(this).hide();
				$("#msg").empty();
				$("#msg").append("Thank you. You are now register to Youssef Merzouki mailing list.");
				$("#email").hide();
				
				return false;
				//triggers.overlay().close();
			}
			
			if(emailok==false){
				$("#msg").empty();
				$("#msg").append("Error - Invalid Email Address");
			}
			

	});


	var newsletterLogin = $("#newsletterLogin").click(function() {
		
		$("#sendemailinfo").show();
		
		$("#msg").empty();
		$("#msg").append("Enter your email below to register to the Youssef Merzouki mailing list.");
		
		$("#email").val("");
		$("#email").show();
	
		
	});

	
	
	
	

}); // end of ready() function
