// JavaScript Document
$(document).ready(function(){ 
        /*$("ul.sf-menu").supersubs({ 
            minWidth:    6,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  0.5     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. */
			$("ul.sf-menu").superfish({
									 autoArrows:  false 
									  });	 
			
	$("#adduserfile").click(function(){
		$("#userfile").append("<input class='formelement' name='userfile[]' type='file'/><br />");
	});
	
	
}); 

function toggleP(me,target) {
	$("#"+me).hide();	
	$("#"+target).fadeIn("slow");	
}
$(function() {
	$('.pics').cycle({
		fx: 'fade',
		timeout: 3000,	
		delay:  0, 
		speed:  1500
	});
}); 
function toggle(div,mode){
	//var d = '#'+div;
	//var cs = $('#'+div).css("display");
	if(mode == 'hide'){
		$('#'+div).hide('slow');
	}else {
		$('#'+div).show('slow');
	}
}

function subscribe(){
	
	var ok = "";
	var email = $("#subscribe_email").val();
	var name = $("#subscribe_name").val();
	//var sname = $("#subscribe_sname").val();
	var source = $("#subscribe_source").val();
	var pid = $("#subscribe_pid").val();
	ok += email == "" ? "<li>Email address</li>" : "";
	ok += email != "" && !isEmail2(email) ? "<li>Check email format</li>" : "";
	ok += name == "" ? "<li>Name</li>" : "";
	//ok += sname == "" ? "<li>surname</li>" : "";
	
	if(ok.length == 0){
		$.ajax({
			method: "get",url: "subscribe.php",data: "email="+escape(email)+"&name="+escape(name)+"&source="+escape(source)+"&pid="+escape(pid),
			success: function(html){ //so, if data is retrieved, store it in html
				$("#keepintouch").html("Thank you for subscribing"); //show the html inside .content div
				return false;
			 }
		 }); //close $.ajax(
	} else {
		$("#sub_warning").html("Please complete your<ul>"+ok+"</ul>");
		$("#sub_warning").show("slow");
	}
	return false;
 } 
 
 function isEmail2(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}
