function mapOnLoaded(){
	if(g_init.street > 0)
		showStreet({id:g_init.street,x:g_init.sx,y:g_init.sy,zoom:g_init.sz,business:g_init.business});	
	else if(g_init.blat && g_init.blng){
		ps.map.setCenter(new google.maps.LatLng(g_init.blat, g_init.blng));
		ps.showBusinessMarker(g_init.business,g_init.bname,parseFloat(g_init.blat),parseFloat(g_init.blng),false,{src:"images/marker1.png",width:47,height:38,offsetX:7,offsetY:34});
		popupBusiness(g_init.business, g_init.bname);
		g_init = null;
	}
	if(g_init.search.length > 0){
		setSearchTarget(0);
		$(".searchbox input[name='what']").val(g_init.search);
		search();
	}
				
	$("#tipbar").slideDown(500);
	setTimeout("hideTipBar()",8000);	
}
function hideTipBar(){
	$("#tipbar").slideUp(500);
}
function pageUnload(){
	ps.unload();
}
function resize(){
	var iever = 0;
	if($.browser.msie){
		var v = $.browser.version.split(".");
		iever = v[0] ? parseInt(v[0]) : 0;
		if (iever > 0 && iever < 8) {
			var h = $(window).height() - $(".top").height() - $(".bottom").height();
			$(".content").height(h);
			$(".main").height(h);
			$("#panel").height(h);
			$("#panel .panelc").height(h - $("#panel .menu").height());
			$("#panelshadow").height(h);
			if(iever < 7 && $(".searchtitle").css("display") != "none"){
				$(".searchresult").height($("#panel .panelc").height() - $(".searchtitle").height() - 1);
			}
			if(iever < 7 && $(".searchtags").css("display") != "none"){
				$(".searchtags").height($("#panel .panelc").height() - 1);
			}
		}
	}
	var h = $(".main").height() - $("#mainBanner").height();
	if($("#streetContainer").css("display") != "none"){
		if(g_isFullView){
			$("#streetContainer").height(h);		
		}else{
			if(h <= 300) g_streetHeight = 0.5;
			var sh = parseInt(h * g_streetHeight);
			$("#streetContainer").height(sh);		
			$("#mapContainer").height(h - sh);
			$("#mapContainer").css("top", sh);
		}		
		if(iever > 0 && iever < 7){
			$("#streetFrame").height($("#streetContainer").height() - $("#horzSplitter").height());
		}
		
	}else{
		$("#mapContainer").height(h);
		$("#mapContainer").css("top", 0);
	}
	if(ps && ps.map) ps.map.checkResize();
}
function showPanel(){	
	if($("#panel").position().left == 0) return; 
	$("#panel").animate({left:"0px"}, 150, function(){
		var diff = ps.map.fromContainerPixelToLatLng(new google.maps.Point(320, 0)).lng() - ps.map.getBounds().getSouthWest().lng();
		var c = ps.map.getCenter();
		var nc = new google.maps.LatLng(c.lat(), c.lng() + diff);
		ps.map.setCenter(nc);

		$(".main").css("marginLeft","320px");
		ps.map.checkResize();
	});
	$(".showpanel").hide();
}
function hidePanel(){
	if($("#panel").position().left < 0) return;
	 
	var diff = ps.map.fromContainerPixelToLatLng(new google.maps.Point(320, 0)).lng() - ps.map.getBounds().getSouthWest().lng();
	var c = ps.map.getCenter();
	var nc = new google.maps.LatLng(c.lat(), c.lng() - diff);
	
	ps.map.setCenter(nc);
	$(".main").css("marginLeft","0");
	$("#panel").animate({left:"-320px"}, 150,function(){
		ps.map.checkResize();		
	});
	$(".showpanel").show();
}
function horzSplitterMove(evt){
	var h = evt.pageY - $("#streetContainer").offset().top + 2;
	var mh = $(".main").height() - $("#mainBanner").height();
	if(mh <= 300) h = parseInt(mh / 2);
	else if(mh - h < 150) h = mh - 150;
	else if(h < 150) h = 150;
	g_streetHeight = h / mh;

	$("#streetContainer").height(h);
	$("#mapContainer").height(mh - h);
	$("#mapContainer").css("top", $("#streetContainer").height());
	
	if (!$.browser.msie) {
		$("#streetContainer").trigger("resize");
		$("#mapContainer").trigger("resize");
	}else{
		var v = $.browser.version.split(".");
		iever = v[0] ? parseInt(v[0]) : 0;
		if (v[0] && parseInt(v[0]) < 7) {
			$("#streetFrame").height($("#streetContainer").height() - $("#horzSplitter").height());
		}
	}	
}
function beginHorzSplitterMove(){
	$(document.body).css("cursor", "s-resize");
	$(document).bind("mousemove", horzSplitterMove);
	$(document).bind("mouseup", endHorzSplitterMove);	
}
function endHorzSplitterMove(){
	$(document).unbind("mousemove", horzSplitterMove);		
	$(document).bind("mouseup", endHorzSplitterMove);
	$(document.body).css("cursor", "default");
	
	if(ps.map) ps.map.checkResize();
}
function streetFullView(full){
	if(g_isFullView == full) return;
	g_isFullView = full;
	if(full){
		g_panelVisibleSaved = ($("#panel").position().left >= 0);
		hidePanel();
		resize();
		$("#streetButtons a[rel='maximize']").hide();
		$("#streetButtons a[rel='restore']").show();
	}else{
		if(g_panelVisibleSaved)
			showPanel();					
		resize();
		$("#streetButtons a[rel='maximize']").show();
		$("#streetButtons a[rel='restore']").hide();
	}
}
function showLoading(){
	$("#mainLoading").css({left:($(".main").width() - $("#mainLoading").width()) / 2,top:($(".main").height() - $("#mainLoading").height()) / 2});
	$("#mainLoading").show();	
}
function hideLoading(){
	$("#mainLoading").hide();
}
function mapOnStreetClick(id, lat, lng){
	ps.setActiveStreet(id);
	showLoading();
	$.ajax({
		type:'GET',
		url:'services/get_streetpos.php?id='+id+'&lat='+lat+'&lng='+lng,
		success:function(data){
			var pos = ps.map.fromLatLngToContainerPixel(new google.maps.LatLng(lat,lng));
			
			if(data > 0 && data < 999999)
				showStreet({id:id,x:data,y:1},{x:pos.x,y:pos.y});
			else
				showStreet({id:id},{x:pos.x,y:pos.y});
				
			hideLoading();
		},
		error:function(){
			ps.setActiveStreet(-1);
			hideLoading();
		}
	});
}
function showStreet(options, mousePos){
	if(options.id == undefined) return;
	if(options.business == undefined || !options.business) options.business = 0;
	if(options.x == undefined || !options.x) options.x = 0;
	if(options.y == undefined || !options.y) options.y = 0;
	if(options.zoom == undefined || !options.zoom) options.zoom = 0;
	
	if($("#streetContainer").css("display") == "none"){
		var h = $(".main").height();
		var sh = parseInt(h * g_streetHeight);		
		if(mousePos != undefined && mousePos.x != undefined && mousePos.y != undefined){
			$("#streetFrame").html("");
			$("#streetContainer").css({"left":mousePos.x,"top":mousePos.y,"width":0,"height":0});
			$("#streetContainer").show();

			$("#streetContainer").animate({left:0,top:0,width:"100%",height:sh+"px"}, 300, function(){
				resize();
				insertStreetFlash(options);
			});
		}else{
			$("#streetContainer").css({left:0,top:0,width:'100%',height:sh});
			$("#streetContainer").show();
			resize();
			insertStreetFlash(options);
		}
		ps.useSmallMapControl();
	
		if(window.addEventListener)
			$("#streetContainer").bind("DOMMouseScroll", wheelHandler);
		$("#streetContainer").bind("mousewheel", wheelHandler);
					
	}else{
		var s = getStreet()
		if(s) s.showStreet(options.id, options.business, options.x, options.y, options.zoom);
	}
	$.cookie("laststreet",options.id+","+options.x+","+options.y, {expires:15,path:'/'});
}
function hideStreet(noanimation){
	if(noanimation == undefined) noanimation=false;
	var latlng = ps.getStreetPosMarkerLatLng();
	if(noanimation != true && latlng){
		var h = $(".main").height() - $("#mainBanner").height();
		$("#mapContainer").height(h);
		$("#mapContainer").css("top", 0);
		var pos = ps.map.fromLatLngToContainerPixel(latlng);
		$("#streetContainer").animate({left:pos.x,top:pos.y,width:"0",height:"0"}, 300, function(){
			$("#streetContainer").css("display","none");//hide();
			if(g_isFullView){
				if(g_panelVisibleSaved) showPanel();					
				g_isFullView = false;
			}
			resize();
			ps.setActiveStreet(-1);
		});
	}else{
		$("#streetContainer").css("display","none");//hide();
		if(g_isFullView){
			if(g_panelVisibleSaved) showPanel();					
		}
		resize();
		ps.setActiveStreet(-1);
		g_isFullView = false;
	}
	$("#streetButtons a[rel='maximize']").show();
	$("#streetButtons a[rel='restore']").hide();
	ps.useLargeMapControl();
	if(window.addEventListener)
		$("#streetContainer").unbind("DOMMouseScroll", wheelHandler);
	$("#streetContainer").unbind("mousewheel", wheelHandler);
	$("#streetFrame").html('');

	$.cookie("laststreet", null);
}
function insertStreetFlash(options){
	if(options.id == undefined) return;
	if(options.business == undefined) options.business='';
	if(options.x == undefined) options.x='';
	if(options.y == undefined) options.y='';
	if(options.zoom == undefined) options.zoom='';

	var s = AC_FL_RunContent2( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
	'flashvars', 'id='+options.id+'&business='+options.business+'&x='+options.x+'&y='+options.y+'&zoom='+options.zoom,
	'width','100%','height','100%','id','street','align','middle','src','street','quality','high','wmode','transparent','bgcolor','#ffffff','name','street','allowscriptaccess','always','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../street' ); //end AC code
	document.getElementById("streetFrame").innerHTML = s;
	//$("#streetFrame").html(s);
}
function wheelHandler(event){
	var delta = 0;
	if (!event) /* For IE. */
	        event = window.event;
	if (event.wheelDelta) { /* IE/Opera. */
	        delta = event.wheelDelta/120;
	        /** In Opera 9, delta differs in sign as compared to IE. */
	        if (window.opera)
	                delta = -delta;
	} else if (event.detail) { /** Mozilla case. */
	        /** In Mozilla, sign of delta is different than in IE.
	         * Also, delta is multiple of 3.*/
	        delta = -event.detail/3;
	}
	/** If delta is nonzero, handle it.
	 * Basically, delta is now positive if wheel was scrolled up,
	 * and negative, if wheel was scrolled down. */
	if (delta)
	        handleWheel(delta, event.ctrlKey);
			
	/** Prevent default actions caused by mouse wheel.
	 * That might be ugly, but we handle scrolls somehow
	 * anyway, so don't bother here..*/
	if (event.preventDefault)
	        event.preventDefault();
	event.returnValue = false;	
}
function handleWheel(delta, ctrl) {
	var s = getStreet();
	if(!s) return;
	
	if(ctrl){ // zoom
		if(delta > 0)
			s.setZoom(document.street.getZoom() + 0.1);
		else
			s.setZoom(document.street.getZoom() - 0.1);			
	}else // scroll
		s.mouseWheel(delta);
}
function showBusiness(business,markerIcon,lat,lng){
	if(lat!=undefined && lng !=undefined)
		ps.map.panTo(new google.maps.LatLng(lat, lng));
	
	showLoading();
	$.ajax({
	type:"GET",
	url:"./services/find_businessoverlay.php?id="+business,
	success:function(response){
		var r = response.split("\t");
		if (r[0] == 0) {
			hideStreet(true);
			if(markerIcon != undefined && markerIcon=='default')
				ps.showBusinessMarker(business, r[1],parseFloat(r[2]),parseFloat(r[3]), false,{src:"images/marker1.png",width:47,height:38,offsetX:7,offsetY:34});
			else if(markerIcon){
				ps.showBusinessMarker(business, r[1],parseFloat(r[2]),parseFloat(r[3]),true,markerIcon);
				//ps.map.panTo(new google.maps.LatLng(parseFloat(r[2]),parseFloat(r[3])));
			}
			ps.rearrangeMarkers('search',business);

		}else {
			showStreet({id:r[0],business:business},{lat:parseFloat(r[2]),lng:parseFloat(r[3])});	
			if(markerIcon != undefined && markerIcon == 'default') ps.showBusinessMarker(business, r[1],parseFloat(r[2]),parseFloat(r[3]), false,{src:"images/marker1.png",width:47,height:38,offsetX:7,offsetY:34});
			else if(markerIcon){
				ps.showBusinessMarker(business, r[1],parseFloat(r[2]),parseFloat(r[3]),true,markerIcon);
				//ps.map.panTo(new google.maps.LatLng(parseFloat(r[2]),parseFloat(r[3])));				
			} 
			ps.rearrangeMarkers('search',business);
		}
		hideLoading();
	},error:function(a,b){
		hideLoading();
	}		
	});
	//e("fstreet").contentWindow.document.street.showBusiness(business);
}
function showBusiness2(id){
	var s = getStreet();
	if(s) s.showBusiness(id,'default');
}

