// JavaScript Document



$(document).ready(function() {
	//init tablesorter
	$("table.tablesorter").tablesorter({ widgets: ['zebra']}); 

	//menu attivitą e destinazioni
	$('#menu_destinazioni').hide();
	$('#menu_attivita').hide();

	$('#destinazioni_li').click(function() {
		$('#menu_destinazioni').slideToggle(400);
		$('#menu_attivita').hide();
		$("#roll_attivita").removeClass('roll_up').addClass('roll_down'); 
		$("#roll_destinazioni").toggleClass('roll_down').toggleClass('roll_up'); 
		return false;
	});
	$('#attivita_li').click(function() {
		$('#menu_attivita').slideToggle(400);
		$('#menu_destinazioni').hide();
		$("#roll_destinazioni").removeClass('roll_up').addClass('roll_down'); 
		$("#roll_attivita").toggleClass('roll_down').toggleClass('roll_up'); 
		return false;
	});
	
	//homepage gallery
	var rotateDelay = 7000; 
	var rotateTabs = true;
	
 
	var $tabItems = $('ul.homepage_gallery_tabs li a').click (function(){ 
																			
	clearTimeout(timer);
	doRotateTabs(); 
	$('ul.homepage_gallery_tabs li').removeClass('hover');
	$(this).parent().parent().addClass('hover'); 
	});
	
	var tabs = $("ul.homepage_gallery_tabs").tabs('.homepage_gallery_divs > div', {effect:'fade',fadeInSpeed: 500,api:true}); 
	function doRotateTabs(){ 
			timer = setTimeout(function(){ 
			$('ul.homepage_gallery_tabs li').removeClass('hover');
			if(tabs.getIndex() == $tabItems.length-1){  
				tabs.click(0);
			} else { 
				tabs.next(); 
			}
			$('ul.homepage_gallery_tabs li h5 a.current').parent().parent().addClass('hover');
			doRotateTabs(); 
			}, rotateDelay); 
	}
	doRotateTabs();  
	//
	 
	//ACCORDION BUTTON ACTION	
	$('ul.accordion li').click(function() {
		$('ul.element').slideUp('normal');
		$(this).find('ul.element').slideDown('normal');
		$('ul.accordion li').removeClass('page_left_il_down').addClass('page_left_il'); 
		$(this).toggleClass('page_left_il').toggleClass('page_left_il_down'); 
	});
 
	//HIDE THE DIVS ON PAGE LOAD	
	$("ul.element").hide();
	
	// paginazione 
	$("table.paging tbody").quickPager({
		pageSize: 4,
		currentPage: 1,
		pagerLocation:"both"
	});
	
	//stili form
	$("select, input:checkbox, input:radio").uniform();
	
	//tasto back to top
	$(".backtotop").click(function(event){
		event.preventDefault();
		$('html, body').animate({scrollTop:0}, 400);
	});
	
	$('.scrollPage').click(function(event) {
	event.preventDefault();
	var elementClicked = $(this).attr("href");
	var destination = $(elementClicked).offset().top;
	$('html, body').animate({ scrollTop: destination}, 400 );
	return false;
	});
	
	//combobox
	$("#macro_destinazione").jCombo("/includes/combobox/getMacroDestinazione.php", {
		initial_text: "Tutte le destinazioni"
	});
	$("#destinazione").jCombo("/includes/combobox/getDestinazione.php?id=", { 
		initial_text: "Tutte le destinazioni",
		selected_value: "null", 
		parent: "#macro_destinazione"
	});		
	
	
	
});


// verifica e azioni form
function fillfield(element) {
if (element.id == 'search_term') {
	if(element.value == '') {document.getElementById(element.id).value = 'Cerca...';}
}
if (element.id == 'nome') {
	if(element.value == '') {document.getElementById(element.id).value = 'nome';}
}
if (element.id == 'cognome') {
	if(element.value == '') {document.getElementById(element.id).value = 'cognome';}
}
if (element.id == 'mail') {
	if(element.value == '') {document.getElementById(element.id).value = 'mail';}
}
if (element.id == 'nick') {
	if(element.value == '') {document.getElementById(element.id).value = 'nick';}
}
if (element.id == 'note') {
	if(element.value == '') {document.getElementById(element.id).value = 'note';}
}
if (element.id == 'indirizzo') {
	if(element.value == '') {document.getElementById(element.id).value = 'indirizzo';}
}
if (element.id == 'paese') {
	if(element.value == '') {document.getElementById(element.id).value = 'paese';}
}
if (element.id == 'telefono') {
	if(element.value == '') {document.getElementById(element.id).value = 'telefono';}
}
if (element.id == 'messaggio') {
	if(element.value == '') {document.getElementById(element.id).value = 'messaggio';}
}
if (element.id == 'commento') {
	if(element.value == '') {document.getElementById(element.id).value = 'commento';}
}
}
function emptyfield(element) {
if (element.id == 'search_term') {
	if(element.value == 'Cerca...') {document.getElementById(element.id).value = '';}
}
if (element.id == 'nome') {
	if(element.value == 'nome') {document.getElementById(element.id).value = '';}
}
if (element.id == 'cognome') {
	if(element.value == 'cognome') {document.getElementById(element.id).value = '';}
}
if (element.id == 'mail') {
	if(element.value == 'mail') {document.getElementById(element.id).value = '';}
}
if (element.id == 'nick') {
	if(element.value == 'nick') {document.getElementById(element.id).value = '';}
}
if (element.id == 'note') {
	if(element.value == 'note') {document.getElementById(element.id).value = '';}
}
if (element.id == 'indirizzo') {
	if(element.value == 'indirizzo') {document.getElementById(element.id).value = '';}
}
if (element.id == 'paese') {
	if(element.value == 'paese') {document.getElementById(element.id).value = '';}
}
if (element.id == 'telefono') {
	if(element.value == 'telefono') {document.getElementById(element.id).value = '';}
}
if (element.id == 'messaggio') {
	if(element.value == 'messaggio') {document.getElementById(element.id).value = '';}
}
if (element.id == 'commento') {
	if(element.value == 'commento') {document.getElementById(element.id).value = '';}
}
}
// formatta i numeri con il punto 
function format(numero) {
var regexp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
var formattato = numero+'';
while(regexp.test(formattato)) {
formattato = formattato.replace(regexp, '$1.$2');
}
return formattato;
}
