var imGMapObj=null,imStreetViewPoint=[],from_htmls=[],to_htmls=[],imMapObj={},imSVOverlay=null,imGeocodeRequestDelay=null;function imLatLngs(a,f,c,h,e,i,k,p){this.latlngLoc=a;this.format_adr=f;this.adr_comp=c;this.bus_name=h;this.phone=e;this.url=i;this.desc=k;this.images=p}function imIconOptions(a){this.icon_options=a}
(function(a){a.fn.extend({imGoogleMaps:function(f){opts=a.extend({},a.googleMaps.defaults,f);return this.each(function(){new a.googleMaps(this,opts)})}});a.googleMaps=function(f,c){function h(){imMapObj.mapId=c.map;imMapObj.streetId=c.street_view;v.append(a("<div></div>").attr("id",c.map));if(c.instructions){if(c.instructions.location=="top"){var b=c.map;a("<div></div>").attr("id",c.instructions.container).html(c.instructions.label).insertBefore("#"+b)}else a("<div></div>").attr("id",c.instructions.container).html(c.instructions.label).insertAfter("#"+
c.map);a("<div></div>").attr("id",c.instructions.container).html(c.instructions.label)}c.street_view&&(a("<div></div>").attr("id","imStreetViewClose").append(a("<a></a>").attr({id:"imStreetCloseBtn",title:"Exit Street View"}).append(a("<img></img>").attr("src",c.street_close_loc))).insertAfter("#"+c.map),a("<div></div>").attr("id",c.street_view).insertAfter("#imStreetViewClose"),a("#imStreetCloseBtn").click(function(){toggleStreetView(-1)}))}function e(){var b;b=new google.maps.LatLng(0,0);var j=
{};j.zoom=c.zoom_level?c.zoom_level:1;j.center=b;j.mapTypeId=google.maps.MapTypeId.ROADMAP;if(c.show_streetview_overlay)j.streetViewControl=!0;imGMapObj=new google.maps.Map(document.getElementById(c.map),j);c.show_traffic&&(b=new google.maps.TrafficLayer,b.setMap(imGMapObj));c.show_bicycling&&(b=new google.maps.BicyclingLayer,b.setMap(imGMapObj));c.data_type=="layer"&&(b=new google.maps.KmlLayer(c.data_url),b.setMap(imGMapObj));if(c.show_more_button)b=c.show_traffic,j=c.show_bicycling,b=[{name:"Traffic",
obj:new google.maps.TrafficLayer,checked:b},{name:"Bicycling",obj:new google.maps.BicyclingLayer,checked:j}],j=document.createElement("DIV"),new imGMapMoreControl(j,b),j.index=1,imGMapObj.controls[google.maps.ControlPosition.TOP_RIGHT].push(j),a("#imGMapChkControl0").live("click",function(){i(this,"traffic")}),a("#imGMapChkControl1").live("click",function(){i(this,"bicycle")});q=new google.maps.Geocoder;return!0}function i(b,c){var a;b.checked?(c=="traffic"?a=new google.maps.TrafficLayer:c=="bicycle"&&
(a=new google.maps.BicyclingLayer),w=a,a.setMap(imGMapObj)):w.setMap(null)}function k(b){var j,m;if(d.is_layer)j=1,m=d.address;else if(d[b].is_layer_url)j=d.length,m=d[b].address;(new google.maps.KmlLayer(m)).setMap(imGMapObj);b++;c.progress_bar&&a(window).trigger("updateProgress");b<j?imGeocodeRequestDelay=setTimeout(function(){p(b)},1E3):clearTimeout(imGeocodeRequestDelay)}function p(b){var j,m,e,g,f,r,n,h="";d.is_layer||d[b].is_layer?k(b):(d.lat?(j=new GLatLng(d.lat,d.lng),n=1):d.address?(n=1,
j=d.address,m=d.name?d.name:"",m=d.business_name?d.business_name:m,e=d.phone?d.phone:"",g=d.url?d.url:"",f=d.desc?d.desc:"",r=d.images?d.images:"",h=d.custom_marker?d.custom_marker:""):d[0].address?(n=d.length,j=d[b].address,m=d[b].name?d[b].name:"",m=d[b].business_name?d[b].business_name:m,e=d[b].phone?d[b].phone:"",g=d[b].url?d[b].url:"",f=d[b].desc?d[b].desc:"",r=d[b].images?d[b].images:"",h=d[b].custom_marker?d[b].custom_marker:""):d[0].lat?(n=d.length,j=new GLatLng(d[b].lat,d[b].lng)):(j=d,n=
1),q.geocode({address:j},function(d,i){i==google.maps.GeocoderStatus.OK?(s[b]=new imLatLngs(d[0].geometry.location,d[0].formatted_address,d[0].address_components[0],m,e,g,f,r),h&&(t[b]=h),b++,c.progress_bar&&a(window).trigger("updateProgress"),b<n?imGeocodeRequestDelay=setTimeout(function(){p(b)},c.geocode_request_rate):(clearTimeout(imGeocodeRequestDelay),z())):alert("Sorry, we are unable to gecode address: "+j+" for the following reason: "+i)}))}function u(b){if(q){var j;j=0;j=b.lat||b.address?
1:b[0].address?b.length:1;d=b;c.progress_bar&&a(window).trigger("startProgress",[j]);p(0)}}function z(){var b=new google.maps.LatLngBounds;a.each(s,function(c,a){var d=a.latlngLoc;A(d,c,a.format_adr,a.adr_comp,a.bus_name,a.phone,a.url,a.desc,a.images);b.extend(d)});imGMapObj.fitBounds(b);imGMapObj.setCenter(b.getCenter())}function A(b,a,c,d,g,e,f,n,h){var i=B(a,b),l=new google.maps.Marker(i);google.maps.event.addListener(l,"click",function(){var i={content:C(b,a,c,d,g,e,f,n,h)};(new google.maps.InfoWindow(i)).open(imGMapObj,
l)});return l}function C(b,d,e,f,g,h,i,n,x){var o="";f=f.street_address?f.street_address+"<br />"+f.locality+", "+f.administrative_area_level_1+" "+f.postal_code:e;h&&(f+="<br />"+h);h=y(i,"add");i&&c.show_infowindow_url&&(f+='<br /><a href="'+h+'" target="_blank" class="infoWindowUrl">'+y(i,"remove")+"</a>");n&&(f+='<br /><span class="infoWindowDescription">'+n+"</span>");g&&(o='<span class="infoWindowBusinessName">'+g+"</span><br />",i&&c.show_infowindow_url==!1&&(o='<span class="infoWindowBusinessName"><a href="'+
h+'" target="_blank">'+g+"</a></span><br />"));g='<p class="infoWindowStreetAddress">';g+=o+f;c.street_view&&(imStreetViewPoint[d]=b,g+='<br /><a href="javascript:void(0)" onclick="toggleStreetView('+d+');">Street View</a>');c.show_directions&&(g+='<br /><span id="imDirectionsSearchCntnr'+d+'">Directions: <a href="javascript:showDirectionsToSearch('+d+')">To here</a> - <a href="javascript:showDirectionsFromSearch('+d+')">From here</a></span>',to_htmls[d]='Start Address:<form action="javascript:imGMapDirections.getDirections()"><input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br><select id="imdir-travel-mode"><option value="DRIVING">Driving</option> <option value="WALKING">Walking</option><option value="BICYCLING">Bicycling</option></select><INPUT value="Show Directions" TYPE="SUBMIT"><br><input type="hidden" id="daddr" value="'+
e+'"/><br /> <a href="javascript:showDirectionsFromSearch('+d+')">Get Directions From Here</a>',from_htmls[d]='End Address:<form action="javascript:imGMapDirections.getDirections()"><input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br><select id="imdir-travel-mode"><option value="DRIVING">Driving</option> <option value="WALKING">Walking</option><option value="BICYCLING">Bicycling</option></select><INPUT value="Show Directions" TYPE="SUBMIT"><br><input type="hidden" id="saddr" value="'+
e+'"/><br /> <a href="javascript:showDirectionsToSearch('+d+')">Get Directions To Here</a>');if(x){var l="",k="";a.each(x,function(a,b){var c=b.class_name?'class="'+b.class_name+'" ':"";k=b.width&&itme.height?"<img "+c+'src="'+b.image_loc+'" width='+b.width+" height="+b.height+" />":"<img "+c+'src="'+b.image_loc+" />";l+=b.url?'<a href="'+b.url+'" target="_blank">'+k+"</a>":k;b.new_line&&(l+="<br />")});g+="<br />"+l+"</p>"}else g+="</p>";return g}function y(b,a){var c=b;b.length!=0&&(a=="add"?b.substr(0,
7)!="http://"&&(c="http://"+b):a=="remove"&&b.substr(0,7)=="http://"&&(c=b.substr(7,b.length)));return c}function B(b,a){var d,f,g;d="http://chart.apis.google.com/chart?chst=";var e,h,i,k,o;if(t.length!=0)g=t[b][0];else if(c.custom_marker)g=c.custom_marker;else return{draggable:c.draggable,position:a,map:imGMapObj};o=g.icon_color?g.icon_color.replace("#",""):"FD766A";f=g.star_color?g.star_color.replace("#",""):"FFFFFF";i=s.length>99?"+":g.label=="alpha"?String.fromCharCode("A".charCodeAt(0)+b):b;
k=g.label_color?g.label_color.replace("#",""):"000000";h="|"+o;if(g.type=="standard"){h+="|"+k;o=g.star_color?d+"d_map_xpin_letter&chld=pin_star|":d+"d_map_pin_letter&chld=";o+=i+h;g.star_color?(e=23,h=39,i=45,k=42,o+="|"+f):(e=21,h=34,i=40,k=37);f=g.star_color?d+"d_map_xpin_shadow&chld=pin_star":d+"d_map_pin_shadow";d=new google.maps.MarkerImage(o,new google.maps.Size(e,h),new google.maps.Point(0,0),new google.maps.Point(e/2,h));f=new google.maps.MarkerImage(f,new google.maps.Size(i,k),new google.maps.Point(0,
0),new google.maps.Point(0,k));i=h;h=[];var l;switch(g.type){case "standard":h=[e/2,i,0.4375*e,0.625*i,0.3125*e,0.4375*i,0.21875*e,0.3125*i,0.3125*e,0.125*i,0.5*e,0,0.6875*e,0.125*i,0.78125*e,0.3125*i,0.6875*e,0.4375*i,0.5625*e,0.625*i];for(g=0;g<h.length;g++)h[g]=parseInt(h[g]);l={coord:h,type:"poly"};break;case "flat":g=Math.min(e,i)/2;for(l=0;l<9;l++)e=45*l*(Math.PI/180),i=g+g*Math.sin(e),h.push(parseInt(g+g*Math.cos(e)),parseInt(i));l={coord:h,type:"circle"}}return{icon:d,shadow:f,shape:l,draggable:c.draggable,
position:a,map:imGMapObj}}else if(g.type=="flat")return e=g.width?g.width:32,h=g.height?g.height:32,labelSize=g.label_size?g.label_size:14,g=g.shape?g.shape:"circle",d=new google.maps.MarkerImage("http://chart.apis.google.com/chart?cht="+(g=="circle"?"it":"itr")+"&chs="+e+"x"+h+("&chco="+o+",000000ff,ffffff01")+"&chl="+(i=="+"?"":i)+"&chx="+k+","+labelSize+"&chf=bg,s,00000000&ext=.png",new google.maps.Size(e,h),new google.maps.Point(0,0),new google.maps.Point(e/2,h/2)),{icon:d,draggable:c.draggable,
position:a,map:imGMapObj};else if(g.type=="user_image")return d=g.width&&g.height?new google.maps.MarkerImage(g.image_loc,new google.maps.Size(g.width,g.height),new google.maps.Point(0,0),new google.maps.Point(g.width,g.height/2)):new google.maps.MarkerImage(g.image_loc),{icon:d,draggable:c.draggable,position:a,map:imGMapObj}}function D(){var b="";c.data&&(a.each(c.data,function(a,c){b+=c.name+"="+c.value+"&"}),b=b.substr(0,b.length-1));return b}var q,w,v=a(f),s=[],t=[],d="";(function(){h();e();if(c.data_type!=
"layer")if(c.progress_bar&&v.imProgressBar({progress_bar:{container:c.progress_bar.container,bar_back_class:c.progress_bar.bar_back_class,bar_class:c.progress_bar.bar_class},display:{type:"inline",insert_type:"before",element:"#"+c.map},animate_duration:1500}),c.data_url){var b=D();a.ajax({type:"GET",url:c.data_url,data:b,dataType:c.data_type,beforeSend:"",success:u})}else c.address?u(c.address):c.lat_lng?u(c.lat_lng):alert("Address must be specified!")})()};a.googleMaps.defaults={data_url:"",data:"",
data_type:"json",address:"",map:"",lat_lng:"",show_directions:!0,draggable:!1,street_view:"",street_close_loc:"",show_streetview_overlay:!1,show_traffic:!1,show_bicycling:!1,show_more_button:!1,progress_bar:"",geocode_request_rate:500,custom_marker:"",instructions:{container:"googInstruct",label:"Click on the marker to get directions",location:"top"},zoom_level:"",show_infowindow_url:!0}})(jQuery);
imGMapProgressBar=function(a,f,c){var h=document.createElement("DIV");h.setAttribute("class",f);f=document.createElement("DIV");f.setAttribute("class",c);f.setAttribute("id",c);f.style.width="0px";h.appendChild(f);a.appendChild(h)};function showDirectionsToSearch(a){document.getElementById("imDirectionsSearchCntnr"+a).innerHTML=to_htmls[a]}function showDirectionsFromSearch(a){document.getElementById("imDirectionsSearchCntnr"+a).innerHTML=from_htmls[a]}
var imGMapDirections={getSelectedTravelMode:function(){var a="",f=document.getElementById("imdir-travel-mode");f=f.options[f.selectedIndex].value;f=="DRIVING"?a=google.maps.DirectionsTravelMode.DRIVING:f=="BICYCLING"?a=google.maps.DirectionsTravelMode.BICYCLING:f=="WALKING"?a=google.maps.DirectionsTravelMode.WALKING:alert("Unsupported travel mode.");return a},getDirections:function(){var a=document.getElementById("saddr").value,f=document.getElementById("daddr").value;a={origin:a,destination:f,travelMode:this.getSelectedTravelMode(),
provideRouteAlternatives:!0};f=new google.maps.DirectionsService;var c=new google.maps.DirectionsRenderer;f.route(a,function(a,e){if(e!=google.maps.DirectionsStatus.OK)alert("Directions failed: "+e);else{var f=window.open("","w","width=600,height=500,scrollbars=yes,menubar=yes,location=no,status=no"),k=f.document.createElement("div");k.setAttribute("id","googDirections");k.style.width="600px";f.document.body.appendChild(k);c.setMap(imGMapObj);c.setPanel(f.document.getElementById("googDirections"));
c.setDirections(a)}})}};imGMapMoreControl.prototype.createCheckBox=function(a,f,c){var h;try{h=document.createElement(c?'<input type="checkbox" id="'+f+'" name="'+a+'" checked>':'<input type="checkbox" id="'+f+'" name="'+a+'">')}catch(e){h=document.createElement("input"),h.setAttribute("type","checkbox"),h.setAttribute("name",a),h.setAttribute("id",f),c&&h.setAttribute("checked","checked")}return h};
function imGMapMoreControl(a,f){var c=this,h=f.length,e=document.createElement("DIV");e.style.backgroundColor="white";e.style.width="6em";e.style.borderStyle="solid";e.style.borderWidth="1px";e.style.marginTop="6px";e.style.cursor="pointer";e.style.textAlign="center";e.title="Show/Hide Layers";var i=document.createElement("DIV");i.style.fontFamily="Arial,sans-serif";i.style.fontSize="12px";i.style.paddingLeft="4px";i.style.paddingRight="4px";i.innerHTML="<b>More...</b>";e.appendChild(i);a.appendChild(e);
e=document.createElement("DIV");e.setAttribute("id","imGMapCheckCntnr");e.style.position="absolute";e.style.top="24px";e.style.left="0px";e.style.marginTop="-1px";e.style.fontSize="12px";e.style.padding="6px 4px";e.style.width="120px";e.style.backgroundColor="#fff";e.style.color="#000";e.style.border="1px solid gray";e.style.borderTop="1px solid #e2e2e2";e.style.display="none";e.style.cursor="default";a.appendChild(e);for(i=0;i<h;i++)rd=this.createCheckBox("imGMapChkControl","imGMapChkControl"+i,
f[i].checked,f[i].obj),e.appendChild(rd),e.innerHTML+=f[i].name,i<h-1&&(e.innerHTML+="<br />");google.maps.event.addDomListener(a,"click",function(){c.toggleMenu()})}imGMapMoreControl.prototype.toggleLayer=function(a,f){a.checked&&f.setMap(imGMapObj)};imGMapMoreControl.prototype.toggleMenu=function(){var a=document.getElementById("imGMapCheckCntnr");a.style.display=a.style.display=="block"?"none":"block"};
function toggleStreetView(a){a==-1?(document.getElementById(imMapObj.streetId).style.display="none",document.getElementById("imStreetViewClose").style.display="none",document.getElementById(imMapObj.mapId).style.display="block"):(new google.maps.StreetViewService).getPanoramaByLocation(imStreetViewPoint[a],30,function(a,c){if(c=="OK"){document.getElementById(imMapObj.streetId).style.display="block";document.getElementById("imStreetViewClose").style.display="block";document.getElementById(imMapObj.mapId).style.display=
"none";var h={position:a.location.latLng,pov:{heading:0,pitch:0,zoom:1}};h=new google.maps.StreetViewPanorama(document.getElementById(imMapObj.streetId),h);imGMapObj.setStreetView(h)}else alert("Street View is not available for this location")})}$(document).ready(function(){$("ul#primary-nav li").click(function(){var a=$(this).find("a").attr("href");if(a!==window.location.pathname)window.location=a}).mouseover(function(){this.style.cursor="pointer"});$("#mapInfo").imGoogleMaps({address:"The Werks, 45 Church Road, Hove, BN3 2BE, UK"})});

