	(function($) {

		$.suggest = function(input, options) {
			var $input = $(input).attr("autocomplete", "off");
			var $results = $(document.createElement("ul"));
			var timeout = false;		// hold timeout ID for suggestion results to appear	
			var prevLength = 0;			// last recorded length of $input.val()
			var cache = [];				// cache MRU list
			var cacheSize = 0;			// size of cache in chars (bytes?)
			$results.addClass(options.resultsClass).appendTo('body');
			resetPosition();
			$(window)
				.load(resetPosition)		// just in case user is changing size of page while loading
				.resize(resetPosition);
			$input.blur(function() {
				setTimeout(function() { $results.hide() }, 200);
			});
			try {
				if($results.bgiframe)
				{$results.bgiframe();}
			} catch(e) { }
			$input.keyup(processKey);		// onkeydown repeats arrow keys in IE/Safari
			function resetPosition() {
				// requires jquery.dimension plugin
				var offset = $input.offset();
				var inputWidth=$input.width();			
				if(isNaN(inputWidth) || inputWidth==0)
					inputWidth=parseInt($input.css("width"));
				var _p =parseInt($input.css("padding-left"));
				if(!isNaN(_p))
					inputWidth+=_p;
				_p =parseInt($input.css("padding-right"));
				if(!isNaN(_p))
					inputWidth+=_p;
				$results.css({
					top: (offset.top + input.offsetHeight) + 'px',
					left: offset.left + 'px',
					width: inputWidth+ 'px'
				});
			}
			function processKey(e) {
				if ((/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) ||
					(/^13$|^9$/.test(e.keyCode) && getCurrentResult())) {
		            
		            if (e.preventDefault)
		                e.preventDefault();
					if (e.stopPropagation)
		                e.stopPropagation();

					e.cancelBubble = true;
					e.returnValue = false;
				
					switch(e.keyCode) {
	
						case 38: // up
							prevResult();
							break;
				
						case 40: // down
							nextResult();
							break;
	
						case 9:  // tab
						case 13: // return
							selectCurrentResult();
							break;
							
						case 27: //	escape
							$results.hide();
							break;
	
					}
					
				} else if ($input.val().length != prevLength) {
					
					if (timeout) 
						clearTimeout(timeout);
					timeout = setTimeout(suggest, options.delay);
					prevLength = $input.val().length;
				}
					
				
			}
			
			
			function suggest() {
			
				var q = $.trim($input.val());

				if (q.length >= options.minchars) {
					
					cached = checkCache(q);
					
					if (cached) {
					
						displayItems(cached['items']);
						
					} else {
						var typeId=1;
						var uri=location.pathname;
						if(uri.indexOf("/ershoufang/")==0)
							typeId=1;
						else if(uri.indexOf("/zufang/")==0)
							typeId=0;
						else{
							if($("#searchtype").length==1)
							 	typeId=$("#searchtype").val();
							else
								typeId=$("select[name=stype]").val();
						}
						if(typeof typeId=="undefined")	
							typeId=1;
						$.get(options.source, {q:q,t:typeId}, function(txt) {
							$results.hide();
							var items = parseTxt(txt, q);
							displayItems(items);
							addToCache(q, items, txt.length);
							
						});
						
					}
					
				} else {
				
					$results.hide();
					
				}
					
			}
			
			
			function checkCache(q) {

				for (var i = 0; i < cache.length; i++)
					if (cache[i]['q'] == q) {
						cache.unshift(cache.splice(i, 1)[0]);
						return cache[0];
					}
				
				return false;
			
			}
			
			function addToCache(q, items, size) {

				while (cache.length && (cacheSize + size > options.maxCacheSize)) {
					var cached = cache.pop();
					cacheSize -= cached['size'];
				}
				
				cache.push({
					q: q,
					size: size,
					items: items
					});
					
				cacheSize += size;
			
			}
			
			function displayItems(items) {
				
				if (!items)
					return;
					
				if (!items.length) {
					$results.hide();
					return;
				}
				
				var html = '';
				for (var i = 0; i < items.length; i++)
					{
						var ts2 = items[i].split("|");
						if(ts2.length==2)
							html += '<li><div class="name">'+ts2[0]+'</div><div class="amount">约 <span>'+ts2[1]+'</span> 条</div><div class="clear"/></li>';
					}
				$results.html(html).show();
				$results
					.children('li')
					.mouseover(function() {
						$results.children('li').removeClass(options.selectClass);
						$(this).addClass(options.selectClass);
					})
					.click(function(e) {
						e.preventDefault(); 
						e.stopPropagation();
						selectCurrentResult();
					});
							
			}
			
			function parseTxt(txt, q) {
				
				var items = [];
				var tokens = txt.split(options.delimiter);
				
				// parse returned data for non-empty items
				for (var i = 0; i < tokens.length; i++) {
					var token = $.trim(tokens[i]);
					if (token) {
						items[items.length] = token;
					}
				}
				
				return items;
			}
			
			function getCurrentResult() {
			
				if (!$results.is(':visible'))
					return false;
			
				var $currentResult = $results.children('li.' + options.selectClass);
				
				if (!$currentResult.length)
					$currentResult = false;
					
				return $currentResult;

			}
			
			function selectCurrentResult() {
			
				$currentResult = getCurrentResult();
			
				if ($currentResult) {
					
					$input.val($currentResult.children(":first").text());
					try{
					var chd2=$currentResult.children(":nth-child(2)").children("SPAN").text();
					if(chd2!=null)
						$input.attr("secondvalue",chd2);
					}catch(ex){}
					$results.hide();
					
					if (options.onSelect)
						options.onSelect.apply($input[0]);
						
				}
			
			}
			var idx=0;
			function nextResult() {
			
				$currentResult = getCurrentResult();
			
				if ($currentResult)
					{
					$currentResult
						.removeClass(options.selectClass);
					var nt=$currentResult.next();
					if(nt && nt.length>0)
						{
							
							nt.addClass(options.selectClass);
							$input.val(nt.children(":first").text());
							try{
								var chd2=nt.children(":nth-child(2)").children("SPAN").text();
								
								if(chd2!=null)$input.attr("secondvalue",chd2);
							}catch(ex){}
							
						}else{
							
							
							$input.val($input.attr("initv"));
							$input.attr("secondvalue",$input.attr("initc"));
						}
					}
				else
					{
						$input.attr("initv",$input.val());
						$input.attr("initc",$input.attr("secondvalue"));
						var nt=$results.children('li:first-child');
						if(nt && nt.length>0){
							nt.addClass(options.selectClass);
							$input.val(nt.children(":first").text());
							try{
								var chd2=nt.children(":nth-child(2)").children("SPAN").text();
							
								if(chd2!=null)$input.attr("secondvalue",chd2);
								}catch(ex){}
							}
						
					}
			
			}
			
			function prevResult() {
			
				$currentResult = getCurrentResult();
			
				if ($currentResult)
				{	
					$currentResult
						.removeClass(options.selectClass);
					var nt=$currentResult.prev();
					if(nt && nt.length>0)
						{
							nt.addClass(options.selectClass);
							$input.val(nt.children(":first").text());
							try{
								var chd2=nt.children(":nth-child(2)").children("SPAN").text();
								if(chd2!=null)$input.attr("secondvalue",chd2);
								
							}catch(ex){}
						}else{
							$input.val($input.attr("initv"));
							$input.attr("secondvalue",$input.attr("initc"));
								
						}
						
				}
				else
					{
						$input.attr("initv",$input.val());
						$input.attr("initc",$input.attr("secondvalue"));
						var nt=$results.children('li:last-child');
						if(nt && nt.length>0){
							nt.addClass(options.selectClass);
							$input.val(nt.children(":first").text());
							try{
								var chd2=nt.children(":nth-child(2)").children("SPAN").text();
								if(chd2!=null)$input.attr("secondvalue",chd2);
								
							}catch(ex){}
							
						}
					}
			}
			
	
		}
		$.fn.suggest = function(source, options) {
			if (!source)
				return;
			options = options || {};
			options.source = source;
			options.delay = options.delay || 100;
			options.resultsClass = options.resultsClass || 'ac_results';
			options.selectClass = options.selectClass || 'ac_over';
			options.matchClass = options.matchClass || 'ac_match';
			options.minchars = options.minchars || 1;
			options.delimiter = options.delimiter || '\n';
			options.onSelect = options.onSelect || false;
			options.maxCacheSize = options.maxCacheSize || 65536;
			this.each(function() {
				new $.suggest(this, options);
			});
	
			return this;
			
		};
		
	})(jQuery);
	/*最近浏览房源*/
	function showZJLL(){
	var topdiv= $("#topzjll");
	if(topdiv.css("display")=="none"){
		if(topdiv.attr("rel")!=1){
		    topdiv.attr("rel","1");
			$.ajax({type:"get",
	        url:"/recent/lltop.jsp",
	        dataType:"htm",
	        error: function(){
            topdiv.html("没有保存最近浏览的房源");
        	},
	        success:function(html){
		    topdiv.html(html);
	       	}});
		}
		topdiv.css("display","block");
	}else{
		topdiv.css("display","none");
	}
	}
	
	
   
    try{
       var ua = navigator.userAgent.toLowerCase();
       if (window.ActiveXObject)
          {
          	 var ie = ua.match(/msie ([\d.]+)/)[1]; 
          	 if(parseInt(ie)<=6){
          	 	document.execCommand("BackgroundImageCache", false, true);
          	 }
          }
       }catch(Exc){
     }
