// F1 front-end/back-end toggle
	if (document.all) {
		document.onhelp = function() {
			location.href = 'admin/';
			return false;
		}
	} else {
		document.onkeydown = function (evt) {
			if (evt.keyCode == '112') {
				location.href = 'admin/';
				return false;
			}
		}
	}

// mailup validazione email
function isEmail(strEmail) {
    validRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (strEmail.search(validRegExp) == -1) {
      alert('Inserire un indirizzo e-mail valido');
      return false;
    }
    return true;
}

// JQUERY
$(document).ready(function(){

	// SLIDESHOW HOME
	if ( $('#slideShow').length > 0 ){ // SE SONO IN HOME
		$('#slideShow').crossSlide({
		  fade: 1
		}, [
		  { src: '/images/slideshow/IMG_8792.jpg', from: 'bottom right', to: 'top left 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8803.jpg', from: 'top left', to: 'bottom right 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8812.jpg', from: 'bottom right', to: 'top left 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8860.jpg', from: 'top left', to: 'bottom right 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8757.jpg', from: 'bottom right', to: 'top left 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8763.jpg', from: 'bottom right', to: 'top left 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8765.jpg', from: 'top left', to: 'bottom right 1.3x', time: 3 },
		  { src: '/images/slideshow/IMG_8766.jpg', from: 'bottom right', to: 'top left 1.3x', time: 3 }
		]);
	};
	
	// SVUOTO IL CAMPO AL FOCUS per tutti quei campi di testo con attributo 'emptyIf'
	$(':text[emptyIf]')
		.focusin(function(){
			if ( $(this).val() == $(this).attr('emptyIf') ){
				$(this).val('');
			};
		})
		.focusout(function(){
			if ( $.trim($(this).val()) == '' ){
				$(this).val($(this).attr('emptyIf'));
			};
		})
	;


	// DROPDOWN
	// gestione delle aperture varie
	var hoverIntentConfig = {
		over:
			function(){
				$('.dropDownTrigger').removeClass('selected'); // spengo i pulsanti
				$('.dropDownWrapper')
					.stop(false,true) // interrompo eventuali altre animazioni non completate
					.hide() // nascondo tutti i wrapper
					.filter('[rel='+ $(this).attr("rel") +']') // trovo il corrispondente da aprire (che abbia lo stesso 'rel' del trigger) e...
						.slideDown('fast', function(){ // ... lo mostro
							$(this).find('.dropDownContent').fadeIn();
						});
				$(this).addClass('selected'); // ... accendo il relativo pulsante
			}
		, out: function(){}
		, interval: 30
	};
	$('.dropDownTrigger').hoverIntent(hoverIntentConfig);
	// chiudo tutto se clicco fuori e rimuovo il selected...
	$('body').click(function(){
		$('.dropDownWrapper').slideUp(function(){
			$('.dropDownContent').hide();
			$('.dropDownTrigger[class~=selected]').removeClass('selected');
		});
	});
	// ... e non se clicco nel contenuto di un dropdown
	$('[class*=dropDown]').click(function(event){ event.stopPropagation(); });
	
	// PULSANTE DI CHIUSURA (di tutti i dropdown)
	$('<div>')
		.css({
			position: 'absolute'
			, top: '15px'
			, right: '20px'
			, cursor: 'pointer'
			, width: '16px'
			, height: '16px'
			, background: 'url(/images/ui-icons_ed9f26_256x240.png) 0 -16px'
		})
		.click(function (){ 
			$(this).parent().slideUp(function(){
				$('.dropDownContent').hide();
				$('.dropDownTrigger[class~=selected]').removeClass('selected');
			});
		})
		.appendTo($('.dropDownWrapper'));
	

	// SCROLLABLE di default
	$('#marchi, #prodotti').scrollable();


	// FRECCETTA ACCANTO AI PULSANTI IN BARRANAV
	$('a.dropDownTrigger').prepend('<i></i>');
	

	// COLORBOX
	$('[class~=colorbox]').colorbox({ width: "80%", height: "80%" });
	// video youtube
	$('#videoGhostLink').colorbox({href:"http://www.youtube.com/v/6v09z3Bif-k&amp;hl=it_IT&amp;fs=1", iframe: true, innerWidth: 640, innerHeight: 385 });
	// CANTIERE
	$('#annuncioCantiere a').colorbox({ innerWidth: 800, innerHeight: 1131 });


	// ERRORI CON TOOLTIP NELLA FORM
	$('form#contatti span.error').prev().addClass('errorTrigger'); // aggiungo la classe al campo precedente l'errore
	$('.errorTrigger').tooltip({
		position: 'bottom center'
		, effect: 'slide'
		, direction: 'left'
		, relative: true
	});


});
