/* 
 * $Date: 2009-07-24 11:23:24 +0200 (ven, 24 lug 2009) $
 * $Rev: 138 $
 */
  
/*
 * Copyright (c) 2008 Massimiliano Balestrieri
 * 
 * $Date:2008-10-28 17:04:42 +0100 (mar, 28 ott 2008) $
 * $Rev:251 $
 * @requires jQuery v1.2.6
 * 
 * Copyright (c) 2008 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 */
jQuery.noConflict();

////////////////////////////////////////////////////////////////////////////////
//*********** ACCORDION AUTOLOAD ***********************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    jQuery(".accordion").accordion({
        header: ".ui-accordion-header",
        clearStyle: true
    });
});

////////////////////////////////////////////////////////////////////////////////
//*********** TABS AUTOLOAD ****************************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    jQuery(".tabs").tabs();
});

////////////////////////////////////////////////////////////////////////////////
//*********** SLIDER AUTOLOAD **************************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    jQuery('.slider').slider();
    jQuery('.slider-range').slider({range: true});
});

//JQSISP da qui in poi
				
////////////////////////////////////////////////////////////////////////////////
//*********** DIALOG AUTOLOAD **********************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    jQuery('div.dialog').dialog({
        title : this.title
        //close : function(){
        //   jQuery(".ui-dialog").remove();
		//}
    });
	
	//CSS DIALOG:
	var _url = ' /ris/css/generaliV3/jquery/dialog_print.css';
	var _css = jQuery('<link type="text/css" href="'+_url+'" rel="stylesheet" media="print" id="dialog-print" />');
	//var _has_css = _css.length > 0;
	//var _print = jQuery('link[@media="print"][@rel="stylesheet"]');
	//console.log(_print);
	
    jQuery('a.dialog').click(function(){
       var _options = jQuery(this).metadata();
       _options.title = this.title;
	   
	   //CSS
	   //if(_has_css){
	       //_print.attr("rel","alternate stylesheet");
		   //_css.attr("rel","stylesheet");
	   //}
	   jQuery("head").append(_css);
	   
	   
       if(this.href.indexOf("#") !== -1 && !_options.target){
         _options.target = "#" + this.href.split("#")[1]; 
         _options.type = 'inline';
       }
       //console.log(_options);
       if(_options.target && _options.type == 'inline'){
           var _clone = jQuery(_options.target).clone();
           jQuery("body").append(_clone);
           _clone.dialog(_options).show();
       }else{
           if(_options.modal){
               _options.overlay = { opacity: 0.5,background: "black"  };
           }
           _options.close = function(){
		       //jQuery("#ahah").remove();
		       jQuery("#ahah").remove();
		       jQuery(".ui-dialog").remove();
		       jQuery("#mydialog-target").remove();
			   
		   	   //if(_has_css){
			   //    _print.attr("rel","stylesheet");
			   //   _css.attr("rel","alternate stylesheet");
			   //}
			   _css.remove();	
			   
		   };
           jQuery.ajax({
    			type: "GET",
      			url: this.href,
    			success : function(data){
    				var re = /<div id=\"dialog_target\">([\S\s]*)<!--\/dialog-target-->/;
    				var _d = data.match(re);
                    var _html = _d && _d[0] ? _d[0] : data;
                    //console.log(_d[0]);
    				jQuery("body").append('<div id="ahah" style="display:none"></div>');//+_d[0]+'
                    var _ahah = jQuery("#ahah").append(_html);
                    
                    _ahah
                    .dialog(_options)
                    .show();
                    
                    jQuery("span.stampa",_ahah).jbutton({text : 'stampa', callback : function (){window.print();} });
                    jQuery("span.chiudi",_ahah).jbutton({text : 'chiudi', callback : function (){_ahah.dialog("close");} });
                    
                    
    			}
            });
       }
       return false;
    });
});



////////////////////////////////////////////////////////////////////////////////
//*********** DATEPICKER IT ****************************************************
//Italian initialisation for the jQuery UI date picker plugin.
//Written by Apaella (apaella@gmail.com).
////////////////////////////////////////////////////////////////////////////////
jQuery(function($){
    $.datepicker.regional['it'] = {
        clearText: 'Svuota', clearStatus: 'Annulla',
        closeText: 'Chiudi', closeStatus: 'Chiudere senza modificare',
        prevText: '&#x3c;Prec', prevStatus: 'Mese precedente',
        prevBigText: '&#x3c;&#x3c;', prevBigStatus: 'Mostra l\'anno precedente',
        nextText: 'Succ&#x3e;', nextStatus: 'Mese successivo',
        nextBigText: '&#x3e;&#x3e;', nextBigStatus: 'Mostra l\'anno successivo',
        currentText: 'Oggi', currentStatus: 'Mese corrente',
        monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
        'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
        monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
        'Lug','Ago','Set','Ott','Nov','Dic'],
        monthStatus: 'Seleziona un altro mese', yearStatus: 'Seleziona un altro anno',
        weekHeader: 'Sm', weekStatus: 'Settimana dell\'anno',
        dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
        dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
        dayNamesMin: ['Do','Lu','Ma','Me','Gio','Ve','Sa'],
        dayStatus: 'Usa DD come primo giorno della settimana', dateStatus: 'Seleziona D, M d',
        dateFormat: 'dd/mm/yy', firstDay: 1, 
        initStatus: 'Scegliere una data', isRTL: false};
    $.datepicker.setDefaults($.datepicker.regional['it']);
});
			
////////////////////////////////////////////////////////////////////////////////
//*********** DATEPICKER AUTOLOAD **********************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    jQuery('div.calendario').datepicker(
        jQuery.extend({},jQuery.datepicker.regional["it"],{
            defaultDate : 0
        })
     );
	var _y = new Date();
	_y = _y.getFullYear();
    jQuery(':input.calendario').datepicker(
        jQuery.extend({},jQuery.datepicker.regional["it"],{
            yearRange: '1930:' + _y,
			showOn: "button", 
            buttonImage: '/ris/css/generaliV3/jquery/im/ico_calendario.gif',  
            buttonImageOnly: true
        })
    );
});

////////////////////////////////////////////////////////////////////////////////
//*********** THEME AUTOLOAD ***************************************************
////////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function(){
    var _class = jQuery("body").attr("class");
    //console.log(_class);
    if(_class && _class.indexOf("tema") !== -1){
        _class = _class.replace("tema-","");
        var _url_base = '/ris/css/generaliV3/jquery/temi/' + _class + '/jquery-ui-themeroller.css';
        //console.log(_url_base);
        jQuery('head').append('<link type="text/css" href="'+_url_base+'" rel="stylesheet" media="screen" />');    
    }
});				
