function displayMapRos() {
	var index, totalamount=10;
		$('#resultsMap').css('display', '');
		$('#linkDisplayMap').html('<a onclick="hideMapRos()" href="javascript:void(0)">nascondi mappa</a>');
		for (index=1; index<=totalamount; index++) {
			if (document.getElementById('summaryNumberID'+index)) {
				document.getElementById('summaryNumberID'+index).className = 'summaryNumber isVisible';
			}
		}
		$.cookie('showMap', '1', { expires: 7, path: '/'});
		initialize();
	} 
	
function hideMapRos() {
	var index, totalamount=10;
		$('#resultsMap').css('display', 'none');
		$('#linkDisplayMap').html('<a onclick="displayMapRos()" href="javascript:void(0)">mostra mappa</a>');
		for (index=1; index<=totalamount; index++) {
			if (document.getElementById('summaryNumberID'+index)) {
				document.getElementById('summaryNumberID'+index).className = 'summaryNumber isHidden';
			}
		}
		$.cookie('showMap', '0', { expires: 7, path: '/'});
}

function Inizializer() {
			$("#dove").data("action","").data("value","scrivi la località").data("key","");
			$(".display li").hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);

$("#more-motore").click( function() {$("#option-motore").slideToggle("fast");$(this).toggleClass("selected"); return(false);}); 

		}

/**
 * bindSlider
 * 
 * @param {Object} o	id del div dello slider
 * @param {Object} s	step dello slider 
 * @param {Object} mn	valore minimo
 * @param {Object} mx	valore massimo
 * @param {Object} v	valore attuale
 * @param {Object} f	funzione da eseguire allo slide
 */

function bindSlider(o,s,mn,mx,v,f) {$("#slider-" + o).slider({orientation: "horizontal",step: s,animate: true,min: mn,max: mx,value: v,slide: f});}
function UI_SliderMq(e,ui) {( ui.value == 410 ) ? $("#mqmax").val("qualsiasi") : $("#mqmax").val( "da " + ui.value + " mq" );}
function UI_SliderLoc(e,ui) {
	if ( ui.value == 0 ) { 
		$("#vani").val("qualsiasi"); 
	} else if (ui.value == 6) {
		$("#vani").val("oltre 5");
	} else {
		$("#vani").val( ui.value );
	}
}
function UI_SliderRooms(e,ui) {( ui.value == 0 ) ? $("#camere").val("qualsiasi") : $("#camere").val( ui.value );}
function UI_SliderBath(e,ui) {( ui.value == 0 ) ? $("#bagni").val("qualsiasi") : $("#bagni").val( ui.value );}

jQuery(function($) {
	$(document)

	Inizializer();  
	
	
});

$(function() { $("#tabs").tabs(); }); 


function lookup(inputString) {
		$('input[name=inputhide]').attr({value: ''});

        $.post("/w-response/response-comuni-motore.asp", {queryString: ""+inputString+""}, function(data){
            if(data.length >0) {
                $('#suggestions').fadeIn();
                $('#autoSuggestionsList').html(data);
            }
        });
} // lookup

function lookuphide(inputString) {
        $('#suggestions').fadeOut();
} // lookup


function fill(thisValue) {
    $('#dove').val(thisValue);
	setTimeout("$('#suggestions').fadeOut();", 400);
}
function fillid(thisValue2) {
    $('#inputhide').val(thisValue2);
}
function SelectAll(id)
{
    document.getElementById(id).select();
}

 

