$(document).ready(function () {
     
    $('#nav li').hover(
        function () {
            //show its submenu
           // $('ul', this).slideDown(100);
			 $('ul', this).show(100);
        },
        function () {
            //hide its submenu
            //$('ul', this).slideUp(100);     
			$('ul', this).hide(100);   
        }
    );
     

  $('#nav ul').hover(   //hovering anywhere in the submenu

//this works but code below is better

	 function (){
//		 $(this).css("visibility","hidden");

		$('#myid').removeClass('resources');
		$('#myid').addClass('test');
	},
        function () {
            $('#myid').removeClass('test');
		$('#myid').addClass('resources'); 
        }
);





$('.box').mouseover(function() { //when mouse over the box div change the border
 $(this).removeClass("box").addClass("boxhighlight");
});


$('.box').mouseleave(function() { //when mouse leaves set it back again
 $(this).removeClass("boxhighlight").addClass("box");
 });



/*
 $('#nav ul ').hover(   //hovering over the submenu
	function (){
	 $('#myid').css("background-position","-289px -150px");
	},
        function () {
		$('#myid').css("background-position","-289px -100px");
	}
	);
*/

$("#twitter").getTwitter({
		userName: "fodip",
		numTweets: 6,
		loaderText: "Loading tweets...",
		slideIn: true,
	//	showHeading: true,
		showHeading: false,
		headingText: "FODIP on Twitter",
		showProfileLink: true
	});


}); //doc ready

//mailing list
$(document).ready(function() { //error message already hidden by validate.js - no not any more

 $('.error').hide(); //hide error messages in contact form and mailing list form


$('#mailinglistsubmit').click(function() { 

for (var i=0; i < document.ajaxradioform.myradio.length; i++)
   {
   if (document.ajaxradioform.myradio[i].checked)
      {
      var radiovalue = document.ajaxradioform.myradio[i].value; //gets radiovalue (either 'subscribe' or 'unsubscribe')
      }
   }


var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var mailinglistemail = $("#mailinglistemail").val();  
if ((!mailinglistemail) || (!mailinglistemail.match(emailExp))){//if no email or invalid return false
$("#mailinglist_error").fadeIn(500);  
return false;
}


document.getElementById('mailinglistsubmit').disabled=true; //disable the button
var t=setTimeout("document.getElementById('mailinglistsubmit').disabled=false", 5000);// re-enable the button after 5 seconds


var dataString = 'mailinglistemail='+ mailinglistemail + '&radiovalue=' + radiovalue;
$.ajax({
		type: "POST",
		url: "processmailinglist.php", 
		data: dataString,
		cache: false,
		success: function(html){

$("#mailinglist_error").fadeOut(500);  
$("#mailinglistmessage").fadeIn(1000);

$("#mailinglistmessage").append(html);// the placement
$("#themessage").fadeIn("slow");// comes from the php

$('#mailinglistemail').focus(function() {//if you focus on the field the message fades out, as does any errors
$("#mailinglistmessage").fadeOut(1000);
$('#mailinglistmessage').empty(); //empty the div so you dont get messages  on top of one another
});




}//html function
});//ajax
return false;
});//click function
});//doc ready

//end mailing list//

//for contact form//
$(document).ready(function() { 
$('#successmessage').hide(); //hide success message


$('.text-input').focus(function() {//when focus on a field change the class to focus
$(this).removeClass('text-input').addClass('focus');
});

$('.text-input').blur(function() {//when moving away change the class back
 $(this).removeClass('focus').addClass('text-input');
});


//$("#message").val("Your message"); //set text area prompt
//  $("#message").val(""); //clear field//clear comment prompt on focus, have done this in the html with //onFocus="this.value=''; this.onfocus=null;"
//$('#message').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
//  $("#message").val(""); //clear field
//});

//$("#name").val("Your name"); //set input area prompt
//$('#name').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
//  $("#name").val(""); //clear field
//});

//$("#email").val("Your email"); //set input area prompt
//$('#email').focus(function() {//clear comment prompt on focus- this is the same as //onFocus="this.value=''; this.onfocus=null;"
//  $("#email").val(""); //clear field
//});

$('#submit').click(function() {
var name = $("#name").val();  //variables from the contact form
	var email = $("#email").val();  
	var message = $("#message").val();  
	var spam = $("#spam").val();  
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	
            if ((name == "") || (name == "Your name")) {  
			$("#name_error").fadeIn(500);  
			$("#name").focus();  
			 return false;  
			}  
/*
			 if ((email == "") || (email == "Your email")) {  
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}
	*/

			if (!email.match(emailExp)){		//if email is not valid
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}  	

			 if ((message == "") || (message == "Your message")) {  
			$("#message_error").fadeIn(500);  
			$("#message").focus();  
			 return false;  
			} 
			if (spam !="FODIP"){
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}


		
	/*		if ((spam !="fodip") && (spam !="FODIP")){  // AND needed here if you want 2 negative conditions		
			$("#spam_error").fadeIn(500);  
			$("#spam").focus();  
			 return false;  
			}*/  
					

document.getElementById('submit').disabled=true; //disable the button
var t=setTimeout("document.getElementById('submit').disabled=false", 5000);// re-enable the button after 5 seconds			


var dataString = 'name='+ name +'&email='+ email + '&message='+ message;
$.ajax({
		type: "POST",
		url: "processmail.php", 
		data: dataString,
		cache: false,
		success: function(html){

//$('#seeall').replaceWith(html);

$('#successmessage').fadeIn(1000);

$('.text-input').focus(function() { //if you focus on a field again the success message goes as do the errors
$("#successmessage").fadeOut(1000);
$('.error').hide();
});

//$("#placement").append(html);// is the placement
//$("#fromphp").fadeIn("slow");// comes from the php //have to hide it first for fade to work!!
//$('#newcomment').fadeOut(2000);
//$('#newcomment').empty(); //empty the div other wise any new comments are seen again

		}//html function
});//ajax
return false;

});//click function
});//doc ready

//end contact form//


