﻿/**
 * Trova i box con classe "allclick".
 * All'interno cerca dei link, ed estende l'href sul click di tutto il box
 * @return null
 */
function allClick()
{
try
{
	var clickbox = $('.allclick');
	clickbox.each(function()
	{
		var $this = $(this);
		$this.css('cursor','pointer');
		$this.bind('click', function(){window.location.href=$('a',this).attr('href');});
	});
}
catch(e) {toDebug(e.toString());}
}


function slideBox()
{
try
{		
	$('#offerte-slider1').cycle({
		fx: 'scrollHorz',
		speed: 2000,
		timeout: 6500, 
		next:   '#nextOff1', 
		prev:   '#prevOff1' 
	});

	$('#offerte-slider2').cycle({
		fx: 'scrollHorz',
		speed: 2000,
		timeout: 6500, 
		next:   '#nextOff2', 
		prev:   '#prevOff3' 
	});
	
	$('#head-slider').cycle({
		fx: 'fade',
		speed: 2000,
		timeout: 6500, 
		next:   '#nextPic', 
		prev:   '#prevPic' 
	});
}
catch(e) {toDebug(e.toString());}
}


function cancellaForm()
{
try
{
	$(".input_form:text").bind('focus blur',function(event)
	{
		var value = $(this).attr("originalValue");
		if (event.type == "focus") {
			if ($(this).val() == "" || $(this).val() == value) {
				$(this).val("");
			}
		}else {
			if ($(this).val() == "") {
				$(this).val(value);
			}
		}
	});	
	$("textarea.input_form").bind('focus blur',function(event)
	{
		var value = $(this).attr("originalValue");
		if (event.type == "focus") {
			if ($(this).text() == "" || $(this).text() == value) {
				$(this).text("");
			}
		}else {
			if ($(this).text() == "") {
				$(this).text(value);
			}
		}
	});
}
catch(e) {toDebug(e.toString());}
}

function formPrevBambini()
{
try
{	
	$('select#frm_numero_bambini option').click(function(){
		var $this = $(this);
		var nchild = parseInt($this.val());
		if (nchild>3) nchild=3;
		if (('#frm_eta_bambini')||(nchild==0)){
			$('#frm_eta_bambini').remove();
		}
		if (nchild>0){
			var contenuto = "";
			var ncol = (nchild*2)-1;
			if(ncol == 1) ncol = 2;
			contenuto += "<table id=\"frm_eta_bambini\"><tr><td style=\"padding-top:5px; padding-right: 10px;\">età bambini</td>";
			for (i=1; i<=nchild; i++){
				contenuto += "<td><div><select><option value='' selected=''>?</option><option value='1'>1</option><option value='2' >2</option><option value='3'>3</option><option value='4' >4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select></div></td>";
				if(i!=nchild || ncol==2){
					contenuto += "<td width='10'></td>"
				}
			}
			contenuto += "</tr></table>";
			$('.box-eta-bambini').html(contenuto);
		}
	});
}
catch(e) {toDebug(e.toString());}
}

/*****************************************************************************************/
//	inizio funzioni di debug
debug_msg = false;
function toDebug(string)
{
	if (debug_msg)
	{
		if((typeof window.console=="undefined")) {alert(string);}
		else {
			console.error();
			console.group(string);
			console.trace();
			console.groupEnd();
		}
	}
}
function toConsole(string)
{
	if((typeof window.console=="undefined")) {alert(string);}
	else console.log(string);
}
//fine funzioni di debug

function $j(argument)
{
	var result = jQuery(argument);
	if (result.length == 0) return null;
	else return result;
}

$j(document).ready(function()
{ 

	allClick();
	slideBox();
	//cancellaForm();

	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook'});
	
});

$j(window).load(function()
{
	formPrevBambini();

});

$j(window).resize(function()
{

});

/*****************************************************************************************/
