// JavaScript Document

// Clear form fields
$.fn.search = function() {
  return this.focus(function() {
    if( this.value == this.defaultValue ) {
      this.value = "";
      this.style.color = "#000000";
      this.style.background = "#ffffcc";
    }
  }).blur(function() {
		if( !this.value.length ) {
      this.value = this.defaultValue;
      this.style.color = "#9bbc26";
      this.style.background = "#ffffff";
		}
	});
};

// Anchor Slider by Cedric Dugas - http://www.position-absolute.com
jQuery.fn.anchorAnimate = function(settings) {
  settings = jQuery.extend({
    speed : 600 //1100
}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault();
			var locationHref = window.location.href;
			var elementClick = $(caller).attr("href");
			if( ( elementClick[0]!='#' ) && ( elementClick.indexOf('#') > 0 ) ) elementClick = elementClick.substr( elementClick.indexOf('#') );
      var destination = $(elementClick).offset().top;
      $("html:not(:animated),body:not(:animated)").animate({
        scrollTop: destination
      }, settings.speed, function() {
        window.location.hash = elementClick
      })
		  	return false;
		})
	})
}

// Inizializzazione
$(document).ready(function() {

	
	// Clear form fields
	$("#find, #markup, #sheet").search();
	$("#name, #oggetto, #email, #message, #nospam").search();

	// External Links
	$("a[rel='external']").attr('target', '_blank');

	// Anchor Slider by Cedric Dugas - http://www.position-absolute.com
	$("a[rel='slider']").anchorAnimate();
  
});
