$(document).ready(function() {
  
  $("input[type=text]").placeholder();

  /*
	$("#menu li").hover(
    function () {
      $(this).children(".dropdown").fadeIn(500);
    },
    function () {
      $(this).children(".dropdown").fadeOut(500);
    }
  );
  
  
  
	$('#btnTop a').click( function(event) {
    event.preventDefault();
    //var $top = $( $(this).attr('href') );
    
    $('html, body').animate({
      scrollTop: 0
    }, 500);
  });
*/

    

    $('.preview.load img').each(function(){
        var $img = $(this);
        var $parent = $img.parent();
        var src = $img.attr('src');

        if ($img[0].complete){
            $parent.removeClass('load');
            $img.show();
        }else{
            $img.load(function(){
                $parent.removeClass('load');
                $img.fadeIn('slow');
            }).attr('src', src);
        }
    });

    $('input[type=text], textarea').placeholder();
  
    $('#menuContattaci form, #maggioriInfoform form').live('submit', function( e ) {
        e.preventDefault();
        var form= $(this);
        var submit = form.find('button[type=submit]');
        
        submit.attr('disabled', 'disabled');
        submit.val('Invio in corso');
        
        $.post($(this).attr('rel'), $(this).serialize())
        .success(function( data ) { 
            submit.removeAttr('disabled');
            submit.val('Invia');
            alert(data.msg);
        })
        .error(function(){
            alert("Errore nell’invio del form");
        });
    });    
  
  		
});



;(function($) {
/**
 * Clear input and textarea placeholder values on focus in and replaces them on focus out if no edit was made
 *
 * @example jQuery("input").placeholder();
 *
 * @lastmod 2011-01-12 23.40
 *
 * @name placeholder
 * @type jQuery
 * @param Object	settings (not used yet)
 *								
 * @return jQuery
 * @author Dharma Ferrari (http://www.dharmaferrari.com)
 */
$.fn.placeholder = function(settings)
{  
	settings = $.extend({}, $.fn.placeholder.defaults, settings);
	
	return this.each(function() {
  	var $this = $(this);
    $this.addClass(settings.cssClass);
  	
    $this.data('old', $this.val());
	
    // On focus in
    $this.focusin(function() {
      if($this.data('old') == $this.val()) {
        $this.val('');
        $this.removeClass(settings.cssClass);
      }
    });
    
    // On focus out
    $this.focusout(function() {
      if('' == $this.val()) {
        $this.val($this.data('old'));
        $this.addClass(settings.cssClass);
      }
    });
    
  });
  
}

$.fn.placeholder.defaults = {
	cssClass : 'placeholder_in'
};

})(jQuery);

