$(document).ready(function(){

// ========================================================================================== 
// ! ANCHOR SCROLL FUNCTION -----------------------------------------------------------------   
// ========================================================================================== 

	$.localScroll(2500,{easing:'elasout'});


// ============================== 
// ! Search Form value switcher   
// ============================== 

	$('#s').attr({ value: 'Search' }).focus(function(){
            if($(this).val()=="Search"){
               $(this).val("");
            }
       });
	$('#s').blur(function(){
		if($(this).val()==""){
        	$(this).val("Search");
        }
	});
	
// ============================== 
// ! Search Form value switcher   
// ============================== 

	$('#comment').attr({ value: 'Type Your Comments Here.' }).focus(function(){
            if($(this).val()=="Type Your Comments Here."){
               $(this).val("");
            }
       });
	$('#comment').blur(function(){
		if($(this).val()==""){
        	$(this).val("Type Your Comments Here.");
        }
	});
	

// ============================== 
// ! Comment Form value switcher   
// ============================== 

	$('#author').attr({ value: 'Name (required)' }).focus(function(){
            if($(this).val()=="Name (required)"){
               $(this).val("");
            }
       });
	$('#author').blur(function(){
		if($(this).val()==""){
        	$(this).val("Name (required)");
        }
	});
	
	
	/* email */
	
	$('#email').attr({ value: 'Email (will not be published) (required)' }).focus(function(){
            if($(this).val()=="Email (will not be published) (required)"){
               $(this).val("");
            }
       });
	$('#email').blur(function(){
		if($(this).val()==""){
        	$(this).val("Email (will not be published) (required)");
        }
	});
	
	/* URL */
	
	$('#url').attr({ value: 'Website' }).focus(function(){
            if($(this).val()=="Website"){
               $(this).val("");
            }
       });
	$('#url').blur(function(){
		if($(this).val()==""){
        	$(this).val("Website");
        }
	});
	
	
	


// ==================================================== 
// ! Show/Hide sidebar quick subscription signup form   
// ==================================================== 
		
	$('#newsletter_link').click(function(){
		if ($('#quick_subscribe_form').is(":hidden")) {
        $('#quick_subscribe_form').slideDown("fast");
      } else {
        $('#quick_subscribe_form').slideUp("fast");
      }
	return false;
	});
	
	
// ================================= 
// ! Show/Hide email a friend form   
// ================================= 
	$('#mail_friend_form_wrap').hide();
	
	$('#mail_friend_button').click(function(){
		if ($('#mail_friend_form_wrap').is(":hidden")) {
        $('#mail_friend_form_wrap').slideDown("fast");
      } else {
        $('#mail_friend_form_wrap').slideUp("fast");
      }
	return false;
	});
	



// =======================================
// ! Email A Friend Form value switcher   
// =======================================

	$('#mail_friend_form input[type="text"]').focus(function(){
            if( ($(this).val()=="Enter Your Name") || ($(this).val()=="Enter Your Email") || ($(this).val()=="Enter Your Friend's Name") || ($(this).val()=="Enter Your Friend's Email") ) {
               $(this).val("");
            }
       });
	$('#yourName').blur(function(){
		if($('#yourName').val()==""){
			$('#yourName').val("");
        	$('#yourName').val("Enter Your Name");
        }
	});
	$('#yourEmail').blur(function(){
		if($('#yourEmail').val()==""){
        	$('#yourEmail').val("Enter Your Email");
        }
	});
	$('#friendsName').blur(function(){
		if($('#friendsName').val()==""){
        	$('#friendsName').val("Enter Your Friend's Name");
        }
	});
	$('#friendsEmail').blur(function(){
		if($('#friendsEmail').val()==""){
        	$('#friendsEmail').val("Enter Your Friend's Email");
        }
	});
	
	
	
	
// =================================== 
// ! Process the Email A Friend Form   
// =================================== 

$('#submitFriendMail').click(function(){

	//capture data
	var action = "process_form";
	var yourURL = $('#yourURL').val();
	var yourName = $('#yourName').val();
	var yourEmail = $('#yourEmail').val();
	var friendsName = $('#friendsName').val();
	var friendsEmail = $('#friendsEmail').val();
	
	if((yourName=="")||(yourName=="Enter Your Name")){
		var formError = true;
		$('#yourName').css("background-color","#FFCCCC");
	}
	else{
		$('#yourName').css("background-color","#ECEDEF");
	}
	if((yourEmail=="")||(yourEmail=="Enter Your Email")){
		var formError = true;
		$('#yourEmail').css("background-color","#FFCCCC");
	}
	else{
		$('#yourEmail').css("background-color","#ECEDEF");
	}
	if((friendsName=="")||(friendsName=="Enter Your Friend's Name")){
		var formError = true;
		$('#friendsName').css("background-color","#FFCCCC");
	}
	else{
		$('#friendsName').css("background-color","#ECEDEF");
	}
	if((friendsEmail=="")||(friendsEmail=="Enter Your Friend's Email")){
		var formError = true;
		$('#friendsEmail').css("background-color","#FFCCCC");
	}
	else{
		$('#friendsEmail').css("background-color","#ECEDEF");
	}
	
	
	
	if(formError == true){
		alert("Form Elements Missing!");
		return false;
	}
	
	else{

	//organize the data properly
	var data = 'yourName=' + yourName + '&yourEmail=' + yourEmail + '&friendsName=' + friendsName + '&friendsEmail=' + friendsEmail + '&yourURL=' + yourURL + '&action=' + action;
	
	//disabled all the text fields
	$('#mail_friend_form').animate({opacity:"0.25"},500, function(){
	$('#yourName').attr("disabled","disabled");
	$('#yourEmail').attr("disabled","disabled");
	$('#friendsName').attr("disabled","disabled");
	$('#friendsEmail').attr("disabled","disabled");
	$('#submitFriendMail').attr("disabled","disabled");
	
	
		//start the ajax
		$.ajax({
					
			url: "http://devel.sbwmedianetwork.com/caresource/wordpress/wp-content/themes/caresource/email_a_friend_script.php",	
		
			type: "POST",

			data: data,		
		
			cache: false,
		
			success: function (html) {
				
				if(html=="fail"){
					
					$('#mail_friend_form').animate({opacity:"1"},500);
					
					$('#yourName').attr("disabled","false");
					$('#yourEmail').attr("disabled","false");
					$('#friendsName').attr("disabled","false");
					$('#friendsEmail').attr("disabled","false");
					$('#submitFriendMail').attr("disabled","false");
					
					$('#yourName').css("background-color","#FFCCCC");
					$('#yourEmail').css("background-color","#FFCCCC");
					$('#friendsName').css("background-color","#FFCCCC");
					$('#friendsEmail').css("background-color","#FFCCCC");
					
					$('#mail_friend_note').html("Server has failed to process. Please try again");
					$('#mail_friend_note').animate({opacity:"0"},10);
					$('#mail_friend_note').animate({opacity:"1"},500, function (){
						$('#mail_friend_note').animate({opacity:".99"},3000, function(){
							$('#mail_friend_note').fadeOut("fast");
						});
					});
					return false;
					
				}
				else if(html=="success"){
					
					$('#mail_friend_form').animate({opacity:"1"},500);
					
					$('#yourName').removeAttr("disabled");
					$('#yourEmail').removeAttr("disabled");
					$('#friendsName').removeAttr("disabled");
					$('#friendsEmail').removeAttr("disabled");
					$('#submitFriendMail').removeAttr("disabled");
					
					$('#yourName').val("Enter Your Name");
					$('#yourEmail').val("Enter Your Email");
					$('#friendsName').val("Enter Your Friend's Name");
					$('#friendsEmail').val("Enter Your Friend's Email");
					
					$('#mail_friend_form_wrap').slideUp("fast");
					
					$('#mail_friend_note').html("Thank you for sending a note to your friend!");
					$('#mail_friend_note').slideDown("fast");
					$('#mail_friend_note').animate({opacity:"1"},5000, function (){
						$('#mail_friend_note').slideUp("slow");
					});
					return false;
					
				}
				else{
					alert(html);
				} 
				
			}		
		});
		
	});

return false;
	}
});    
	
	
	
// ================================================================== 
// ! AUTHOR TOOLTIPS ==============================================   
// ================================================================== 

$('.author_roll').mouseover(function(){
	
	var tipID = "#"+$(this).attr("alt");
        $(tipID).fadeIn("fast");
	return false;

});
$('.author_roll').mouseout(function(){
	
	var tipID = "#"+$(this).attr("alt");
        $(tipID).fadeOut("fast");
	return false;

});

$('.author_2_roll').mouseover(function(){
	
	var tipID = "#"+$(this).attr("alt");
        $(tipID).fadeIn("fast");
	return false;

});
$('.author_2_roll').mouseout(function(){
	
	var tipID = "#"+$(this).attr("alt");
        $(tipID).fadeOut("fast");
	return false;

});
	
	
	
	
});