// STREET EVENTS
function streetOnShow(streetid, business, x, y, zoom){
	ps.setActiveStreet(streetid);
//	if(e("stores").style.display == "")
//		e("ifstores").src = "menustores.php?s=" + streetid + "&c=0";
		
	if(g_init != undefined && streetid == g_init.street && g_init.business > 0){
		setTimeout("popupInitBusiness()", 1000);
	}	
	// log
	if(business == undefined) business = 0;
	if(x == undefined) x = 0;		
	saveLog('/street.php', streetid, business, x);
}
function popupInitBusiness(){
	popupBusiness(g_init.business, '');		
	//g_init.business = -1;
	g_init = null;
}
function streetOnBusinessOver(id, name,lat,lng){
	ps.showBusinessMarker(id, name, lat, lng, false, {src:"images/marker1.png",width:47,height:38,offsetX:7,offsetY:34});
}
function streetOnBusinessOut(){
	ps.hideBusinessMarker();
}
function streetOnBusinessClick(id,name){
	popupBusiness(id, name);	
}
function streetOnLinkOver(linkid){
	ps.setStreetHot(linkid, true);
}
function streetOnLinkOut(linkid){
	ps.setStreetHot(linkid, false);	
}
function streetOnScroll(street, lat, lng){
	ps.map.setCenter(new google.maps.LatLng(lat,lng));
	ps.setStreetPosMarker(new google.maps.LatLng(lat,lng));
	
	var s = getStreet();
	if(s){
		$.cookie("laststreet",s.getStreetID()+","+s.getXPos()+","+s.getYPos(), {expires:15,path:'/'});
	}	
}
// STREET FUNCTIONS
function streetZoomIn(){
	var s = document.street||document.getElementById("street");
	var z = s.getZoom() + 0.2;
	s.setZoom(z);
}
function streetZoomOut(){
	var s= document.street||document.getElementById("street");
	var z = s.getZoom() - 0.2;
	s.setZoom(z);
}
function streetWhiteLayer(){
	var s = getStreet();
	if(s)
		s.showWhiteLayer();
}

