/*	



	File: sitescript.js

	Stefano Giliberti - kompulsive@gmail.com clickswitch.net		

*/



$(document).ready(function(){

	/* Dropdown */

	$("#navigation li.top-parent").hover(function(){	/* On .top-parent class hover */

			$(this).stop().find("ul.ddown").slideDown(250); /* Finds a list with .ddown class and slide it down in 250ms */

		}, /* On mouse out */

		function(){

			$(this).stop().find("ul.ddown").slideUp(250); /* Finds a list with .ddown class and slide it up in 250ms */

		}

	);

	/* On click fade dropdown out */

	$("#navigation ul.ddown").click(function(){

		$(this).stop().fadeOut("slow");

	});

	

	/* Search box */

	$("input.input-search").val("Search something"); /* Sets "Search something" as default value */

	$("input.input-search").focus(function(){ /* On focus .. */

		inputDef=$(this).val() /* picks the -current- value */

		if(inputDef=='Search something'){ /* if the current value corrispond to the initial value (inputDef var) */

			$(this).val(''); /* empty the input */

			$(this).css('color','#5e5e5e');

		}

	});

	$("input.input-search").blur(function(){ /* on blur */

		inputDef=$(this).val();

		if(inputDef==''){ /* if the current value is null .. */

			$(this).css('color','#ababab');

			$(this).val('Search something'); /* Resets "Search something" as default value */

		}

	});



	/* Replace div#send-button with the submit button (alternative method to show it only on javascript-compatible browsers) */

	$("form#contact-form #send-button").html('<input type="submit" id="submitinput" class="input-go" value="Send it!" />');

	

	/* Contact form set-up */

	$("#contact-form").ajaxForm(function(data) {

		if (data == 1){ // If its all ok

			$("#contact-form").resetForm(); /* Resets the form */

			$("p#form-success").fadeIn("slow"); /* Fades in p#form-success */

			$("#contact-form #submitinput").fadeOut("fast") /* Removes the submit button */

		}

		else if (data==2){ // Server error

			$("p#form-info").text("Error! Try again please.").fadeIn(500).fadeIn(5000).fadeout("fast");

		}

		else if (data==3){ // Blank fields or invalid email

			$("p#form-info").text("Please fill correctly all necessary fields.").fadeIn(500).fadeIn(5000).fadeout("fast");

		}

	});

});

