YUI.add("locations_map",function(b){function a(){a.superclass.constructor.apply(this,arguments)}b.extend(a,b.Base,{_map:null,_map_center:"7.780980,-18.984375",_map_default_zoom:1,_map_click_zoom_level:3,_gMarkers:new Array(),default_location_type:"facility",active_location_type:"",current_location_type:"",locations:new Array(),locations_count:0,active_location_name:"",selected_loc:"",initializer:function(){_globalObj=this;this.getActiveLocationFromURL();this.loadMapAndMarkers()},getActiveLocationFromURL:function(){var d=window.location.href;var e="/map/";var c=d.indexOf(e);if(c!=-1){var h=c+e.length;var g=d.substr(h);g=g.substr(0,g.length-1);this.active_location_type=g;var f=g.indexOf("/");if(f!=-1){this.active_location_type=g.substr(0,f);this.active_location_name=g.substr(f+1)}}},convertStaticCoordToGLatLng:function(d){var c=d.split(",");return new GLatLng(this.trim(c[0]),this.trim(c[1]))},trim:function(c){return c.replace(/^\s+|\s+$/g,"")},loadMapAndMarkers:function(){this._map=new GMap2(document.getElementById("google_map"));this._map.setCenter(this.convertStaticCoordToGLatLng(this._map_center),this._map_default_zoom);this._map.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(10,10)));this._map.addControl(new GMenuMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,10)));this._map.savePosition();this._map.enableContinuousZoom();var d=b.one(".map_reset_link");b.on("click",this.resetAllLocation,d,this);this.createMenu();var c=(this.active_location_type!=""?this.active_location_type:this.default_location_type);this.loadLocations(c)},createMenu:function(){b.on("click",this.handleMenuClick,".niceform",this);return;var h=b.one(".side_list");var i=b.one(".niceform");var c=b.Node.create('<select name="location_type" class="map_type_menu" size="1"></select>');var g=(this.active_location_type!=""?this.active_location_type:this.default_location_type);var d=this.createOption("facility","PotashCorp Facilities",g=="facility");c.appendChild(d);var f=this.createOption("investment","PotashCorp Investments",g=="investment");c.appendChild(f);var j=this.createOption("partner","PotashCorp Partners",g=="partner");c.appendChild(j);i.appendChild(c);var e=b.Node.create('<ul class="region_list"></ul>');h.appendChild(e)},createOption:function(e,f,d){var c=b.Node.create('<option class="location_map_option" value="'+e+'">'+f+"</option>");c.set("selected",d);return c},handleMenuClick:function(f){f.preventDefault();var d=f.target;if(d.ancestor(".location_map_option")){b.one(".location_type .NFSelectRight").set("innerHTML",d.get("innerHTML"));var c=(d.get("href").substr(d.get("href").lastIndexOf("/")+1));this.loadLocations(c)}return},displayLocations:function(){var h=b.one(".region_list");var d;var k;var c;var e;var j;var l;var m="non_facility";this._map.clearOverlays();this._gMarkers=new Array();if(h.hasChildNodes()){b.all(".region_list li").remove()}this.selected_loc="";this.resetAllLocation();for(var g=0;g<this.locations_count;g++){if(this.locations[g]["latlng"]!=""){var f=this.createMarker(g,this.locations[g]);this.displayMarker(g,f);if(g==0){d=this.locations[g]["country"];k=this.createListItem("","heading",d,false);h.appendChild(k)}else{if(d!=this.locations[g]["country"]){d=this.locations[g]["country"];k=this.createListItem("","heading",d,false);h.appendChild(k);b.one("#loc_"+(g-1)).addClass("last")}}c=this.locations[g]["name"];e=this.locations[g]["city"];j=(this.locations[g]["province/state"]!=""?this.locations[g]["province/state"]:this.locations[g]["country"]);l=c+" - "+(e!=""?e+", ":"")+j;if(this.current_location_type=="facility"){m="facility_"+(this.locations[g]["nutrient"].toLowerCase())}k=this.createListItem("loc_"+g,"item "+m,l,true);h.appendChild(k);if(this.locations[g]["url_name"]==this.active_location_name){if(this.active_location_name=="canpotex"){if(this.locations[g]["city"]=="Saskatoon"){this.selected_loc="loc_"+g}}else{this.selected_loc="loc_"+g}}}}if(g!=0){b.one("#loc_"+(g-1)).addClass("last")}},createListItem:function(g,e,f,d){if(f=="Trinidad"&&this.current_location_type=="facility"){f="International"}var c=b.Node.create('<li id="'+g+'" class="'+e+'">'+f+"</li>");if(d){b.on("click",this.handleItemClick,c,this)}return c},handleItemClick:function(d){var c=d.currentTarget;var f=c.get("id");this.selectLocation(f)},selectLocation:function(c){this.updateListSelected(c);var d=c.split("loc_");if(this._gMarkers[d[1]]!=null){GEvent.trigger(this._gMarkers[d[1]],"click")}this.selected_loc=c},createMarker:function(f,j){var c="/common/images/interface/map/";var l={Potash:"map_icon_K.png",Nitrogen:"map_icon_N.png",Phosphate:"map_icon_P.png","Nitrogen/Phosphate":"map_icon_N_P.png"};var e=c+"map_icon_P_I.png";if(this.current_location_type=="facility"){var h=j.nutrient;if(j.city=="Geismar"){h="Nitrogen/Phosphate"}e=c+l[h]}var i=j.city+", "+(j["province/state"]!=""?j["province/state"]:j.country);var k=this.buildInfoWindowText(j);var g=new GIcon();g.image=e;g.shadow=c+"map_icon_shadow.png";g.iconSize=new GSize(28,32);g.iconAnchor=new GPoint(13,30);g.infoWindowAnchor=new GPoint(20,5);var d=new GMarker(this.convertStaticCoordToGLatLng(j.latlng),{draggable:false,icon:g,title:i});GEvent.addListener(d,"click",function(){_globalObj._map.panTo(d.getPoint());_globalObj._map.setZoom(_globalObj._map_click_zoom_level);d.openInfoWindowHtml(k);_globalObj.updateListSelected("loc_"+f)});return d},buildInfoWindowText:function(j){var h="";var k=j.address;var c=j.address2;var f=j.city;var e=j["province/state"];var g=j.postal_code;var d=j.country;var i=j.nutrient;if(f=="Geismar"){i="Nitrogen / Phosphate"}h="<strong>"+(this.current_location_type=="facility"?"PCS "+i+"<br />":"");h+=(f!=""?f+", ":"")+(e!=""?e:d)+"</strong><br /><br />";h+=(k!=""?k:"")+"<br />";h+=(c!=""?c+"<br />":"");h+=(f!=""?f+", ":"")+(e!=""?e:"")+" "+(g!=""?g+", ":"")+d;return h},displayMarker:function(d,c){this._map.addOverlay(c);this._gMarkers[d]=c},loadLocations:function(f){if(f!=this.current_location_type){this.current_location_type=f;var d={method:"GET",data:"type="+f,context:this};var c=function(g,j){var h;try{h=b.JSON.parse(j.responseText)}catch(i){alert("Malformed JSON object");return}if(h.success==true){this.locations=h.locations;this.locations_count=h.total;this.displayLocations();this.selectLocation(this.selected_loc)}};var e=function(g,h){alert("Could not load the locations")};d.on={success:c,failure:e};b.io("/ajax/location/LocationMapAjaxController/loadLocationsByCountryAndType/",d)}},updateListSelected:function(c){var d=null;d=b.one(".selected");if(d!==null){d.removeClass("selected")}if(c!=""){d=null;d=b.one("#"+c);if(d!==null){d.addClass("selected")}}},resetAllLocation:function(){this.updateListSelected("");this._map.returnToSavedPosition();this._map.disableInfoWindow();this._map.enableInfoWindow()}});b.LocationsMap=a},"@VERSION@",{requires:["base","io","json","node"]});if(GBrowserIsCompatible()){YUI({timeout:10000}).use("locations_map","node",function(a){a.on("domready",function(){var b=new a.LocationsMap()})})}else{loadBrowserSupportError()}function loadBrowserSupportError(){var a=YAHOO.util.Dom.get("google_map");a.innerHTML='I\'m sorry! It appears you are using a browser not currently supported by Google Maps.<br>Google Maps currently only supports the following web browsers:<UL><LI>IE 6.0+ (download: <A href="http://www.microsoft.com/windows/ie/ie6/downloads/critical/ie6sp1/default.mspx" target=_blank>Windows</A>) <LI>Firefox 0.8+ (download: <A href="http://www.mozilla.org/products/firefox/" target=_blank>Windows</A> <A href="http://www.mozilla.org/products/firefox/" target=_blank>Mac</A> <A href="http://www.mozilla.org/products/firefox/" target=_blank>Linux</A>) <LI>Safari 1.2.4+ (download: <A href="http://www.apple.com/support/downloads/safari.html" target=_blank>Mac</A>) <LI>Netscape 7.1+ (download: <A href="http://browser.netscape.com/ns8/" target=_blank>Windows</A> <A href="http://browser.netscape.com/ns8/" target=_blank>Mac</A> <A href="http://browser.netscape.com/ns8/" target=_blank>Linux</A>) <LI>Mozilla 1.4+ (download: <A href="http://www.mozilla.org/products/mozilla1.x/" target=_blank>Windows </A> <A href="http://www.mozilla.org/products/mozilla1.x/" target=_blank>Mac</A> <A href="http://www.mozilla.org/products/mozilla1.x/" target=_blank>Linux</A>) <LI>Opera 8.02+ (download: <A href="http://www.opera.com/download/index.dml?platform=windows" target=_blank>Windows</A> <A href="http://www.opera.com/download/index.dml?platform=mac" target=_blank>Mac</A> <A href="http://www.opera.com/download/index.dml?platform=linux" target=_blank>Linux</A>) </LI></UL>If you wish to view your selection on a map, please download one of the browsers listed above.'};