function getStreet(){
	if($("#streetContainer").css("display") == "none") return null;
	else return document.street ? document.street : document.getElementById("street");
}
function getStreetId(){
	var result = 0;
	var s = getStreet();
	if(s && s.getStreetID)
		result = s.getStreetID();
	return result;
}
function popupBusiness(business, name){
	$.fn.colorbox({
		iframe: true,
		href: "business.php?id="+business,
		width: "800px",
		height: "665px",
		open: true,
		title: name,
		/*cbox_complete: popupDrag2,*/
		speed: 200
	});		
}
function gotoEditorPage(){
	var center = ps.map.getCenter();
	window.location.href = "./editor.php?lat=" + center.lat() + "&lng=" + center.lng();
}
function showBusinessList(streetid){
	var s = e("stores");
	e("ifstores").src = "menustores.php?s=" + streetid + "&c=0";

	s.style.left = "0px";
	s.style.top = "22px";
	s.style.height = (parseInt(e("streetc").style.height) - 22 - 18) + "px";
	s.style.width = "200px";
	s.style.display = "";
	
	saveLog('businessesOnStreet');
}
function hideStoreList(){
	e("stores").style.display = "none";
	e("ifstores").src = "";
}
function getURLParam(){
	var center = ps.map.getCenter();
	var param = "lat="+center.lat()+"&lng="+center.lng()+"&maplevel="+ps.map.getZoom();
	var s = getStreet();
	if (s) {
		param += "&s=" + s.getStreetID();
		param += "&sx=" + s.getXPos();
		param += "&sy=" + s.getYPos();
		param += "&sz=" + s.getZoom();
	}
	return param;	
}
function getURL(page){
	if(page==undefined) page ='';
	var center = ps.map.getCenter();
	var url = "http://"+location.host+"/"+page+"?lat="+center.lat()+"&lng="+center.lng()+"&maplevel="+ps.map.getZoom();
	var s = getStreet();
	if (s) {
		url += "&s=" + s.getStreetID();
		url += "&sx=" + s.getXPos();
		url += "&sy=" + s.getYPos();
		url += "&sz=" + s.getZoom();
	}
	return url;
}
function showCurrURL(){
	if(!ps || !ps.map){
		$.jGrowl("Map is not loaded yet.<br />Please try after map is loaded.", {life:3000,closeTemplate:"x"});
		return;
	}
	if($("#p_url").css("display") == "none"){
		$("#p_url").css("top", $(".top").height());
		//$("#p_url").css("left", $(window).width() - $("#p_url").width());
		$("#p_url").show();
		$("#pu_urltext").val(getURL());
		$("#pu_urltext").select();
		$("#pu_urltext").focus();
	}else
		hideCurrURL();
}
function hideCurrURL(){
	$("#p_url").hide();
}
function mapLabelClick(id){
//	alert(id);
}
function mapMoved(sender){
	var center = ps.map.getCenter();
	$.cookie("lastmappos",center.lat()+","+center.lng()+","+ps.map.getZoom(), {expires:15,path:'/'});
	if($("#streetContainer").css("display") == "none")
		$.cookie("laststreet", null);
}

