$(document).ready(function(){
	
	// scroll to top from footer & make magic with the frog
	$(".top-link").click(function(){
		var frog_says = $("#frog-quotes p").text();
		$.scrollTo("#wrap", 1500 );
		$("#frog-quotes p").replaceWith("<p>Wow! Nice jump there, chief.</p>");
		setTimeout( "$('#frog-quotes p').fadeOut(2000);", 3000);
		setTimeout( function(){ $('#frog-quotes p').replaceWith('<p>'+frog_says+'</p>'); }, 5000);
		return false;
	});
	
	// open external links in ne window.
	$(".external").attr("target","_blank");
	
	// add first-child class to first paragraph of articles
	$(".article :nth-child(2)").addClass("first-child");
	
	// RSValidation for contact form 
	$("#contact-form").RSV({
		errorFieldClass: "error",
		errorTargetElementId: "error-message",
		displayType: "display-html",
		errorTextIntro: "<strong>Please fix the following errors.</strong>",
		rules: [
			"required,name,Please enter your <strong>name</strong>.",
			"required,email,Please enter your <strong>email address</strong>.",
			"valid_email,email,Please enter a <strong>valid email address</strong>.",
			"required,subject,Please enter a <strong>subject</strong>.",
			"required,message,Please enter a <strong>message</strong> to send."
		]
	});

	// clear out archive search
	$(":text").focus(function(){
		if($(this).val() == "Type Keywords"){
			var oldVal = $(this).val();
			$(this).blur(function(){
				if($(this).val() == "") { $(this).val(oldVal); }
			});
			$(this).val("");
		}
	});
	
	// archives search
	var qr_url = "/previous/archive-search/";
	
	$("#archive-search input.submit-btn").click(function(){
	
		var qr_input = $("#archive-search input.search-value").val();
		
		// fadeout the exisiting stuffs
		$("#archive-content div").fadeOut();
		
		// fake the preloader and hide the results
		setTimeout( function(){ $("#archive-loader").addClass("loading"); $("#archive-content").load(qr_url+escape(qr_input)+'/', function(){ $("#archive-content div").hide(); }); }, 1000);
		
		// remove the fake loader and show the results
		setTimeout( function(){ $("#archive-loader").removeClass("loading"); $("#archive-content div").fadeIn(); }, 3500);
		
		return false;
		
	});
	
});