jQuery(document).ready(function(){

	// accordion-like table
	$('.accordion .head').click(function() {
		$(this).next().toggle();
		$(this).toggleClass('active');
		$(this).find('.first').toggleClass('ui-corner-bl');
		$(this).find('.last').toggleClass('ui-corner-br');
		$(this).find('.icon span.ui-icon').toggleClass('ui-icon-triangle-1-s').toggleClass('ui-icon-triangle-1-e');
		return false;
	}).next().hide();

	// tabs
	$( ".tabs" ).tabs({
		ajaxOptions: {
			error: function( xhr, status, index, anchor ) {
				$( anchor.hash ).html(
					"Errore di connessione" );
				}
		}
	});

	// datepickers
	var periodFromOptions = {
		showOn: 'button',
		buttonImage: base_url + '/public/styles/images/ui-calendar.png',
		buttonImageOnly: true,
		buttonText: 'Calendario',
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy',
		showButtonPanel: true,
		monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic'],
		prevText: 'Mese precedente',
		nextText: 'Mese successivo',
		currentText: 'Oggi',
		closeText: 'Fatto'
	};
	$(".datepicker.from").each(function() {
		$(this).datepicker(periodFromOptions);
		var periodToOptions = periodFromOptions;
		var $myself = $(this);
		periodToOptions['beforeShow'] = function(input, inst) {
			return {
				minDate: $myself.datepicker('getDate'),
				maxDate: null
			};
		};
		$("input[rel='" + $(this).attr('id') + "'].datepicker.to").datepicker(periodToOptions);
	});

	// buttons
	$('input[type=submit]').addClass('ui-state-highlight').addClass('ui-corner-all');
	$('input[type=submit]').hover(function(){
		$(this).toggleClass('ui-state-highlight').toggleClass('ui-state-hover');
	})
});

