/* ********************************************************************************
					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, " "));
};



/* ********************************************************************************
						JGROWL - NOTICE, WARNING, ERROR
******************************************************************************** */
function showNotice(text, title){ $.jGrowl(text, { header: title, theme: 'notice' }) };
function showWarning(text, title){ $.jGrowl(text, { header: title, sticky: true, theme: 'warning' }) };
function showError(text, title){ $.jGrowl(text, { header: title, sticky: true, theme: 'error' }) };



/* ********************************************************************************
									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(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" ); };

	
	/* ********************************************************************************
							VALIDAZIONE CHECKBOX PRIVACY
	******************************************************************************** */
	$('form').submit(function(){
		if ( $(':checkbox.privacy').is(':not(:checked)') ){
			showError('E\' necessario accettare l\'informativa sulla privacy.', 'Attenzione');
			return false;
		}
	});


	// SCROLLABLE HOME (promozioni)
	$('#promoScrollable').scrollable({
		prev: '#promoPrev'
		, next: '#promoNext'
		, keyboard: true
		, circular: true
	}).autoscroll({ autoplay: true, interval: 4000 });		
	
	
	//COLOR BOX
	$("a[rel='foto']").colorbox({
		transition:"elastic"
		, slideshow: true
		, slideshowSpeed: 3000
		, opacity: 0.95	
		, width:"80%"
		, height:"90%"
	});
	
	//COLOR BOX
	$("a[rel='foto2']").colorbox({
		transition:"elastic"
		, slideshow: true
		, slideshowSpeed: 3000
		, opacity: 0.95
		, width:"80%"
		, height:"90%"
	});
	//COLOR BOX
	$("#privacy").colorbox({ width:"80%", height:"90%", iframe:true});
	
	// FORM CONTATTO: field highlight
	$('#form input.data, #form textarea')
		.focus(function(){
			$(this).css({ background: '#ffa' })
			.parent().css({color: '#000'})
		})
		.blur(function(){
			$(this).css({ background: '#fff' })
			.parent().css({color: '#555'})
		})

	// MESSAGGI DI SISTEMA DELLA FORM
	$("#formOk").submit(function() {
		var send = true;
		if($('#accept_privacy').is(':checked') == false) {
			send = false;
			$.fn.colorbox({width:"50%", inline:true, href:"#checkedPrivacy"});
			return false;
		}
	});

	// CARICO IL DETTAGLIO DELLA FOTO
	$('#fotoItems img').click(function(){ // al click su una thumb
		$('#fotoDetail').attr({
			src: $(this).attr('detail') // mostro il suo dettaglio
			, zoom: $(this).attr('zoom') // predispongo il link per lo zoom
		});
		$("#fotoDetail").colorbox({
			photo: true
			, href: function(){ return $(this).attr('zoom') }
			, width:"80%"
			, height:"90%"
			, opacity: 0.95		
		});
	});
	$("#fotoDetail").colorbox({
		photo: true
		, href: function(){ return $(this).attr('zoom') }
		, width:"80%"
		, height:"90%"
		, opacity: 0.95		
	});
	
});

function isInteger(s)
{
	var i;
	for(i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if(((c < "0") || (c > "9"))) return false;
	}
	return true;
}