$(document).ready(function(){ 
my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox']");

$('#dove').change(function() {
  $('input[name=inputhide]').attr({value: ''});
});


$('.Resquestmap a[href*=#]').click(function() {
 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
 && location.hostname == this.hostname) {
   var $target = $(this.hash);
   $target = $target.length && $target
   || $('[name=' + this.hash.slice(1) +']');
   if ($target.length) {
  var targetOffset = $target.offset().top;
  $('html,body')
  .animate({scrollTop: targetOffset}, 1500);
	if (this.hash.slice(1)=="login") {
	$("input.focus:last").focus();
    return false;
}
   }
 }
  });
$(".focus").focus(function() {
		$(".focus").addClass("curFocus")
	});
	$("input").blur(function() {
		$(".focus").removeClass("curFocus")
	});

var indexbb;
if ($.cookie('showMap') == ''){
		$.cookie('showMap', '1', { expires: 7, path: '/'});
	
}	
if (($.cookie('showMap') == 1) || ($.cookie('showMap') == null)){
		$('#resultsMap').css('display', '');
		$('#linkDisplayMap').html('<a onclick="hideMapRos()" href="javascript:void(0)">nascondi mappa</a>');
	
} else {	
		$('#resultsMap').css('display', 'none');
		$('#linkDisplayMap').html('<a onclick="displayMapRos()" href="javascript:void(0)">mostra mappa</a>');
		for (indexbb=1; indexbb<=10; indexbb++) {
			if (document.getElementById('summaryNumberID'+indexbb)) {
				document.getElementById('summaryNumberID'+indexbb).className = 'summaryNumber isHidden';
			}
}

}
$('.summaryNumber a').click(function(){
		$( 'html, body' ).animate( { scrollTop: 140 }, 'slow' );
		return false;
	});
var $elem = $('#contenutomappa');

$(".infotooltipsagenzia[title]").tooltip({effect: 'toggle',slideOffset: 30});
$(".infotooltips[title]").tooltip({effect: 'toggle',slideOffset: 30});

jQuery('.fotovetrina').kriesi_image_preloader({delay:300});	// activates preloader for non-slideshow images
jQuery('.fotovetrinatesto').kriesi_image_preloader({delay:300});	// activates preloader for non-slideshow images
jQuery('.product_image').kriesi_image_preloader({delay:300});	// activates preloader for non-slideshow images



$("a.switch_thumb").toggle(function(){
	$(this).removeClass("swap");
	$("ul.display").fadeOut("fast", function() {
	$(this).fadeIn("fast").addClass("thumb_view");
	});
	}, function () {
	$(this).addClass("swap");
	$("ul.display").fadeOut("fast", function() {
	$(this).fadeIn("fast").removeClass("thumb_view");
});
}); 
	
/*$('.product_image img').hover(function() {
  $(this).addClass('product_imagehover');
}, function() {
  $(this).removeClass('product_imagehover');
});*/



$(".product_image a img").hoverIntent({
				over: makeTall, 
				timeout: 100, 
				out: makeShort
			});

});
function makeTall(){  $(this).animate( {opacity: "0.5" }, 200 );}
function makeShort(){ $(this).animate( {opacity: "1" }, 200 );}

// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------


(function($)
{
	$.fn.kriesi_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})(jQuery);


