//var thisroute = null;
//var routelayer = new VEShapeLayer();
 

BingDirection = {};

(function () {

	BingDirection.Map = function(mapObjName,mapName,useAnchor,enterpriseBingKey)
	{
		//Enterprise bing key supplied by Bing.
		var enterpriseKey=enterpriseBingKey;
		var mapLoaded =false;
		// this value is true if there is no need for numbers
		// to be shown within the anchor image (eg. for GW)
		var useAnchorIndex=useAnchor;
		
		// the name of the map div tag
		var mapDivName=mapName; 

		var mapObjNameStr=mapObjName;

		 /**********************************************
		 * These following lines manipulates the icon image
		 * as it sets the index number as well as the anchor image
		 * Three mouse events are used: over, down and out
		 **********************************************/
		 var icon1 = "<div id='icon";
		 var icon2 = "' onmouseover="+mapObjNameStr+".OnMouseOver(this,";
		 var icon3 = ") onmousedown="+mapObjNameStr+".OnMouseClick(this,";
		 var icon4 = ") onmouseout="+mapObjNameStr+".OnMouseOut(this)>";
		 var icon5 = "<div id='hotelNumber'>";
		 var icon6 = "</div><div>";
		 var icon7 = "</div>";		
		
		//Global Variable for Saving detailed Div.
		 var addDetailsDiv;
		 var addDetailsDiv2;

		// this is the error message if there is a Bing connection issue
		 var errorMsg = mapdown;

		 // tag names and class names for the details bubble
		 var detailTitle = "mapBubbleDetailsTitle";
		 var detailBody = "mapBubbleDetailsBody";
		 var details = "mapBubbleDetails";
		 var detailsClose="mapBubbleDetailsClose";
		 var detailsClassName = "mapBubble";
		 var detailsDiv=null;
		 var detailsToolTip="detailsToolTip";


		// tag names and class names for the hotel name bubble
		 var hotelName = "mapBubbleHotelName";
		 var hotelNameStr = "hotelNameStr";
		 var hotelNameClassName = "mapBubble";
		 var hotelNameDiv = null;
		 var hotelNameToolTip="hotelNameToolTip";
		 
		// tag names and class names common for both hotel name and details bubble
		 var titleClassName = "title";
		 var tootipClassName = "map-tooltip-pointer";
		 var innerToolTipClassName = "map-tooltip-pointer-inner";
		 var bodyClassName = "body";
		 var iconCloseClassName = "iconClose";
		 var closeIconName="/HiWayWeb/framework/skins/hiway/en_GB/i/bing_icon_close.gif";

		// these values determines the width and height
		// of the anchor image and branded image
		// they are used to center the bubbles above the image
		// and set the dimensions of the IE5/6 specific image div tag
		// assuming that these values do not change
		//Anchor images is used for Hotel Search icons.
		var anchorImgWidth=29;
		var anchorImgHeight=40;
		
		// Brand Images used for Hotel Level Pages.
		var brandedImgWidth=33;
		var brandedImgHeight=40;

		// these values are set depending on the useAnchorIndex boolean
		var imgWidth=0;
		var imgHeight=0;
		
		// this is the height of the pointer
		// assuming that this value does not change
		var pointerHeight=14;

		// this object represents the div tag that wraps
		// around the image. It is the "this" object of 
		// OnMouseOver,OnMouseOut and OnMouseClick
		 var currentHotelNameObj=null;
		 var currentDetailsObj=null;

		// this is the current index of the hotel
		// which the mouse is either hovering or has clicked
		 var currentHotelNameIndex=-1;
		 var currentDetailsIndex=-1;
		
		// boolean that is set to true
		// when someone clicks on a hotel
		// in order to get the details
		var detailsOpened=false;

		// if using an IE 5.5 and 6
		// this flag is true for older versions of IE
		var isOldIE=false;

		// this flag is set when the user is dragging an anchor
		var dragging = false;

		// map object
		var map = null;
		
		//Temporary Object setting for checking the status
		var myCounter=0;
		

		var overrideZoom=false;
		var zoomLevel=1;
		var dataIndex=0;

		// these arrays store the Bing shape representing each image instance
		// each line that links the lat/long to the image
		// each latlong
		// for each hotel
		var polyLineArray = new Array();
		var shapeArray = new Array();
		var latLongArray = new Array();
		var gCheck = false;
		
		var locale = G_LOCALE;

		var hotelList = {
			"centerLat" : "",
			"centerLong" : "",
			"centerImgUrl" : "",
			"list" : []
		};

		var mapLoaded = false;

		// initializing the imgWidth/imgHeight variables
	    // based on whether branded images are set or not
	   var initImgVariables = function()
	   {
			if (useAnchorIndex || locale=='ja_JP')
			{
				imgWidth = anchorImgWidth;
				imgHeight = anchorImgHeight;
			} else {
				imgWidth = brandedImgWidth;
				imgHeight = brandedImgHeight;
			}
			
	   };
		
	   // getting the position of the div tag on the page
		// this code checks the x,y position of the di
		var findPos = function(obj) {
			 if (obj.id)
			 {
				var objid = obj.id;
				var newobj = document.getElementById(objid);

				if (newobj){
					var curleft = curtop = 0;
					try{
						do {
							curleft += newobj.offsetLeft;
							curtop += newobj.offsetTop;
						} while (newobj = newobj.offsetParent);

					} catch (ex){}
					return [curleft,curtop];
				}
			}
		};

		// sets the position of the detail box
		var setDetailPosition = function(obj){
			if (obj)
			{
				// getting the map div in order to get its width and height
				var mapDiv = document.getElementById(mapDivName);
				var mapDivPos = findPos(mapDiv);
				var mapLeftMargin = mapDivPos[0]-10;
				var mapTopMargin = mapDivPos[1];				

				// getting the pointer div in order to dynamically set the pointer
				var pointerDiv = document.getElementById(detailsToolTip);

				// the calculation below do the following
				// 1. does not allow the details bubble to move past the leftmost/rightmost borders
				// 2. when the bubble is at the leftmost/rightmost borders the location of the pointers
				// are dynamically set. Otherwise the default is 50%
				
				var imgLeftOffSet = detailsDiv.clientWidth/2-imgWidth/2;
				var imgTopOffSet = detailsDiv.clientHeight+pointerHeight;

				var currentDetailsPos = findPos(obj);

				if (currentDetailsPos)
				{
					var x = currentDetailsPos[0];
					var y = currentDetailsPos[1];
					
					//Fixing the IE issue
					if(useAnchorIndex==true || locale=='ja_JP'){
						pointerDiv.style.left="49.5%";
					}
					else{
						pointerDiv.style.left="50%";
					}	
					// when the bubble reaches the leftmost border
					if(x<detailsDiv.clientWidth/2+mapLeftMargin){
						if(x>=mapLeftMargin+imgWidth/2){
							pointerDiv.style.left=x-mapLeftMargin+"px";
						}else
						{
							pointerDiv.style.left=imgWidth/2+"px";
						}
						x = detailsDiv.clientWidth/2+mapLeftMargin;						
					}

					if (x>mapDiv.clientWidth-detailsDiv.clientWidth/2-imgWidth/2+mapLeftMargin)
					{						
						if (x>mapDiv.clientWidth-detailsDiv.clientWidth/2+mapLeftMargin-imgWidth/2 && x<mapLeftMargin+mapDiv.clientWidth-imgWidth)
						{   
							pointerDiv.style.left=x-(mapDiv.clientWidth-detailsDiv.clientWidth+mapLeftMargin)+imgWidth/2+"px";
						} else {
							pointerDiv.style.left=detailsDiv.clientWidth-imgWidth/2+"px";
						}
						x=mapDiv.clientWidth-detailsDiv.clientWidth/2-imgWidth/2+mapLeftMargin;
					}		
					
					// if the bottom of the bubble is at the top of the map
                     if (y < mapTopMargin){
                     	y = mapTopMargin;
                     }

                     // if the bottom of the bubble is at the bottom of the map
                     if (y > mapDiv.clientHeight +mapTopMargin){
                        y = mapDiv.clientHeight +mapTopMargin;
                     }

					detailsDiv.style.left=(x-imgLeftOffSet)+"px";
					//detailsDiv.style.top=(currentDetailsPos[1]-imgTopOffSet)+"px";
					detailsDiv.style.top=(y-imgTopOffSet)+"px";					
				}
			}
		};

		// sets the position of the detail box
		var setHotelNamePosition = function(obj){
			if (obj)
			{
				var mapDiv = document.getElementById(mapDivName);
				var pointerDiv = document.getElementById(hotelNameToolTip);

				var mapDivPos = findPos(mapDiv);
				var mapLeftMargin = mapDivPos[0]-10;

				var imgLeftOffSet = hotelNameDiv.clientWidth/2-imgWidth/2;
				var imgTopOffSet = hotelNameDiv.clientHeight+pointerHeight;

				var currentHotelNamePos = findPos(obj);

				if (currentHotelNamePos)
				{
					var x = currentHotelNamePos[0];
					if(useAnchorIndex==true || locale=='ja_JP'){
					pointerDiv.style.left="49.5%";
					}
					else{
					pointerDiv.style.left="50%";
					}
					if(x<hotelNameDiv.clientWidth/2+mapLeftMargin){
						if(x>=mapLeftMargin+imgWidth/2){
							pointerDiv.style.left=x-mapLeftMargin+"px";
						}
						else
						{
							pointerDiv.style.left=imgWidth/2+"px";
						}
						x = hotelNameDiv.clientWidth/2+mapLeftMargin;
						
					}
					if (x>mapDiv.clientWidth-hotelNameDiv.clientWidth/2-imgWidth/2+mapLeftMargin)
					{
						if(x>=mapDiv.clientWidth-hotelNameDiv.clientWidth/2-imgWidth+mapLeftMargin && x<mapDiv.clientWidth+mapLeftMargin-imgWidth){
							pointerDiv.style.left=x-(mapDiv.clientWidth-hotelNameDiv.clientWidth+mapLeftMargin)+imgWidth/2+"px";
						}else {
							pointerDiv.style.left=detailsDiv.clientWidth-imgWidth/2+"px";
						}
						x=mapDiv.clientWidth-hotelNameDiv.clientWidth/2-imgWidth/2+mapLeftMargin;
					}

					hotelNameDiv.style.left=(x-imgLeftOffSet)+"px";
					hotelNameDiv.style.top=(currentHotelNamePos[1]-imgTopOffSet)+"px";
					var currentDetailsObjIndex  = currentDetailsIndex+1;

				}
			}
		};

				 
		// builds a string that represent the image div
		var buildImgTag = function(imgUrl){
			var imgStr = "";
			if(!isOldIE){
				imgStr = appendStrings(["<img  src='",imgUrl,"'/></div>"]);
			} else {
				// if it is an old IE browser then a filter needs to applied
				// so that the png images shows a transparent background
				var height = imgHeight+"px";
				var width = imgWidth+"px";
				imgStr = appendStrings(["<div style=\"height:",height,";width:",width,";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='",imgUrl,"', sizingMethod='scale');\"></div></div>"]);
			}
			return imgStr;
				
		};

		// dynamically adds a div for the hotel name bubble 
		var buildHotelNameDiv = function (){			
			var divTag = document.createElement("DIV");
			divTag.id = hotelName;
			divTag.className = hotelNameClassName;
			divTag.innerHTML =appendStrings(["<div id='",hotelNameStr,"' class='",titleClassName,"'></div><div id='"+hotelNameToolTip+"' class='",tootipClassName,"'><div class='"+innerToolTipClassName,"'></div>"]);
			document.body.appendChild(divTag);
		};

		// dynamically adds a div for the details bubble
		var buildDetailsDiv = function(){
			var divTag = document.createElement("DIV");
			divTag.id = details;
			divTag.className = detailsClassName;
			divTag.style.textAlign ="left";
			divTag.innerHTML =appendStrings(["<div id='",detailBody,"' class='",bodyClassName,"'></div><div id='",detailsClose,"' onclick='"+mapObjNameStr+".closeDetails()'><img class='",iconCloseClassName,"' src='"+closeIconName,"' alt='Close' /></div><div id='"+detailsToolTip+"'class='",tootipClassName,"'><div class='",innerToolTipClassName,"'></div>"]);
			document.body.appendChild(divTag);
		};


		// show an error message if there is a connection issue with Bing
		var buildErrorDiv = function(){
			var errorDivTag = document.createElement("DIV");
			errorDivTag.innerHTML= errorMsg;
			// errorDivTag.className = errorDivTagClassName;
			var mapDiv = document.getElementById(mapDivName);
			mapDiv.appendChild(errorDivTag);
			
		};

		 // debugging
		var debug = function (str){
				document.getElementById("output").innerHTML=str;
		 };


		 // checks the version of IE
		// if it is an old IE then set the isOldIE flag to true
		var checkIEVersion = function (){
			var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
			isOldIE = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7);
		};
		
	/*function drawRoute(){
				if(thisroute != null){
				var path = new VEShape(VEShapeType.Polyline,thisroute.ShapePoints);
				//path.HideIcon();
				path.SetLineWidth(10);
				routelayer.AddShape(path);
				routelayer.Show();
			}
		 }
 	function hideRoute(){
			 if(thisroute != null && routelayer.IsVisible){
				routelayer.Hide();
			}
		 }*/
		  // reset a few things once the zoom occurs
		 var onEndZoom=function (){
				var i =0;
				var hotelLatLong=null;
				var shape = null;

				for (i=0;i<hotelList.list.length;i++)
				{
					var polyline = polyLineArray[i];
					var points = polyline.GetPoints();
					var origPoint = points[0];
					polyline.SetPoints([origPoint,origPoint]);
			
					// move the image back to the original latlong 
					// in case they were dragged away
					var shape = shapeArray[i];
					shape.SetIconAnchor(origPoint);
			
					// reset the icon back to the anchor image (as opposed to the dragged image)
					var iconStr = shape.GetCustomIcon();
					if (iconStr.search(hotelList.list[i].dragImgUrl)!=-1)
					{
						iconStr = iconStr.replace(hotelList.list[i].dragImgUrl,hotelList.list[i].anchorImgUrl);
						shape.SetCustomIcon(iconStr);
					}
			
				}
				// remove the details bubble
				detailsDiv.style.visibility='hidden';				
			};

			// when the mouse stops dragging the anchor image
			// this function is invoked
			var EndDragHandler = function(e) {
				
				// if e.Shape returns a Bing shape object
				if (e.Shape){
		
					var currentLatLong = e.LatLong;
					var currentShape = e.Shape;
					var index = currentShape.shapeIndex;

					// redrawing the line to the image
					var polyline = polyLineArray[index];
					var points = polyline.GetPoints();
					var origPoint = points[0];
					var destinPoint = new VELatLong(e.LatLong.Latitude, e.LatLong.Longitude,0,VEAltitudeMode.RelativeToGround);
					polyline.SetLineColor(new VEColor(0,0,0,1.0));					
					polyline.SetPoints([origPoint,destinPoint]);

					// swapping the image from the anchor image to the "nearby" image
					// once the image is dragged to another location
					var iconStr = currentShape.GetCustomIcon();
					if (iconStr.search(hotelList.list[index].dragImgUrl)==-1)
					{
						iconStr = iconStr.replace(hotelList.list[index].anchorImgUrl,hotelList.list[index].dragImgUrl);
						currentShape.SetCustomIcon(iconStr);
					}

					// if the image returns to its original point then the image
					// is reset to the anchor image
					if (origPoint.Latitude== e.LatLong.Latitude && origPoint.Longitude == e.LatLong.Longitude && iconStr.search(hotelList.list[index].dragImgUrl)!=-1)
					{
						iconStr = iconStr.replace(hotelList.list[index].dragImgUrl,hotelList.list[index].anchorImgUrl);
						currentShape.SetCustomIcon(iconStr);
					}
				}
				// dragging is done
				dragging=false;

			};

			// when the user starts dragging the image this method is invoked
			var StartDragHandler = function(e) {
				dragging=true;
			};

			// as the user is dragging the image
			// it resets the position of the bubble (either hotel name bubble or hotel name bubble)
			var DragHandler = function(e) {
				setDetailPosition(currentDetailsObj);
				setHotelNamePosition(currentHotelNameObj);
			};


			function checkDrag(e)
			{
			};
			
			// passing an array of strings and returned a joined string
			var appendStrings = function(list){
				 this.buffer = [];
				var i =0;
				for (i=0;i<list.length;i++){
					buffer.push(list[i]);
				}
				return buffer.join("");
			 };

			// trim the white space
			 var trim = function(string) {
				return string.replace(/^\s*/, "").replace(/\s*$/, "");
			 };
		
		return {
				
			 checkMap : function()
			 {			 	
				gCheck=true;								 	
			 },
	
			toggleTheMap : function(link, latitude, longitude, hideMapText, showMapText) 
			{
				
				var link = jQuery(link);
				href = link.attr('href');
				if (link.hasClass('collapsed')) {
					link.text(hideMapText);
					if(mapLoaded == false){
												
					}
					link.replaceClass('collapsed','expanded');
					jQuery(href).show();
					jQuery('.mapMarker1').show();
					jQuery('.mapMarker').show();
					jQuery('.hsresult h2').addClass('makeRoomForMapMarker');
					//mapLoaded = true;
				} else {
					link.text(showMapText);
					link.replaceClass('expanded','collapsed');
					jQuery(href).hide();
					jQuery('.mapMarker1').hide();
					jQuery('.mapMarker').hide();
					jQuery('.hsresult h2').removeClass('makeRoomForMapMarker');
				}
				return false;
			},
			
		   resetMap:function()
			{
				onEndZoom();
			},

			getName:function()
			{
				return mapObjNameStr;
			},
			
			
			addItemsToMap:function ()
			{
				if (map){
					// adding all the hotels on the map
					var i =0;
					for (i=hotelList.list.length-1;i>=0;i--)
					{
						this.addItemToMap(i);
					}
					
					if(latLongArray.length == 1){map.SetCenterAndZoom(latLongArray[0], 15);}
					else map.SetMapView(latLongArray);
					
				}
			},

			// add a hotel based on its latitude, longitude and its index
			// in the list of hotels
			addItemToMap:function (index,layer)
			{

				var hotelLatLong = new VELatLong(hotelList.list[index].hotelLat,hotelList.list[index].hotelLng, 0, VEAltitudeMode.RelativeToGround);
				var shape = new VEShape(VEShapeType.Pushpin,hotelLatLong);
				
     		    //Set the icon
				var icon = "";
				var pinid = index+1;
				
				// checks if the anchor image needs to show an index and sets the
				// icon image appropriately
				if (useAnchorIndex){
					icon = appendStrings([icon1,pinid,icon2,index,icon3,index,icon4,icon5,pinid,icon6,buildImgTag(hotelList.list[index].anchorImgUrl),icon7]);
				} else {
					icon = appendStrings([icon1,pinid,icon2,index,icon3,index,icon4,buildImgTag(hotelList.list[index].anchorImgUrl)]);
				}
				shape.SetCustomIcon(icon);
							
				 //make the images draggable and set up the events
				 shape.Draggable = true;
				 shape.onstartdrag = StartDragHandler;
				 shape.onenddrag = EndDragHandler;
				 //shape.onenddrag = checkDrag2;
				 shape.ondrag = DragHandler;
				
				 // create a line that will link the latlong of the shape to wherever the image is dragged
				 var newpoly = new VEShape(VEShapeType.Polyline, [hotelLatLong,hotelLatLong]);
				 newpoly.HideIcon();
				 polyLineArray[index] = newpoly;
		
				if (layer!=null || typeof layer!="undefined")
  				 {
				   
					layer.AddShape(shape);
					layer.AddShape(newpoly);
				 }else {
					// add the shape and line to the map
					map.AddShape(shape);
					map.AddShape(newpoly);
				}
			
				// store the index of the shape into a custom property shapeIndex
				shape.shapeIndex = index;

				// store the shape in an array
				shapeArray[index]=shape;
				
			  },

			// makes the details bubble invisible
			closeDetails : function (){
				detailsDiv.style.visibility = "hidden";
				detailsOpened=false;
			},

			
			// invoked when the mouse hovers over the anchor image
			OnMouseOver : function(obj,index){
				// if we are clicking on the bubble we should see the details bubble
				// not the hotel name bubble
				if (index==currentDetailsIndex && detailsOpened)
				{
					this.closeHotelName();
					
				}else{
					// showing the details bubble
					
					if (obj.id && dragging!=true && (hotelList.list[index].hotelName!="" || typeof hotelList.list[index].hotelName!="undefined"))
					{
						
						// if the current hotel name is already set no need to reset it
						if (currentHotelNameIndex != index){
							currentHotelNameIndex=index;
							currentHotelNameObj= obj;
							document.getElementById(hotelNameStr).innerHTML=hotelList.list[index].hotelName;
						}
						setHotelNamePosition(obj);
						hotelNameDiv.style.visibility = "visible";
					}
				}

			},


			// this method is invoked when the mouse is clicked
			// it shows the details bubble and set its position on the page
		   OnMouseClick:function(obj,index) {
			
		   		var changing;
		   		//for Search Result page
  	            if(jQuery('#addressDiv'+(index+1)).html()!=null){
  	            	           	
  	            	detailsDiv.style.width='300px';           	
  	                var addDiv = jQuery('#addressDiv'+(index+1));
  	                document.getElementById(detailBody).innerHTML=addDiv.html();
					setDetailPosition(obj);
					detailsDiv.style.visibility='visible';
					detailsOpened = true;
					currentDetailsObj= obj;
					currentDetailsIndex = index;
					this.closeHotelName();
  	            }
  	            //For Hotel Level Pages.
  	            else{
				detailsDiv.style.width='400px';
				if(index==0){
		   		document.getElementById(detailBody).innerHTML=addDetailsDiv.html();
		   		}
		   		else{changing =0; addDetailsDivSimple = jQuery('#info'+(index+1));}
				var descriptionStr = hotelList.list[index].hotelDescription; 
				
				if(descriptionStr != "") //POI clicked
				{
				    detailsDiv.style.width='300px';
					document.getElementById(detailBody).innerHTML=descriptionStr;
					setDetailPosition(obj);
					detailsDiv.style.visibility='visible';
					detailsOpened = true;
					currentDetailsObj= obj;
					currentDetailsIndex = index;
					this.closeHotelName();
				}
				
				else //if (typeof descriptionStr.centerLat!="undefined" || descriptionStr.centerLat!="")
				{
					//descriptionStr = trim(descriptionStr);
					    if(changing==0){document.getElementById(detailBody).innerHTML=addDetailsDivSimple.html();}					    
						setDetailPosition(obj);
						detailsDiv.style.visibility='visible';
						detailsOpened = true;
						currentDetailsObj= obj;
						currentDetailsIndex = index;
						this.closeHotelName();

				 }
				}
		   },

			// when the mouse hovers away from the image the hotel name bubble disappears
		   OnMouseOut:function (obj) {
		   		this.closeHotelName();
		   },

			// return map for future use
			getMapObj:function(){
				return map;
			},

			getLatLongArray:function(){
				return latLongArray;
			},
			
			getHotelList:function(){
				return hotelList;
			},

			// makes the details bubble invisible
			closeHotelName:function (){
				hotelNameDiv.style.visibility = "hidden";	
			},

			// sets the json as its data
			// all information is already stored in the json
			// it simply overwrites the global json 
			setJSONData:function (newHotelList)
			{
				for (i=0;i<newHotelList.list.length;i++)
				{
					this.addData(newHotelList.list[i].hotelName,newHotelList.list[i].hotelLat,newHotelList.list[i].hotelLng,newHotelList.list[i].anchorImgUrl,newHotelList.list[i].dragImgUrl,newHotelList.list[i].hotelDescription);
				}
			},

			// sets the center latitude/longitude
			setCenterLatLong:function (latitude,longitude){
				hotelList.centerLat=latitude;
				hotelList.centerLong=longitude;
			},

			// sets the center image url
			setCenterImgUrl:function(centerImgUrl)
			{
				hotelList.centerImgUrl=centerImgUrl;
			},

			setErrorMsg:function(errorMessage)
			{
				errorMsg=errorMessage;
			},

			setZoomLevelBeforeMapLoad:function (zoomLvl)
			{
				overrideZoom = true;
				zoomLevel = zoomLvl;
			},

			setZoomLevelAfterMapLoad:function(zoomLvl)
			{
				map.SetZoomLevel(zoomLvl);
			},
			
			getListIndex:function(){
				return hotelList.list.length;
			},

			// adds a hotel entry into the json
			// the data is built dynamically
			addData:function (hotelName,hotelLat,hotelLng,anchorImgUrl,dragImgUrl,hotelDescription){				
				hotelList.list.push({hotelName: hotelName, hotelLat: hotelLat,hotelLng:hotelLng,anchorImgUrl:anchorImgUrl,dragImgUrl:dragImgUrl,hotelDescription:hotelDescription});
				var hotelLatLong = new VELatLong(hotelLat,hotelLng, 0, VEAltitudeMode.RelativeToGround);
				//latLongArray[dataIndex]=hotelLatLong;
				//dataIndex++;
				latLongArray.push(hotelLatLong);
			},
			
			// adds a hotel entry into the json
			// the data is built dynamically
			addPoiData:function (hotelName,hotelLat,hotelLng,anchorImgUrl,dragImgUrl,description){
				hotelList.list.push({hotelName: hotelName, hotelLat: hotelLat,hotelLng:hotelLng,anchorImgUrl:anchorImgUrl,dragImgUrl:dragImgUrl,hotelDescription:description});
				var hotelLatLong = new VELatLong(hotelLat,hotelLng, 0, VEAltitudeMode.RelativeToGround);
				dataIndex++;
			},


			resetZoom:function(){
				if(overrideZoom){
					map.SetZoomLevel(zoomLevel);
					if (hotelList.list.length==1){
						map.SetCenter(latLongArray[0]);
					}
				}
				else {
					map.SetMapView(latLongArray);
				}
			},


			resetAllData:function(){
				if (map){
					map.DeleteAllShapes();
				}
				hotelList.list=[];
				latLongArray = [];				
			},

			/*****************************************************************
			 *  Name:				GetMap
			 *  Functionality:		Loads a Bing map 
			 *  Arg:				String, name of a div tag on the page
			 *****************************************************************/
			 GetMap:function()
			 {				
				try
				{				
				  // creates a map and sets the Bing control panel to the smaller version
				  map = new VEMap(mapName);
				  
				  if(gCheck)
				  {
					map = null;
					buildErrorDiv();
					return;						
				  }
					
			      if(map)
					{						
						checkIEVersion();

						// each shape has an index of the hotel in the list
						VEShape.prototype.shapeIndex = 0;

						// dynamically build the 2 div elements: one for hotel name and the other for details
						if(mapLoaded==false){
							buildHotelNameDiv();
							buildDetailsDiv();
						}
						// initialize imgHeight and imgWidth
						initImgVariables();
					
						// hiding the details and hotel name bubbles
					    detailsDiv = document.getElementById(details);
						detailsDiv.style.visibility = "hidden";

						addDetailsDiv2 = jQuery('#hotelInfoDiv');
		   				addDetailsDiv = jQuery('#hotelAtrName').append(addDetailsDiv2.html());
						hotelNameDiv = document.getElementById(hotelName);
						hotelNameDiv.style.visibility = "hidden";
					
						// creating a map and load it
						// the map does not have 3D only 2D and starts with a road map
						map = new VEMap(mapName);
												
						map.SetCredentials(enterpriseKey);						
						map.LoadMap(null, zoomLevel, VEMapStyle.Road, false, VEMapMode.Mode2D, false, 0);
						
						//changes for bird's eye view
						//map.AddShapeLayer(routelayer);																	
						
						document.getElementById("MSVE_navAction_ObliqueMapView").style.display='none';	
																		
						// initializing the array of lat/long
						if (hotelList.list.length != 0)
						{
							map.SetMapView(latLongArray);
						}
						
						// if a center logo and a center lat/long is defined in the json
						// then the map center lat/long is set
						// and an image is fixed there
						if (typeof hotelList.centerLat=="undefined" ||typeof hotelList.centerLong=="undefined" || hotelList.centerLat=="" || hotelList.centerLong=="" || hotelList.list.length==1)
						{							
						}else {
							var centerLongLat = new VELatLong(hotelList.centerLat,hotelList.centerLong, 0, VEAltitudeMode.RelativeToGround);
						 
							if (typeof hotelList.centerImgUrl!="undefined" || hotelList.centerImgUrl!="")
							{
								centerShape = new VEShape(VEShapeType.Pushpin,centerLongLat);
								var centerIcon= appendStrings(["<img  src='",hotelList.centerImgUrl,"'/></div>"]);
								centerShape.SetCustomIcon(centerIcon);
								map.AddShape(centerShape);
							}
							
							map.SetCenter(centerLongLat);
						} 

						if(overrideZoom){
							map.SetZoomLevel(zoomLevel)
						}
						
						
						
						if (latLongArray.length != 0)
						{
							// adding all the hotels on the map
							var i =0;
							for (i=hotelList.list.length-1;i>=0;i--)
							{
								this.addItemToMap(i);
							}
						}
						
						
						if(!useAnchorIndex){												
						if (hotelList.list.length==1 )
						{							
							//map.SetZoomLevel(15);
							map.SetCenterAndZoom(latLongArray[0], 15);
							}
						else {
							map.SetCenter(latLongArray[0]);
						}
						}
						else{
							if (hotelList.list.length==1 )
							{							
							//map.SetZoomLevel(15);
							map.SetCenterAndZoom(latLongArray[0], 15);
								}
							else {map.SetMapView(latLongArray);}
						
						}
						// on zoom resets the hotels icons back to its original location
						map.AttachEvent("onendzoom", onEndZoom);

						// after the user moves the map around reposition the bubble
						map.AttachEvent("onpan", DragHandler);
						mapLoaded = true;	
						
					}					

				}
				catch (Ex)
				{
					// the map div shows an error message
					buildErrorDiv();
				}
			}

		};// closing return block

	};// constructor with private methods

})();