// SEARCH
function setSearchTarget(target){
	if(target==0){ //business
		g_searchTarget = 0;
		$(".searchbox .target a:eq(0)").addClass("on");
		$(".searchbox .target a:eq(1)").removeClass("on");
		$(".searchbox .option .caption:eq(0)").html("What:");
		$(".searchbox .option .caption:eq(1)").html("Where:");
	}else if(target==1){ // street		
		g_searchTarget = 1;
		$(".searchbox .target a:eq(0)").removeClass("on");
		$(".searchbox .target a:eq(1)").addClass("on");
		$(".searchbox .option .caption:eq(0)").html("Name:");
		$(".searchbox .option .caption:eq(1)").html("City:");
	}
	$(".searchbox input[name='what']").val('');
	$(".searchbox input[name='where']").val('');
	$(".searchbox input[name='what']").focus();
	
	autosuggest();
}
function search(page,log){
	if(!ps || !ps.map){
		 $.jGrowl("Map is not loaded yet.<br />Please try after map is loaded.", {life:3000,closeTemplate:"x"}); return;
	}
	g_autosuggest.clearSuggestions();
	if(page == undefined || !page) page=1;	
	var url="services/get_search.php?";
	var what = $(".searchbox input[name='what']").val();
	var where = $(".searchbox input[name='where']").val();
	if(what.length == 0){
		 $.jGrowl("Please, type some keywords.", {life:3000,closeTemplate:"x"}); return;
	}
	if(g_searchTarget == 0){
		url += "target=business&what="+encodeURIComponent(what)+"&where="+encodeURIComponent(where)+"&page="+page;
	}else if(g_searchTarget == 1){
		url += "target=street&what="+encodeURIComponent(what)+"&where="+encodeURIComponent(where)+"&page="+page;
	}
	var mc = ps.map.getCenter();
	url += "&lat="+mc.lat()+"&lng="+mc.lng();
	showPanelLoading();
	hidePanelInfo();
	$.ajax({
		type:'GET',
		url:url,
		dataType:'json',
		success:function(data){
			g_autosuggest.clearSuggestions();
			$(".searchbox").slideUp(200,function(){
				$(".searchtitle .title").html("<strong>"+what+"</strong>"+(where.length > 0 ? " near <strong>"+where+"</strong>" : ''));
				if(data.list.length > 0){
					var begin = (data.page - 1) * data.resultcount + 1;
					$(".searchresult .header").html('Results <strong>'+begin+' - '+(begin+data.list.length) + '</strong> of <span class="count">'+data.totalcount+'</span>');
				}else
					$(".searchresult .header").html('');
					
				$(".searchtitle").show();
				$(".searchresult .searchtags").hide();
				$(".searchresult").css("top",$(".searchtitle").height() + 1);
				$(".searchresult .list").show();
				$(".searchresult .header").show();
				$(".searchresult .paging").show();	

				resize(); // for IE6
				hidePanelLoading();				
				processSearchResult(data);
				
				if(log!=undefined && log){
					var im = new Image();
					target = g_searchTarget==0 ? 'business':'street';
					im.src = "log/searchlogwriter.php?t="+target+"&q="+ encodeURIComponent(what)+"&q2="+encodeURIComponent(where);	
					im.onload = function(){return;};
				}
			});
		},
		error:function(a,b){
			g_autosuggest.clearSuggestions();
			hidePanelLoading();
		}
	});
}
function adjustMapView(markersData){
	if(markersData.length == 0) return;
	ps.map.panTo(new google.maps.LatLng(markersData[0].lat,markersData[0].lng));
}
function processSearchResult(data){
	var list = data.list;
	var html = '';
	var item, bg;
	var markers = [];
	var icon;
	
	if(data.target=='business'){
		for(var i=0; i < list.length; i++){
			item = list[i];
			//bg = 'background:url(images/bullet_'+item.color+'.gif) no-repeat 2px 4px';
			bg = 'background:url(images/map/marker_'+(i+1)+'.png) no-repeat 2px 0px';
			icon = "null";//"{src:'images/map/marker_"+(i+1)+".png',width:25,height:37,offsetX:12,offsetY:34}";
			html += '<li><div class="info" style="'+bg+'"><div class="title"><span class="caption" onclick="showBusiness('+item.id+','+icon+',\''+item.lat+'\',\''+item.lng+'\');">'+item.name+'</span> - <span class="more" onclick="popupBusiness('+item.id+')">more info &raquo;</span></div>';
			html += '<div class="detail">'+item.address;
			if(item.address_detail.length > 0)
				html += ', '+item.address_detail;
			if(item.tel.length > 0)
				html += ' - <span class="tel">'+item.tel+'</span>';
			html += '</div></div></li>';

			icon = new google.maps.Icon();
			icon.image = "images/map/marker_"+(i+1)+".png";
			icon.iconSize = new google.maps.Size(25, 37);
			icon.iconAnchor = new google.maps.Point(12, 34);
			markers.push({id:item.id,lat:item.lat,lng:item.lng,name:item.name,icon:icon});
		}
		ps.clearMarkers();
		ps.addMarkers('search',markers);
		adjustMapView(markers);
	}else if(data.target=='street'){
		for(var i=0; i < list.length; i++){
			item = list[i];
			html += '<li><div class="info"><div class="title"><span class="caption" onclick="showStreet({id:'+item.id+'})">'+item.name+'</span></div>';
			html += '<div class="detail">'+item.city+' &gt; '+item.region;		
			html += '</div></div></li>';
		}
	}
	if(list.length == 0){
		html = '<div style="margin-left:5px;"><b> &nbsp;  <font color="#fa7d02" size="3">No results found</font></b><font color="#5F5F5F"> <br> &nbsp; Sorry, no matches were found.<br> &nbsp;  Check for typos, or try these alternatives...</font><br><br>  &nbsp; <b>Search for a business name, e.g.</b><br> &nbsp; <a href="http://www.showstreet.com/?b=128" target="_parent">Barkers</a><br>  &nbsp; <a href="http://www.showstreet.com/?b=1783" target="_parent">Harvey Norman</a><br>  &nbsp; <a href="http://www.showstreet.com/?b=1753" target="_parent">Japanese Restaurants </a><br><br> &nbsp;<b> Search for an address or landmark, e.g. </b><br> &nbsp; <a href="http://www.showstreet.com/?lat=-36.78507241772236&lng=174.77331655946105&maplevel=18&s=1292&sx=752&sy=245&sz=0.65625" target="_parent">Takapuna</a> <br> &nbsp; <a href="http://www.showstreet.com/?lat=-36.77223220933782&lng=174.76392813632276&maplevel=18&s=204&sx=782&sy=192&sz=0.8359375" target="_parent">Milford</a> <br> &nbsp; <a href="http://www.showstreet.com/?lat=-36.84680576296401&lng=174.76588808563233&maplevel=18&s=583&sx=13941&sy=362&sz=0.5078125" target="_parent">Queen St</a></div>';			
	}
	$(".searchresult .list").html(html);

	// paging
	$(".searchresult .paging").html(getPagingHTML(data.page, data.totalpage,'search'));
	
	$(".searchresult li").mouseover(function(){
		$(this).addClass("hot");
	}).mouseout(function(){
		$(this).removeClass("hot");
	})
	$(".searchresult").scrollTop(0);
}
function getPagingHTML(page,totalpage,module){
	var b, e;
	b = page - 4;
	if(b < 1) b = 1;
	e = b + 7;
	if(e > totalpage) e = totalpage;
	html = '<table width="1%" border="0" cellpadding="0" cellspacing="0" align="center"><tr>';
	if(page > 1) html += '<td><span class="page" onclick="'+module+'('+(page-1)+');">Prev</span></td>';
	for(var i=b; i <= e; i++){
		if(i == page)
			html += '<td><span class="currpage">'+i+'</span></td>';
		else
			html += '<td><span class="page" onclick="'+module+'('+i+');">'+i+'</span></td>';
	}
	if(page < totalpage) html += '<td><span class="page" onclick="'+module+'('+(page+1)+');">Next</span></td>';
	html += '</tr></table>';

	return html;	
}
function closeSearchResult(){
	$(".searchtitle").hide();
	
	$(".searchresult").css("top", 100);
	$(".searchresult .list").html('');
	$(".searchresult .header").html('');
	$(".searchresult .paging").html('');
	$(".searchresult .list").hide();
	$(".searchresult .header").hide();
	$(".searchresult .paging").hide();	
	$(".searchbox").slideDown(200,function(){
		$(".searchresult .searchtags").show();
	});
	
	ps.clearMarkers('search');	
}
function showPanelLoading(){	
	$(".panelc .ploading").css({left:($(".panelc").width() - $(".panelc .ploading").width()) / 2,top:($(".panelc").height() - $(".panelc .ploading").height()) / 2});
	$(".panelc .ploading").show();
}
function hidePanelLoading(){
	$(".panelc .ploading").hide();
}
function showPanelInfo(){
	if($(".bottom .infobtn").hasClass('opened')){
		hidePanelInfo(); return;
	}
	$(".bottom .infobtn").addClass('opened');
	$("#panel .panelinfo").slideDown(500);	
}
function hidePanelInfo(){
	$('#panel .panelinfo').slideUp(300);
	$(".bottom .infobtn").removeClass('opened');
//	$(".bottom .infobtn").show();
}

