/**
 * @author Fabio Terlizzi
 * 
 * Codice che di base utilizza strumenti della libreria 
 * Jquery UI - http://jqueryui.com/
 */

//JQUERY CODE
			// execute your scripts when the DOM is ready. this is a good habit 
			$(document).ready(function() {
			  
		    /**
        * Override buttons and submit and render as jQuery-UI buttons
        *
        */			  
		    $( "button, input:submit").button();
		    
        /**
        * Applica un testo interno ad un campo input, valido come etichetta
        *
        * @depends libreria jquery.infieldlabel.js
        * @param { String } fadeOpacity
        */
        //$("label").inFieldLabels({ fadeOpacity: 0.3, labelClass:'tk_infield' });
        
        /**
        * Applica un testo placeholderinterno ad un campo input o textarea (valido come etichetta)
        * se il browser supporta HTML5 questo plugin non interviene e viene letto l'attributo 
        * "placeholder" del tag di input.
        * https://github.com/mathiasbynens/Placeholder-jQuery-Plugin
        *
        */
        $('input, textarea').placeholder();
  			 			  
        /**
        * Create DialogBox by ID (uesd for the alert() function override)
        *
        * @param { String } elementID
        */        
        $.extend({
          getOrCreateDialog: function(id) {           
            $box = $('#' + id);
            if (!$box.length) {
              $box = $('<div id="' + id + '"><p></p></div>').hide().appendTo('body');
            }
            return $box;
          }
        });        
	  	  	  	  
      /**
      * Selettore data basato su JQuery-UI
      *
      */        
      $.datepicker.setDefaults($.datepicker.regional["it"]);
      $('.date').datepicker({
        minDate: new Date(2011, 1 - 1, 1),               
        autoSize: true,
        showOn: "both",
        showAnim: 'drop',
        buttonImage: "images/calendar16.png",
        buttonText: "Calendario",
        buttonImageOnly: true
      });
        
        
/*        
        // bottone
        $('#bottone').button().click(function(){
          $('#dialog').dialog('open');
          return false;  
        });
*/
/*
        // dialog window
        $( "#dialog" ).dialog({
             autoOpen: false,
             closeText: 'chiudi',
             buttons: {
                "Ok": function() { $(this).dialog("close"); }, 
                "Annulla": function() { $(this).dialog("close"); }
             },
             modal: true,
             title: 'Titolo finestra',
             show: 'fade',
             hide: 'fade' 
        });
        
*/      
        
        
        //$("#miaform").validator();
       
        /*
        // autocompletamento
        var listaVocaboli = [
            "ActionScript",
            "Ajax",
            "AppleScript",
            "Asp",
            "BASIC",
            "C",
            "C++",
            "Clojure",
            "COBOL",
            "ColdFusion",
            "Erlang",
            "Fortran",
            "Groovy",
            "Haskell",
            "Java",
            "JavaScript",
            "Jquery",
            "Lisp",
            "Perl",
            "PHP",
            "Python",
            "Ruby",
            "Scala",
            "Scheme",
            "Tekmar"
          ];
          $("#parole").autocomplete({
            source: listaVocaboli
          });
          */

                  											
			});	// fine JQUERY CODE on document ready
			
			
 /**
 * Override javascript alert() and wrap it into a jQuery-UI Dialog box
 * (questa funzione va al di fuori del controllo sul DOM caricato)
 * http://snipplr.com/view/39648/alert-to-jquery-ui-dialog/
 *
 * @depends $.getOrCreateDialog
 *
 * @param { String } the alert message
 * @param { Object } jQuery Dialog box options
 */
function alert(message, options) {
 
  var defaults = {
    modal   : true,
    resizable : true,
    buttons   : {
      Ok: function() {
        $(this).dialog('close');
      }
    },
    show    : 'fade',
    hide    : 'fade',
    height : 'auto',
    dialogClass : 'modal-shadow'
  }
 
  $alert = $.getOrCreateDialog('alert');  
  // set message
  $("p", $alert).html(message);
  // init dialog
  $alert.dialog($.extend({}, defaults, options));
}
 


