// JavaScript Document

$(document).ready(function(){
		
	showroom();
	
	var ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	if (ie6){
		$('.arrowbox').css({backgroundColor:'#C2CBCF', color:'#000'});
	}
	
	if ($('#content').height()>$('#column').height())
		$('#column').height($('#content').height())
	
	$('.arrowbox').corner({
		tl:{radius:15},
		tr:{radius:15},
		bl:{radius:0},
		br:{radius:0}
	}).css({backgroundImage:'url(layout/arrow.png)',backgroundPosition:'right bottom', backgroundRepeat:'no-repeat'});

	$('.box,h2.round').corner({
		tl:{radius:15},
		tr:{radius:15},
		bl:{radius:15},
		br:{radius:15}
	});


	$('h3.sifr').sifr({
		path: './sifr/',
		font: 'brigitte',
		fontSize:60,
		width:550,
		textAlign:'left'
	});

	$('.halfsifr').sifr({
		path: './sifr/',
		font: 'brigitte',
		fontSize:60,
		width:250,
		textAlign:'center'
	});
	
	$('.box h2, .box .firma').sifr({
		path: './sifr/',
		font: 'brigitte',
		color:'#000',
		textAlign:'left'
	});	
	
	//$('div,img[src$=png]').css({behavior: 'url(layout/iepngfix.htc');})
	// Date picker
	$('.datePicker').each(function(){
		
		var dateOptions = $(this).attr('alt') ? eval('('+$(this).attr('alt')+')') : {};
	
		$(this).datepicker(dateOptions);
	});
	
	

	$('a[@href*="youtube"]').flash(
			{ width: 480, height: 380},
			{ version: 8 },
			function(htmlOptions) {
					$this = $(this);
					htmlOptions.src = $this.attr('href');
					htmlOptions.autoplay=1;
					$this.before($.fn.flash.transform(htmlOptions));						
			}
	).text('');


	
	$('#disponibilita').submit(function(){
																			
		if(($('input[name^=servizi]').length>0) && ($('input[name^=servizi][checked]').length != 2)){
			alert('Devi selezionare 2 omaggi!');
			return false;
		}
		
		// Giorni non validi
		var dataDa = new String($('#dataDa').val()).split('/');
		var night =  $('#nnotti').val();
		var notAllow = ['19/3/2010','20/3/2010'];		

		var date = new Date(parseInt(dataDa[2]), parseInt(dataDa[1]), parseInt(dataDa[0]));
		var i = 0;
		do{
			var strDate = date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear();
			if ($.inArray(strDate,notAllow)>-1){
				alert("Siamo spiacenti ma nel giorno "+ strDate +" non abbiamo piu' disponibilita'");
				return false;
			}
			i++;
			date = new Date(parseInt(dataDa[2]), parseInt(dataDa[1]), parseInt(dataDa[0])+i);
		}while(i<night);
		
		
		
	});



});


var countBox = 0;
function prevBox(){
	countBox --;
	if (countBox <0)
		countBox = $('.box').length-1;
	showBox();
}

function nextBox(){
	countBox ++;
	if (countBox >$('.box').length-1)
		countBox = 0;
	showBox();
}


function showBox(){
	$('.box').hide();


	$('.box:eq('+countBox+')').show();
	$('.box h2, .box .firma').sifr({
		path: './sifr/',
		font: 'brigitte',
		color:'#000',
		textAlign:'left'
	});	
}


function showroom(){
	var val = $('#camera').val();
	$('.camera').hide();
	$('.camera[title='+val+']').show();

}


	function checkForm(){
		if (! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($('#email').val())){
			alert("L'indirizzo email non e' corretto!");
			return false;
		}

		var dataArrivo = $('#dataDa').val();
		var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;

		if (dataArrivo!=''){
			if (!dataArrivo.match(RegExPattern)){
				alert('Devi inserire la data nel formato dd/mm/yyyy.');
				return false;
			} 
		}
		else{
			alert('Devi inserire le date!');
			return false;
		}
		
	 return true					
	
	}