function showServiceArea(){	
	if($("#p_area").css("display") != "none")
		hideServiceArea();
	else{
		if($("#p_area").html().length > 0){
			$("#p_area").slideDown("fast");
		}else{
			$.ajax({
				type:'GET',
				url:'arealist.js',
				success:function(data){
					eval(data);
					var a;
					var html = '<table border="0" cellpadding="0" cellspacing="0"><tr>';
					for(var i = 0; i < areas.length; i++){
						if(i % 12 == 0 || i == 0)
							html += '<td valign="top">';
						html += '<div class="area" onclick="gotoArea('+areas[i].lat+','+areas[i].lng+');">'+areas[i].name.replace("&gt;",'&gt; <span class="sub">')+'</span></div>';
						if(i > 0 && (i % 12 == 11 || i == areas.length - 1))
							html += '</td>';
					}
					html += '</tr></table>';
					$("#p_area").html(html);
					var t="";
					$("#p_area .area").hover(function(){$(this).addClass("hot");$("span",this).addClass("hot");}, function(){$(this).removeClass("hot");$("span",this).removeClass("hot");});
					$("#p_area").slideDown("fast");
				}
			});
		}
		$("#servicearea img").attr("src","images/pullup.gif");
	}
}
function hideServiceArea(noanimation){
	$("#servicearea img").attr("src","images/pulldown.gif");
	if(noanimation == true)
		$("#p_area").hide();
	else
		$("#p_area").slideUp("fast");
}
function gotoArea(lat,lng){
	var latlng = new google.maps.LatLng(lat, lng);

	if(latlng != null){
		ps.map.setCenter(latlng);
		hideStreet();
		// this function has been added so that the street is not visible in the event of change area 25.sep.09
	}
}
function setPanel(index){
	if(g_panelIndex == 1 && index == 1 && $(".searchtitle").css('display')!='none'){
		closeSearchResult();
		return;
	}
	if(g_panelIndex == index) return;	
	if(g_panelIndex == 2) ps.clearMarkers('editing');
	
	$(".panelc .pcontent").each(function(i){
		$(this).hide();
	});
	$("#panel"+index).show();
	g_panelIndex = index;
		
	$("#panel .menu li").removeClass("on");
	$("#panel .menu li:eq("+(index-1)+")").addClass("on");
	
	if(g_panelIndex == 2)
		refreshMyBusinesses();
}
function streetHelp(){
	if($("#streetContainer .streetHelp").css("display") == 'none'){
		$("#streetContainer .streetHelp").slideDown(500);	
	}else{
		$("#streetContainer .streetHelp").slideUp(300);	
	}	
}
function closePopup(){
	$.fn.colorbox.close();	
}
function popupSpot(id){
	$.fn.colorbox({
		iframe: true,
		href: "spot.php?id="+id,
		width: "550px",
		height: "500px",
		open: true,
		title: '',
		cbox_complete: popupDrag2,
		speed: 200
	});
}
function popupVideo(id){
	$.fn.colorbox({
		iframe: true,
		href: "video.php?id="+id,
		width: "550px",
		height: "530px",
		open: true,
		title: '',
		cbox_complete: popupDrag2,
		speed: 200
	});
}
function autosuggest() {
    var target = (g_searchTarget==0 ? 'business':'street');
    g_autosuggest = new bsn.AutoSuggest('searchwhat', {
		script: function (input){ 
			return "autosuggest.php?t="+target+"&input="+encodeURIComponent(input)+"&limit=15"; 
		},
		varname:"input",
		minchars:2,
		timeout:3000
	});
}
function mapMarkerClick(type,id){
	if(type=='business')
		popupBusiness(id);
}
function openPrintPage(){
	var wnd = window.open(getURL('print.php'), "print","resizable=1,scrollbars=1,toolbar=0,height=700,width=670",false);
	wnd.focus();
}
function openEmbed(){
	var params = encodeURIComponent(getURLParam());
	var wnd = window.open("pembed.php?params="+params,"SHOWSTREETEMBED","resizable=1,scrollbars=1,toolbar=0,height=550,width=600",false);
	wnd.focus();
}
