$(document).ready(function(){
	//join the mailing list box slide effect 

	$('#sendmail button').click(function() {
	
		$('#sendmail form').slideToggle('fast');
		
	});	
	
	//$("#email").keypress(Sendmail);
	
	//$("#email").keypress(function() {
	//	$('#sendmail form').slideToggle('fast');	
	//});
	
	$("#submit").click(Sendmail)
					
	function Sendmail() {
		
			
		if ($('submitted').value) {
		    alert('You already joined the list');
		}		
		
		
		var hasError = false;			
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		//validate
		var emailFrom = $("#email").val();
		
		//is email is empty string
		if (emailFrom == ""){
			//$("#submit").after('<em class="error bordo">please enter an email address first</em>');
			//hasError = true;
			alert('please enter an email address first');
			return false;
		}                                    			
		
		// is email is invalid
		else if (!emailReg.test(emailFrom)) {
			//$("#submit").after('<em class="error bordo">please enter a valid email address</em>');
			alert('please enter a valid email address');
			return false;
			//hasError = true;				
		}		
		
		if (!hasError) {		
					  			
			$.ajax({
			    type: "POST",
			    url: "sendmail.aspx",
			    data: "email=" + emailFrom,
//			       success: function(result) {                                                                   
//                  alert("success " + result)
//                },

//                error: function(data) {                                 
//                  alert("error" + result)
//                }

			    success: function(data, textStatus) {		      			      			        
			        $("#visible").html("Thank you for joinning the list.").css({color: "#6699cc", cursor: "pointer"}).attr({disabled: "disabled"});
			    },
			    error: function() {
			        $("#visible").html("Could not send you email. Please try again.").css({color: "red"});
			        $('#sendmail form').slideToggle('fast');			        
			    }			  		    
			});		
		    }
		    return false;			
		}
		
		
		 $("#visible").ajaxStart(function(){
            $(this).html("Sending...").css({color: "#ff3399"});
         });
         
//            
        if ($.jqURL.url().indexOf("default.aspx") > -1 || $.jqURL.url().indexOf(".aspx") == -1) {
                 //alert(CurrentCollectionAlbumID);
                setActiveLink("Code="+CurrentCollectionAlbumID);
        }
        
        else {
            if ($.getURLParam("identity") == "publications")
            {
                setActiveLink($.getURLParam("AlbumName", $(".window dt a").attr('href')));
            }        
        }         
            
         // check if you've got a submenu: publications or collections
         // on publication: to find out which is the current album:
         
         //  var currentAlbumID = $.getURLParam("AlbumID", $(".window dt a").attr('href'));
                    
           //alert($("#sub_main li a[@href*='AlbumID=" + currentAlbumID + "']").html);
         				

})


//function setActiveLink(currentAlbumID(str)) {

//          $("#sub_main li a").each(function() {
//                if (this.href.indexOf(str) > -1 )
//                {
//                    $(this).css({"color":"#ffffff", "background-color":"#000000"});
//                }
//           });
// 
//}

 function setActiveLink(string2compre) {
         $("#sub_main li a").each(function() {
               if (this.href.indexOf(string2compre) > -1 )
               {
                   $(this).css({"color":"#ffffff", "background-color":"#000000"});
               }
          });

}
 



