

function selectToTooltip(select, firstOptionIsDefault, textPrefix)
    {
        var $select    = $(select),
            $input     = $("<input />", {"readonly": "readonly"}),
            textPrefix = typeof textPrefix == 'undefined' ? '' : textPrefix;

        $input.data("select", $select);
        $select.data("input", $input);
        $select.before($input);
        $select.hide();

        if ( firstOptionIsDefault === true )
        {
            $input.val($select.find('option:first').text());
        }

        $input.focus(function() {
            var $input         = $(this),
                $select        = $input.data("select"),
                $options       = $('<ul />'),
                $selectOptions = $select.find('option');

            if ( firstOptionIsDefault === true )
            {
                $selectOptions = $selectOptions.not(':eq(0)');
            }

            $selectOptions.each(function() {
                var $this   = $(this);
                var $option = $('<li />', {
                    "text" : $this.text(),
                    "click": function() {
                        $select
                            .val($this.val())
                            .change();

                        $input.val(textPrefix + $this.text());
                        $input.qtip('destroy');
                    }
                });

                $options.append($option);
            });

            $input.qtip({
                content: {
                    text: $options,
                    title: $select.find('option:first').text()
                },
                hide: {
                    fixed: true,
                    event: "unfocus"
                },
                position: {
            		 viewport: $(window)

                },
                show: {
                    event: "focus"
                },
                style: {
                    tip: true,
                    classes: "ui-tooltip-italiahotels"
                },
                events: {
                    hide: function(event, api) {
                        api.destroy();
                    }
                }
            });

            $input.qtip("show");
        });
    }

$(function() {
		   $(".form-generico").each(function(i) { 
		$(this).validate();
	});
	
	$(".form-newsletter").each(function(i) { 
		$(this).validate();
	});



	 
	 
	 $('a[href*=#voli]').bind('click', function() {
        $(this).colorbox({href: 'http://www.g40.it/ar/offerte.php?i=1&m=p&a=617&l=1', iframe: true, height: '95%', width: '900px', opacity: '0.65', open: true});

        return false;
    });
	 
	 	 
	 $('a[href*=#hotels]').bind('click', function() {
        $(this).colorbox({href: 'http://www.hrs.com/web3/?client=it__tuevacanze', iframe: true, height: '95%', width: '900px', opacity: '0.65', open: true});

        return false;
    });
	
	
	var $slider = $("#slider").carouFredSel({
		items: 1,
		scroll: {duration:900},
		direction: "up",
        scroll: {
            onBefore: function() {
                $('#paginazione-slider-motore-ricerca')
                    .stop()
                    .animate(
                        {backgroundPosition: '0 ' + (- 217 + 63 * $slider.current_position()) + 'px'}, 
                        {duration: $slider.configuration('scroll.duration')}
                    );
            }
        },
        pagination: {
            container: '#paginazione-slider-motore-ricerca',
            anchorBuilder: function(n) {
                //modificare per generare le thumb
                return '<li><img src="' + $('#slider .slide:eq(' + (n - 1) + ') img').attr('src').replace('w=640&h=278', 'w=70&h=45') + '" /></li>';
            }
        }
	});// -217 + 63 * n
	$("#comunicazione-interno2 ul#pt").carouFredSel({
		items: 1,
		prev: "#prev3",
		next: "#next3",
		scroll: {duration:1200, items:1}
	});
	$("#slider-offerte ul").carouFredSel({
		items: 3,
		prev: "#prev",
		next: "#next",
		scroll: {duration:700, items:1}
	});
	
	$("#slider-cataloghi ul").carouFredSel({
		items: 3,
		prev: "#prev2",
		next: "#next2",
		scroll: {duration:800, items:3}
	});
		$("#slider-cadeaux").cycle();
		$("#slider-news").cycle();
		$(".ui-tabs").tabs();
		$.datepicker.setDefaults($.datepicker.regional['it']);
        $('#datadipartenza').datepicker({
            "buttonImage"     : BASEURL + "/images/icon_calendario.jpg",
            "buttonImageOnly" : true,
            "numberOfMonths"  : 2,
            "showButtonPanel" : true,
            "showOn"          : "both",
            "showOtherMonths" : true,
            "stepMonths"      : 2
        });		
	      // selectToTooltip($('#location'), true, 'localita: ');

		if ( $('#map').length > 0 ) {
		
			showmaps();
			
		}
		
		$('a[rel=external]').click(function() {
            window.open($(this).attr('href'));
			
            
            return false;
        });
		

		
		
});
