/* ********************************************************************************
						'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;
		}
	};
};



/* ********************************************************************************
					PRENDO VALORI DALLA QUERY STRING
******************************************************************************** */
function getParameterByName(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
};



/* ********************************************************************************
								RESET DEFAULT
		RIPOPOLO I CAMPI VUOTI CON IL VALORE DI DEFAULT (cancellato al submit)
******************************************************************************** */
function resetDefault(formId){
	if (!formId) formId = '';
	$(formId + ' [emptyIf]').each(function(){
		if ( $(this).val() == '' ){
			$(this).val($(this).attr('emptyIf'));
		}
	})
};



/* ********************************************************************************
									IS INTEGER
******************************************************************************** */
function isInteger(s){
	if ( s == null) return false;
	var i;
	for(i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if(((c < "0") || (c > "9"))) return false;
	}
	return true;
};



/* ********************************************************************************
***********************************************************************************
***********************************************************************************
								DOCUMENT READY
***********************************************************************************
***********************************************************************************
******************************************************************************** */
$(document).ready(function(){



	if($(".flashNotice").length == 1) { showNotice( $(".flashNotice").html(), "Informazione" ); };
	if($(".flashWarning").length == 1) { showWarning( $(".flashWarning").html(), "Attenzione" ); };
	if($(".flashError").length == 1) { showError( $(".flashError").html(), "Problema" ); };



	/* ********************************************************************************
									MB MENU - BARRANAV
	******************************************************************************** */
	$('#barraNav').buildMenu({
		menuSelector:".overlay"
		, menuWidth: 138
		, openOnRight:false
		, containment:'window'
		, iconPath:"ico/"
		, hasImages:false
		, fadeInTime:0
		, fadeOutTime:200
		, menuTop:0
		, menuLeft:0
		, submenuTop:0
		, submenuRight:10
		, opacity:1
		, shadow: false
		, shadowColor: "black"
		, shadowOpacity: 1
		, openOnClick:false
		, closeOnMouseOut: false
		, closeAfter:150
		, minZindex:"auto"
		, hoverIntent: 30
		, submenuHoverIntent: 30
	});
	
	/* ********************************************************************************
										SLIDESHOW
	******************************************************************************** */
	$('#slideHomePager').tabs('#slideHomeImages > a', {
		current: 'selected'
		, effect: 'fade'
		, rotate: true
	}).slideshow({
		autoplay: true
        , clickable: false
	});
		
	
	/* ********************************************************************************
										COLORBOX
	******************************************************************************** */
	// DEFAULT: carico il contenuto via ajax (n.b.: la pagina chiamata non deve essere una pagina completa di tag html, head, ecc.)
	$('a[class~=colorbox]').colorbox();

	// APPLICATO AI PULSANTI
	$(':button[class~=colorbox]').click(function(){ $.colorbox({ href: $(this).attr('href') }) });

	// IFRAME (in colorbox): apro una pag esterna completa di tag html, head, ecc.
	$('[class~="cBoxIframe"]').colorbox({iframe: true, width: '80%', height: '90%' });

	// INLINE: apre un elemento (il cui ID è definito nell'href con #) contenuto nella pagina del chiamante
	$('.showDiv').colorbox({ inline: true, href: function(){ return $(this).attr('href') } });



	/* *******************************************************************************
							VALIDAZIONE FORM CONTATTO
	********************************************************************************* */
	$("#info").validate({
		errorClass: "error2"
		, messages: {
			f_firstname: "Inserire nome e cognome"
			, f_from: "Inserire un'email valida"
			, f_phone: "Inserire il numero di telefono"
			, privacy: "Occorre accettare l'informativa"
		}
	});


	/* ********************************************************************************
								ACCORDION SOCI IN HOME
	******************************************************************************** */
	$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: Math.floor(Math.random()*6)});



	/* ********************************************************************************
										TOOLTIP
	******************************************************************************** */
	// piccolo nero
	$('.tip[title]').tooltip({ effect: 'slide', predelay: 100, delay: 0 }).dynamic();
	// grande nero
	$('.tip2[title]').tooltip({ tipClass: 'tooltip2', effect: 'slide', predelay: 100, delay: 0 }).dynamic();
	// piccolo bianco
	$('.tip3[title]').tooltip({ tipClass: 'tooltip3', effect: 'slide', predelay: 100, delay: 0 }).dynamic();
	// grande bianco
	$('.tip4[title]').tooltip({ tipClass: 'tooltip4', effect: 'slide', predelay: 100, delay: 0 }).dynamic();
	// classe "TODO" per comunicazione di note interne
	$('.todo[title]')
		.tooltip({ effect: 'fade', tipClass: 'tooltipTodo', predelay: 0, delay: 0 })
		.dynamic();
	


	/* ********************************************************************************
									BEHAVIORAL STYLING
	******************************************************************************** */
	/* ANIMAZIONE PAYOFF */
	if ( location.pathname == '/' || location.pathname.indexOf('index') == 1 ){ // se sono in home
		$('#payOffWrapper')
			.append('<img src="/images/payoff.png" alt="Il biologico italiano in movimento" title="Il biologico italiano in movimento" style="display: block; position: absolute; bottom: -35px">')
			.find('img')
				.animate({
					bottom: 0
				}, 800, 'easeOutExpo');
	};


});