function my_lightbox($elements)
{	
	var usedCSS = 1;
	jQuery('link').each(function()
	{	
		styleURL = jQuery(this).attr('href'); 
		CSSnumber = styleURL.match(/style(\d).css/);
		if(CSSnumber && CSSnumber.length > 0)
		{
			usedCSS = CSSnumber[1];
		}
	});
		
	
	var theme_selected = 'light_rounded';
	if (usedCSS == 2 || usedCSS == 4)
	{
		theme_selected = 'dark_rounded';
	}
	
	jQuery($elements).prettyPhoto({
			"theme": theme_selected /* light_rounded / dark_rounded / light_square / dark_square */																	});
	
	jQuery($elements).each(function()
	{	
		var $image = jQuery(this).contents("img");

		$newclass = 'lightbox_video';
		
		if(jQuery(this).attr('href').match(/(jpg|gif|jpeg|png|tif)/)) $newclass = 'lightbox_image';
			
		if ($image.length > 0)
		{	
			if(jQuery.browser.msie &&  jQuery.browser.version < 7) jQuery(this).addClass('ie6_lightbox');
			
			var $bg = jQuery("<span class='"+$newclass+" ie6fix'></span>").appendTo(jQuery(this));
			
			jQuery(this).bind('mouseenter', function()
			{
				$height = $image.height();
				$width = $image.width();
				$pos =  $image.position();		
				$bg.css({height:$height, width:$width, top:$pos.top, left:$pos.left});
			});
		}
	});	
	
	jQuery($elements).contents("img").hover(function()
	{
		jQuery(this).stop().animate({opacity:0.5},400);
	},
	function()
	{
		jQuery(this).stop().animate({opacity:1},400);
	});
}
function showText(text) {
	return unescape(text);
}


			(function($) {
				$.fn.thumbnailSlider = function(options) {
					var opts = $.extend({}, $.fn.thumbnailSlider.defaults, options);
					return this.each(function() {
						var $this 				= $(this),
							o 					= $.meta ? $.extend({}, opts, $pxs_container.data()) : opts;
						
						var $ts_container		= $this.children('.ts_container'),
							$ts_thumbnails		= $ts_container.children('.ts_thumbnails'),
							$nav_elems			= $ts_container.children('li').not($ts_thumbnails),
							total_elems			= $nav_elems.length,
							$ts_preview_wrapper	= $ts_thumbnails.children('.ts_preview_wrapper'),
							$arrow				= $ts_thumbnails.children('span'),
							$ts_preview			= $ts_preview_wrapper.children('.ts_preview');
						
						/*
						calculate sizes for $ts_thumbnails:
						width 	-> width thumbnail + border (2*5)
						height 	-> height thumbnail + border + triangle height(6)
						top		-> -(height plus margin of 5)
						left	-> leftDot - 0.5*width + 0.5*widthNavDot 
							this will be set when hovering the nav,
							and the default value will correspond to the first nav dot	
						*/
						var w_ts_thumbnails	= o.thumb_width + 2*5,
							h_ts_thumbnails	= o.thumb_height + 2*5 + 6,
							t_ts_thumbnails	= -(h_ts_thumbnails + 5),
							$first_nav		= $nav_elems.eq(0),
							l_ts_thumbnails	= $first_nav.position().left - 0.5*w_ts_thumbnails + 0.5*$first_nav.width();
						
						$ts_thumbnails.css({
							width	: w_ts_thumbnails + 'px',
							height	: h_ts_thumbnails + 'px',
							top		: t_ts_thumbnails + 'px',
							left	: l_ts_thumbnails + 'px'
						});
						
						/*
						calculate the top and left for the arrow of the tooltip
						top		-> thumb height + border(2*5)
						left	-> (thumb width + border)/2 -width/2
						*/
						var t_arrow	= o.thumb_height + 2*5,
							l_arrow	= (o.thumb_width + 2*5) / 2 - $arrow.width() / 2;
						$arrow.css({
							left	: l_arrow + 'px',
							top		: t_arrow + 'px'
						});
						
						/*
						calculate the $ts_preview width -> thumb width times number of thumbs
						*/
						$ts_preview.css('width' , total_elems*o.thumb_width + 'px');
						
						/*
						set the $ts_preview_wrapper width and height -> thumb width / thumb height
						*/
						$ts_preview_wrapper.css({
							width	: o.thumb_width + 'px',
							height	: o.thumb_height + 'px'
						});
						
						//hover the nav elems
						$nav_elems.bind('mouseenter',function(){
							var $nav_elem	= $(this),
								idx			= $nav_elem.index();
								
							/*
							calculate the new left
							for $ts_thumbnails
							*/
							var new_left	= $nav_elem.position().left - 0.5*w_ts_thumbnails + 0.5*$nav_elem.width();
							
							$ts_thumbnails.stop(true)
										  .show()	
										  .animate({
											left	: new_left + 'px'
										  },o.speed,o.easing);				  
							
							/*
							animate the left of the $ts_preview to show the right thumb 
							*/
							$ts_preview.stop(true)
									   .animate({
											left	: -idx*o.thumb_width + 'px'
									   },o.speed,o.easing);
							
							//zoom in the thumb image if zoom is true
							if(o.zoom && o.zoomratio > 1){
								var new_width	= o.zoomratio * o.thumb_width,
									new_height	= o.zoomratio * o.thumb_height;
								
								//increase the $ts_preview width in order to fit the zoomed image
								var ts_preview_w	= $ts_preview.width();
								$ts_preview.css('width' , (ts_preview_w - o.thumb_width + new_width)  + 'px');
								
								$ts_preview.children().eq(idx).find('img').stop().animate({
									width		: new_width + 'px',
									height		: new_height + 'px'
								},o.zoomspeed);
							}		
							
						}).bind('mouseleave',function(){
							//if zoom set the width and height to defaults
							if(o.zoom && o.zoomratio > 1){
								var $nav_elem	= $(this),
									idx			= $nav_elem.index();
								$ts_preview.children().eq(idx).find('img').stop().css({
									width	: o.thumb_width + 'px',
									height	: o.thumb_height + 'px'	
								});	
							}
							
							$ts_thumbnails.stop(true)
										  .hide();
										  
						}).bind('click',function(){
							var $nav_elem	= $(this),
								idx			= $nav_elem.index();
							
							o.onClick(idx);
						});
						
					});
				};
				$.fn.thumbnailSlider.defaults = {
					speed		: 100,//speed of each slide animation
					easing		: 'jswing',//easing effect for the slide animation
					thumb_width	: 75,//your photos width
					thumb_height: 75,//your photos height
					zoom		: false,//zoom animation for the thumbs
					zoomratio	: 1.3,//multiplicator for zoom (must be > 1)
					zoomspeed	: 15000,//speed of zoom animation
					onClick		: function(){return false;}//click callback
				};
			})(jQuery);

