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 annuncioclick(idannuncio) {
	var linkannuncio=$("#ann-"+idannuncio).attr("href");
	document.location.href=linkannuncio;
	} 

	
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();  
	
//	$('#recent_blog').cycle({
//			fx:     'blindY',
//			speed:  'slow', 
//			next:   '#recent_blog_down',
//			prev:   '#recent_blog_up',
//			sync:	1,
//			cleartypeNoBg: true
//		});

});

$(function() { $("#tabs").tabs({ fx: { opacity: 'toggle' } }); }); 


function lookup(inputString) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    } else {
		$('input[name=inputhide]').attr({value: ''});
		$('input[name=inputhidetipo]').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 filltipo(thisValue3) {
    $('#inputhidetipo').val(thisValue3);
}
function SelectAll(id)
{
    document.getElementById(id).select();
}

 

$(document).ready(function(){ 
my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox']");
/*$('#logoitalia').shiningImage({
	direction : 'z',
	opacity : 0.25,
	scale : 0.7,
	speed : 100,
	delay : 3000
});*/
$('#dove').change(function() {
  $('input[name=inputhide]').attr({value: ''});
  $('input[name=inputhidetipo]').attr({value: ''});
});

$('#menven').click(function() {
  	$('input[name=tipologia]').attr({value: 'Vendita'});
	$('#menaff a').removeClass('active');
	$('#menaff .selectedmenufreccia').removeClass('frecciavisible');
	$('#menaff .selectedmenufreccia').addClass('freccianonvisible');
	$('#menven a').addClass('active');
	$('#menven .selectedmenufreccia').removeClass('freccianonvisible');
	$('#menven .selectedmenufreccia').addClass('frecciavisible');
	$('#testomotore').html('Ricerca immobili in vendita residenziali e commerciali');
});
$('#menaff').click(function() {
  $('input[name=tipologia]').attr({value: 'Affitto'});
	$('#menven a').removeClass('active');
	$('#menven .selectedmenufreccia').removeClass('frecciavisible');
	$('#menven .selectedmenufreccia').addClass('freccianonvisible');
	$('#menaff a').addClass('active');
	$('#menaff .selectedmenufreccia').removeClass('freccianonvisible');
	$('#menaff .selectedmenufreccia').addClass('frecciavisible');
	$('#testomotore').html('Ricerca immobili in affitto residenziali, commerciali e case vacanza');
});
$('#menven,#menaff').click(function() {
     		var nomecampo=$(this).attr('id');
			var pageURL = 'http://' + document.domain;
                   var url = pageURL+'/w-response/ajax_vendita_affitto.asp.asp';
                   var urlblog =  pageURL;
				   var postData = "campo="+nomecampo+"&rnd="+(Math.random());

                       $.ajax({
                            type: "POST",
                            url: url,
                            data: postData,
                            success: function(datos){
							$("#txtSelectvenaff").html(datos);
							$("select#prezzofino").selectmenu({
				style:'dropdown',
				width:130,
		        maxHeight: 115
				});	

                          		}
      						});
});

$('.Resquestmap a[href*=#],a[href*=#mutuocalcolo]').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 toggle_remaining_desc(id){
	var desc = document.getElementById("descrizione_"+id)
	var toggler = document.getElementById("toggle_descrizione_"+id);
	var toggler_img = document.getElementById("toggle_descrizione_img_"+id);
	var toggler_testo = document.getElementById("toggle_link_testo_"+id)
	
	if (desc.open){
		desc.open = false;
		desc.style.height = "90px";
		if (toggler_img){
			toggler_img.src = "/w-assets/16_square_green_add.png";
			toggler_img.alt="[+]";
			toggler_img.title="leggi di pił";
		}
		if(toggler_testo)
		    toggler_testo.innerHTML = "continua a leggere";
		
	}else{
		desc.open = true;
		desc.style.height = "";
		if (toggler_img){
			toggler_img.src = "/w-assets/16_square_red_remove.png";
			toggler_img.alt="[-]";
			toggler_img.title="leggi di meno";
		}
		if(toggler_testo)
		    toggler_testo.innerHTML = "riduci descrizione";
		
	}
	
}
function setDescProps(id,height){
    var desc = document.getElementById("descrizione_"+id);
    var toggler = document.getElementById("toggle_descrizione_"+id);
    var txtHeight = 0;
    
    if (!desc.textHeight){
	desc.style.height = height;
	desc.style.overflow= "hidden";
	var txt = desc.innerHTML;
	var oDiv = document.createElement('div');
	oDiv.innerHTML = txt;
	oDiv.style.display="none";
	desc.appendChild(oDiv);
	txtHeight = MEgetHeight(oDiv);
	desc.removeChild(oDiv);
	desc.textHeight = txtHeight;
    
    
	if (!desc.origHeight)
	    desc.origHeight = MEgetHeight(desc);
    
	if (txtHeight > desc.origHeight){
	    toggler.style.display = "inline";
	}else
	    desc.style.height = "";
    }
    
}

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// FUNZIONI MOTORE DI RICERCA
function getAjaxFiltroBox(str,str1,str2,divhtml){
	jQuery( function($) {
					var pageURL = 'http://' + document.domain;
                    var url = pageURL+'/w-response/response_risultati_filtro_box.asp';
                    var urlblog =  pageURL;
						$.ajax({
                            type: "POST",
                            url: url,
							cache: false,
                            data: "regione="+str+"&provincia="+str1+"&zona="+str2+"&sid="+Math.random(),
							beforeSend: function(){
							$('#'+divhtml).html('<center><br /><br /><img src="/w-assets/ajax-loader.gif" /></center>');
							 },
                            success: function(datos){
							$('#'+divhtml).html(datos);
                          }
                    });
               });
}
function getAjaxFiltroBoxVenditaAffitto(str,divhtml){
	jQuery( function($) {
					var pageURL = 'http://' + document.domain;
                    var url = pageURL+'/w-response/response_venaff_filter_box.asp';
                    var urlblog =  pageURL;
						$.ajax({
                            type: "POST",
                            url: url,
							cache: false,
                            data: "tipo="+str+"&sid="+Math.random(),
							beforeSend: function(){
							$('#'+divhtml).html('<center><br /><br /><img src="/w-assets/ajax-loader.gif" /></center>');
							 },
                            success: function(datos){
							$('#'+divhtml).html(datos);
                          }
                    });
               });
}

