
var SCROLLABLE=false;var DOUBLE_CLICKABLE=true;var ENABLE_MAP_UTIL=false;var INCLUDE_HOTEL_IN_FAC_LIST=true;var ZOOM=new Array(5,14,14);var ROUTE_CONTAINER="map-tools-directions";var DIRECTION_OPTIONS={getPolyline:true,getSteps:true};var markerData=new Array();var tempPropArray=new Array();var directions="";var activePolyline="";var overview="";var propertyHTML="";var map=null;var openPanelFlag=false;var dafaultIcon="/application/images/googlemap/markers/icons_hotel.png";var defaultShadow="http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/examples/images/sun-shadow.png";var centerMarker=null;var markerGroups={"Tourist Spot":[],"Hotel":[]};var searchMarker=null;google.load("maps","2");google.load("search","1");function toggleMap(tabObj){$('#hotelDirections').hide();$('#panel-map-tools').hide();$('#map-tools-directions').hide();$('#directions_message').hide();if(tabObj.innerHTML=="Hotel Information"){$('#hotelDirections').show();}
if(tabObj.innerHTML=="Local Attractions"){$('#panel-map-tools').show();}
if(tabObj.innerHTML=="Driving Directions"){$('#directions_message').show();$('#map-tools-directions').show();}}
function linkJSOnDemand(jsURL)
{var head=document.getElementsByTagName('head')[0];var script=document.createElement('script');script.type='text/javascript';script.src=jsURL;head.appendChild(script);}
function initializeAttractions(){var attraction_content="<ul>";for(property in markerGroups){if(property!="Hotel"||INCLUDE_HOTEL_IN_FAC_LIST){attraction_content+="<li class=\"location_header "+property.replace(/ /,"_")+"\"><input type=\"checkbox\" value=\"Hide/Show Bars\" onclick=\"closeCustomInfo();toggleGroup('"+property+"')\" checked=\"checked\" class=\"location_checkbox\"/>"+property;attraction_content+="<ul>";for(var i=0;i<markerGroups[property].length;i++){attraction_content+="<li class=\"location_info\" onclick=\"closeCustomInfo();showAttraction('"+property+"',"+i+");scrollUP();\">"+markerGroups[property][i].getTitle()+"</li>";}
attraction_content+="</ul>";attraction_content+="</li>";}}
attraction_content+="</ul>";$('#panel-map-tools').html(attraction_content);}
function showAttraction(markerCat,markerID){var attMarker=markerGroups[markerCat][markerID];customInfoWindow(attMarker,attMarker.getTitle(),balloonContent(attMarker));}
function hideAttraction(markerCat,markerID){var attMarker=markerGroups[markerCat][markerID];attMarker.closeInfoWindow();}
function setCenterMarker(targetID){targetCenterMarker=markerGroups["hotel"][targetID];map.setCenter(targetCenterMarker.getLatLng(),ZOOM[2]);targetCenterMarker.openInfoWindowHtml(targetCenterMarker.getTitle());centerMarker=targetCenterMarker;}
function customInfoWindow(markerObj,infoTitle,infoBody){try{markerObj.openExtInfoWindow(map,"custom_info_window_red","<div class='title'>"+infoTitle+"</div>"+"<p>"+infoBody+"</p>",{beakOffset:2});}catch(e){}if(!PROPERTY&&markerObj.openingdate==''){if(!openPanelFlag){$('#regForm-header').trigger('click');openPanelFlag=true;}
$('#SearchHotelOrLandmark_CheckAvailabilityForm').attr('value',infoTitle);}}
function closeCustomInfo(){map.closeExtInfoWindow();}
function initializeDirections(routeContainer){var directionsPanel=document.getElementById(routeContainer);directions=new GDirections(null,directionsPanel);GEvent.addListener(directions,"addoverlay",function(){if(activePolyline!="")map.removeOverlay(activePolyline);activePolyline=directions.getPolyline();map.addOverlay(activePolyline);});}
function searchControl(){var searchControl=new GSearchControl();var localSearch=new GlocalSearch();var options=new GsearcherOptions();options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);searchControl.addSearcher(localSearch,options);localSearch.setCenterPoint(map);searchControl.setSearchCompleteCallback(localSearch,function(){var results=localSearch.results;var resultsHTML="";if(searchMarker!=null){map.removeOverlay(searchMarker);searchMarker=null;}
if(results[0]){var result=results[0];var markerLatLng=new google.maps.LatLng(parseFloat(result.lat),parseFloat(result.lng));var marker=new google.maps.Marker(markerLatLng,{icon:setMarkerIcon("/application/images/googlemap/markers/icons_magnifyingglass.png",defaultShadow),title:result.title});searchMarker=marker;map.addOverlay(marker);directions.load(marker.getLatLng().lat()+","+marker.getLatLng().lng()+" to "+centerMarker.getLatLng().lat()+","+centerMarker.getLatLng().lng(),DIRECTION_OPTIONS);}});var drawOptions=new google.search.DrawOptions();drawOptions.setSearchFormRoot(document.getElementById("map-tools-directions"));searchControl.draw(document.getElementById("directions_placeholder"),drawOptions);}
function setMarkerIcon(markerIconImage,markerShadowImage){var icon=new GIcon();icon.image=markerIconImage;icon.iconAnchor=new GPoint(16,16);icon.infoWindowAnchor=new GPoint(16,0);icon.iconSize=new GSize(32,32);icon.shadow=markerShadowImage;icon.shadowSize=new GSize(59,32);return icon;}
function toggleGroup(type){for(var i=0;i<markerGroups[type].length;i++){var marker=markerGroups[type][i];if(marker.isHidden()){marker.show();}else{marker.hide();}}}
function hideGroup(type){for(var i=0;i<markerGroups[type].length;i++){var marker=markerGroups[type][i];if(!marker.isHidden())marker.hide();}}
function showGroup(type){for(var i=0;i<markerGroups[type].length;i++){var marker=markerGroups[type][i];if(marker.isHidden())marker.show();}}
function showInfoPanel(popmarker){popmarker.openInfoWindowHtml('Test');}
function centerToMarker(centermarker){map.setCenter(centermarker.getPoint());}
function showAddress(address){if(geocoder){geocoder.getLatLng(address,function(point){if(!point){alert(address+" not found");}
else{log(point);}});}}
function roundNumber(num,dec){var result=Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);return result;}
function calcDistance(lat1,lng1,lat2,lng2,unitL)
{var distance=distVincenty(lat1,lng1,lat2,lng2);if(unitL=="km")distance=distance/1000;if(unitL=="mi")distance=(distance/1000)*0.6214;return roundNumber(distance,2);}
function setupMap(){if(GBrowserIsCompatible()){map=new GMap2(document.getElementById("map"));map.addControl(new GLargeMapControl());linkJSOnDemand('/application/js/extinfowindow.js');var firstMarkerToShow=null;var firstMarkerShownID=0;geocoder=new GClientGeocoder();var mapControl=new GOverviewMapControl();if(DOUBLE_CLICKABLE)map.enableDoubleClickZoom();if(SCROLLABLE)map.enableScrollWheelZoom();if(ENABLE_MAP_UTIL)$('#map-utilities').show();initializeDirections(ROUTE_CONTAINER);$.getJSON("/application/components_jsp/google_markers_JSON.jsp?pid="+propPID,function(data){$.each(data.points,function(i,item){var tempmarker=new GMarker(new GLatLng(item.lat,item.lng),{icon:setMarkerIcon(item.icon,defaultShadow),title:item.title});tempmarker.id=item.id;tempmarker.uri=item.uri;tempmarker.city=item.city;tempmarker.openingdate=item.opendate;tempmarker.category=item.type;tempmarker.prplink=item.proplink;markerData.push(new Array(item.id,item.type,item.title,item.city,item.proplink));GEvent.addListener(tempmarker,"click",function(){customInfoWindow(tempmarker,tempmarker.getTitle(),balloonContent(tempmarker));if(PROPERTY){directions.load(centerMarker.getLatLng().lat()+","+centerMarker.getLatLng().lng()+" to "+item.lat+","+item.lng,DIRECTION_OPTIONS);$('#hotelDirections').hide();$('#panel-map-tools').hide();$('#map-tools-directions').show();}});if(item.type=="Hotel"&&PROPERTY){$('#map-tools-directions').html(item.address);if(firstMarkerToShow==null)
{firstMarkerToShow=tempmarker;centerMarker=tempmarker;}}
markerGroups[item.type].push(tempmarker);map.addOverlay(tempmarker);});if(PROPERTY){initializeAttractions();map.setCenter(firstMarkerToShow.getLatLng(),ZOOM[2]);searchControl();customInfoWindow(firstMarkerToShow,firstMarkerToShow.getTitle(),balloonContent(firstMarkerToShow));}
else{map.setCenter(new GLatLng(54.235963635,-4.547918185),ZOOM[0]);hideGroup("Tourist Spot");$(generateCitySelector()).insertBefore('#map');overrideDefaultLinks();}});}}
function overrideDefaultLinks(){if(!PROPERTY){$(".find_hotel_cityname a").each(function(){});$(".find_hotel_propname a").each(function(){$(this).before('<a href="javascript:closeCustomInfo();centerOnProperty(\''+$(this).text()+'\');scrollUP();"><img src="/application/images/googlemap/magnifymap.jpg" align="left" height="12" style="margin-right:5px;"/></a>');});}}
function scrollUP(){$(window).scrollTop(135);}
function generateCitySelector(){var citySelector="<div id=\"googleDDLForm\"><select id=\"googleCityDDL\" onchange=\"updatePropDDL(this.value);\"><option value=\"0\">- Please Select City -</option>";var cityBuffer="Buffer:";for(var i=0;i<markerData.length;i++){if(markerData[i][3]!="na"&&cityBuffer.indexOf(markerData[i][3])<=0){citySelector+="<option value=\""+markerData[i][3]+"\">"+markerData[i][3]+"</option>";cityBuffer+=","+markerData[i][3];}}
citySelector+="</select>";citySelector+="<select id=\"googlePropDDL\" onchange=\"lockPropAtt()\" disabled=\"disabled\"><option value=\"0\">- Please Select Property -</option></select>";citySelector+="<select id=\"googleAttDDL\" onchange=\"lockPropAtt()\" disabled=\"disabled\"><option value=\"0\">- Please Select Tourist Spot -</option></select>";citySelector+="<button onclick=\"closeCustomInfo();updateMap();\">Go</button>";citySelector+="<button onclick=\"resetGoogleJSForm();closeCustomInfo();\">Reset</button></div>";return citySelector;}
function resetGoogleJSForm(){updatePropDDL($('#googleCityDDL')[0].options[$('#googleCityDDL')[0].selectedIndex].value);if($('#googleCityDDL')[0].selectedIndex<=0){$('#googlePropDDL').attr("disabled",true);$('#googleAttDDL').attr("disabled",true);}
map.setCenter(new GLatLng(54.235963635,-4.547918185),ZOOM[0]);hideGroup("Tourist Spot");}
function updateMap(){if($('#googleCityDDL')[0].selectedIndex>0){if($('#googlePropDDL')[0].selectedIndex>0){centerOnProperty($('#googlePropDDL')[0].options[$('#googlePropDDL')[0].selectedIndex].text);}
else if($('#googleAttDDL')[0].selectedIndex>0){centerOnAttraction($('#googleAttDDL')[0].options[$('#googleAttDDL')[0].selectedIndex].value);}
else{centerOnCity($('#googleCityDDL')[0].options[$('#googleCityDDL')[0].selectedIndex].value);}}}
function balloonContent(markerObj){var balloonHTML="";if(markerObj.category=="Hotel"){balloonHTML+=hotelSummary[markerObj.id];if(!PROPERTY){balloonHTML+="<br class=\"break\"/><a href=\""+markerObj.uri+"\" class=\"balloonPropLink\"><span>Go to Property</span></a>";balloonHTML+="<br class=\"break\"/><a href=\"/group/find_a_hotel.html?searchby=city&city="+markerObj.city+"\" class=\"balloonCitySearch\"><span>Find hotels in "+markerObj.city+"</span></a>";}}
else{balloonHTML+=markerSummary[markerObj.id];if(PROPERTY)
balloonHTML+="<br class=\"break\"/><a href=\"#directions\" class=\"balloonPropLink\"><span>See driving directions</span></a>";}
return balloonHTML;}
function centerOnCity(cityName){for(var i=0;i<markerGroups["Hotel"].length;i++){if($.trim(cityName)==$.trim(markerGroups["Hotel"][i].city)){map.setCenter(markerGroups["Hotel"][i].getLatLng(),ZOOM[1]);showGroup("Tourist Spot");break;}}}
function centerOnProperty(propName){for(var i=0;i<markerGroups["Hotel"].length;i++){if($.trim(propName)==$.trim(markerGroups["Hotel"][i].getTitle())){map.setCenter(markerGroups["Hotel"][i].getLatLng(),ZOOM[2]);customInfoWindow(markerGroups["Hotel"][i],markerGroups["Hotel"][i].getTitle(),balloonContent(markerGroups["Hotel"][i]));showGroup("Tourist Spot");break;}}}
function centerOnAttraction(attID){for(var i=0;i<markerGroups["Tourist Spot"].length;i++){if($.trim(attID)==$.trim(markerGroups["Tourist Spot"][i].id)){markerGroups["Tourist Spot"][i].show();map.setCenter(markerGroups["Tourist Spot"][i].getLatLng(),ZOOM[2]);customInfoWindow(markerGroups["Tourist Spot"][i],markerGroups["Tourist Spot"][i].getTitle(),balloonContent(markerGroups["Tourist Spot"][i]));showGroup("Hotel");break;}}}
function generatePropertySelector(cityName){var propSelector="<select id=\"googlePropDDL\" onchange=\"lockPropAtt();\"><option value=\"0\">- Please Select Property -</option>";for(var i=0;i<markerData.length;i++){if(markerData[i][3]==cityName){propSelector+="<option value=\""+markerData[i][4]+"\">"+markerData[i][2]+"</option>";tempPropArray.push(markerData[i][4]);}}
propSelector+="</select>";return propSelector;}
function generateAttDDL(){var attBuffer="Buffer:";var attSelector="<select id=\"googleAttDDL\" onchange=\"lockPropAtt();\"><option value=\"0\">- Please Select Tourist Spot -</option>";for(var i=0;i<tempPropArray.length;i++){for(var j=0;j<markerData.length;j++){if(markerData[j][4].indexOf(tempPropArray[i])>=0&&attBuffer.indexOf(markerData[j][0])<0&&markerData[j][1]!="Hotel"){attSelector+="<option value=\""+markerData[j][0]+"\">"+markerData[j][2]+"</option>";attBuffer+=","+markerData[j][0];}}}
attSelector+="</select>";return attSelector;}
function updatePropDDL(cityName){if(document.getElementById('googlePropDDL')){$('#googlePropDDL').remove();tempPropArray=[];}
if(document.getElementById('googleAttDDL')){$('#googleAttDDL').remove();}
$(generatePropertySelector(cityName)).insertAfter('#googleCityDDL');$(generateAttDDL()).insertAfter('#googlePropDDL');if($('#googleCityDDL')[0].selectedIndex<=0){$('#googlePropDDL').attr("disabled",true);$('#googleAttDDL').attr("disabled",true);}}
function lockPropAtt(){if($('#googlePropDDL')[0].selectedIndex>0)
$('#googleAttDDL').attr("disabled",true);else
$('#googlePropDDL').attr("disabled",true);if($('#googlePropDDL')[0].selectedIndex<=0&&$('#googleAttDDL')[0].selectedIndex<=0){$('#googlePropDDL').attr("disabled",false);$('#googleAttDDL').attr("disabled",false);}}