	
function isValidEmailAddress(emailAddress) 
{
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);	

		return pattern.test(emailAddress);
}
		
$(document).ready(function(){
	    
		$("#sharePop").dialog({
		  	autoOpen: false,
			bgiframe: true,
			modal: true,
			width:400,
		  	resizable: false,
	  		dragable: false
		});  				
			
		
		
		$("#sendLink").click(function(){	
			
		$.post('/shareLink/',$("#shareFrom").serialize(), 		
		function(data){ 		
		
		if(data == "yes")
		{
			$("#sendId").hide();
			$("#msg_box").html("Successfully Sent");			
			$("input#toMail").val("");
			$("input#fromMail").val("");
			$("textarea#commentShare").val("");						
			location.reload();
		}
		else
		{
			$("#msg_box").html(data);
		}
		
		});
		
		return false;
  		});
	
		//cache selector
		var images = $("#dragcontent img"),
		  //title = $("title").text() || document.title;
		title = "LuckyJets";
		
	    //make images draggable
	    images.draggable({
		  //create draggable helper
		  helper: function() {
		 return $("<div>").attr("id", "helper").html("<span>" + title + "</span><img id='thumb' src='" + $(this).attr("src") + "'>").appendTo("body");
		  },
		  cursor: "pointer",
		  cursorAt: { left: -10, top: 20 },
		  zIndex: 99999,
		  //show overlay and targets
		  start: function() {
		    $("<div>").attr("id", "overlay").css("opacity", 0.7).appendTo("body");
			$("#tip").remove();
			$(this).unbind("mouseenter");
			$("#targets").css("left", ($("body").width() / 2) - $("#targets").width() / 2).slideDown();
		  },
		  //remove targets and overlay
		  stop: function() {
		    $("#targets").slideUp();
			$(".share", "#targets").remove();
		    $("#overlay").remove();
			$(this).bind("mouseenter", createTip);
		  }
		});
		
		//make targets droppable
		$("#targets li").droppable({
		  tolerance: "pointer",
		  //show info when over target
		  over: function() {
		    $(".share", "#targets").remove();
		    $("<span>").addClass("share").text("Share on " + $(this).attr("id")).addClass("active").appendTo($(this)).fadeIn();
		  },
		  drop: function() {
		 
		    var id = $(this).attr("id"),
			  currentUrl = window.location.href,
			  baseUrl = $(this).find("a").attr("href");	
			   //alert($('#sharePop').dialog('open'));	
			if (id.indexOf("twitter") != -1) {
			  window.location.href = baseUrl + "/home?status=" + title + ": " + currentUrl;
			} else if (id.indexOf("delicious") != -1) {
			  window.location.href = baseUrl + "/save?url=" + currentUrl + "&title=" + title;
			} else if (id.indexOf("facebook") != -1) {
			  window.location.href = baseUrl + "/sharer.php?u=" + currentUrl + "&t=" + title;
			} else if (id.indexOf("email") != -1) {			 
			 //alert($('#sharePop').dialog('open'));
			 //$("#msg_box").html("<font size='2'>"+currentUrl+"</font>");
			 $("#myurl").val(currentUrl);
			 $('#sharePop').dialog('open');
			 //window.location.href = baseUrl + "/sendemail.php?u=" + currentUrl + "&t=" + title;
			}
		  }		  
		});
	  
	    var createTip = function(e) {
		  //create tool tip if it doesn't exist
		  ($("#tip").length === 0) ? $("<div>").html("<span>Drag this image to share the page<\/span><span class='arrow'><\/span>").attr("id", "tip").css({ left:e.pageX + 30, top:e.pageY - 16 }).appendTo("body").fadeIn(2000) : null;
		};
		
		images.bind("mouseenter", createTip);
		
		images.mousemove(function(e) {
		
		  //move tooltip
          $("#tip").css({ left:e.pageX + 30, top:e.pageY - 16 });
        });
	  
	    images.mouseleave(function() {
		
		  //remove tooltip
		  $("#tip").remove();
	    });
		
		
		
});
