MapIconImages ={
	1: {normal:"/static/images/ui/icons/gradovi.png", rollover:"/static/images/ui/icons/gradovi.png", selected:"/static/images/ui/icons/gradovi.png"},
	2: {normal:"/static/images/ui/icons/opcine.png", rollover:"/static/images/ui/icons/opcine.png", selected:"/static/images/ui/icons/opcine.png"},
	3: {normal:"/static/images/ui/icons/ustanove.png", rollover:"/static/images/ui/icons/ustanove.png", selected:"/static/images/ui/icons/ustanove.png"},
	4: {normal:"/static/images/ui/icons/obrazovne.png", rollover:"/static/images/ui/icons/obrazovne.png", selected:"/static/images/ui/icons/obrazovne.png"},
	5: {normal:"/static/images/ui/icons/kulturne.png", rollover:"/static/images/ui/icons/kulturne.png", selected:"/static/images/ui/icons/kulturne.png"},
	6: {normal:"/static/images/ui/icons/poduzetnicke.png", rollover:"/static/images/ui/icons/poduzetnicke.png", selected:"/static/images/ui/icons/poduzetnicke.png"},
	7: {normal:"/static/images/ui/icons/turisticke.png", rollover:"/static/images/ui/icons/turisticke.png", selected:"/static/images/ui/icons/turisticke.png"},
	8: {normal:"/static/images/ui/icons/aerodromi.png", rollover:"/static/images/ui/icons/aerodromi.png", selected:"/static/images/ui/icons/aerodromi.png"},
	9: {normal:"/static/images/ui/icons/benzinske.png", rollover:"/static/images/ui/icons/benzinske.png", selected:"/static/images/ui/icons/benzinske.png"},
	shadowImage: "/static/images/ui/icons/shadow.png"
};


//////////////////////
// Class DataLoader //
//////////////////////

/* broadcasts events:
	onMarkersLoad - event object - {subtypeVal1: [{id: val, type: val, lat: val, lng: val, text: val}, ], subtypeVal2: [{id: val, type: val, lat: val, lng: val, text: val}, ]}
	onDataLoad - event object - {subtypeVal1: [itemid1,itemid2,...], subtypeVal2: [itemid1,itemid2,...], }
*/

function DataLoader(dataRequestUrl) {
	this.dataRequestUrl=dataRequestUrl;
	this.dataCache= new DataCache(this);
}

DataLoader.prototype=implementsInterface(Observable);

DataLoader.prototype.requestDataByType=function (dataType) {
	var obj=this;
	var xmlHttpRequestObject;
	var timeoutLength=60000;
	
	if (this.dataCache.isTypeLoaded(dataType)) {
		this.notifyListeners("onDataLoad",this.dataCache.getDataObjectIdsByType(dataType));
		this.notifyListeners("onMarkersLoad",this.dataCache.getMarkersByType(dataType));
	} else {
		window.setTimeout(function() {xmlHttpRequestObject=null;},timeoutLength);
		xmlHttpRequestObject=Ajax.getXMLHttpRequest();
		xmlHttpRequestObject.open("GET",this.dataRequestUrl+"?cmd=getlocbytype&t="+dataType,true);
		xmlHttpRequestObject.onreadystatechange=function() {
			var jsonResponseObject,data,markers;
			if (xmlHttpRequestObject.readyState==4) {
				if (Ajax.isSuccess(xmlHttpRequestObject)) {
					jsonResponseObject=Ajax.getResponseData(xmlHttpRequestObject,"json");
					if (jsonResponseObject.locationsdata.length===0) {
						return false;
					}
					obj.dataCache.storeData(jsonResponseObject.locationsdata);
					obj.dataCache.storeMarkers(jsonResponseObject.markers);
					obj.dataCache.setTypeIsLoaded(dataType);
					data=obj.dataCache.getDataObjectIdsByType(dataType);
					markers=obj.dataCache.getMarkersByType(dataType);
					obj.notifyListeners("onDataLoad",data);
					obj.notifyListeners("onMarkersLoad",markers);
				}
				xmlHttpRequestObject=null;
			}
		};
		xmlHttpRequestObject.send(null);
	}
};

DataLoader.prototype.requestDataBySubtype=function (dataType,dataSubtype) {
	var obj=this;
	var xmlHttpRequestObject;
	var timeoutLength=60000;
	
	/*if (this.dataCache.isSubtypeLoaded(dataType,dataSubtype)) {
		this.notifyListeners("onDataLoad",this.dataCache.getDataObjectIdsBySubtype(dataType,dataSubtype));
		this.notifyListeners("onMarkersLoad",this.dataCache.getMarkersBySubtype(dataType,dataSubtype));
	}*/ 

	if (this.dataCache.isTypeLoaded(dataType)) {
		this.notifyListeners("onDataLoad",this.dataCache.getDataObjectIdsBySubtype(dataType,dataSubtype));
		this.notifyListeners("onMarkersLoad",this.dataCache.getMarkersBySubtype(dataType,dataSubtype));
	} else {

		window.setTimeout(function() {xmlHttpRequestObject=null;},timeoutLength);
		xmlHttpRequestObject=Ajax.getXMLHttpRequest();
		xmlHttpRequestObject.open("GET",this.dataRequestUrl+"?cmd=getlocbytype&t="+dataType,true);
		xmlHttpRequestObject.onreadystatechange=function() {
			var jsonResponseObject,data,markers;
			if (xmlHttpRequestObject.readyState==4) {
				if (Ajax.isSuccess(xmlHttpRequestObject)) {
					jsonResponseObject=Ajax.getResponseData(xmlHttpRequestObject,"json");
					if (jsonResponseObject.locationsdata.length===0) {
						return false;
					}
					obj.dataCache.storeData(jsonResponseObject.locationsdata);
					obj.dataCache.storeMarkers(jsonResponseObject.markers);
					obj.dataCache.setTypeIsLoaded(dataType);
					data=obj.dataCache.getDataObjectIdsBySubtype(dataType,dataSubtype);
					markers=obj.dataCache.getMarkersBySubtype(dataType,dataSubtype);
					obj.notifyListeners("onDataLoad",data);
					obj.notifyListeners("onMarkersLoad",markers);
				}
				xmlHttpRequestObject=null;
			}
		};
		xmlHttpRequestObject.send(null);
	}
};

DataLoader.prototype.getMarkerHtml=function (id) {
	if (typeof this.dataCache.data[id] == "undefined") return false;
	return this.dataCache.data[id].getMarkerHtml();
};
	
DataLoader.prototype.getHtml=function (id) {
	if (typeof this.dataCache.data[id] == "undefined") return false;
	return this.dataCache.data[id].getHtml();
};

DataLoader.prototype.getType=function (id) {
	return this.dataCache.data[id].getType();
};


/////////////////////
// class DataCache //
/////////////////////

function DataCache() {
	this.data={};
	this.dataByType={};
	this.markersByType={};
	this.loadedTypes=[];
	this.subtypeNames={};
	// by type
	//this.dataClasses= {1:"LocationData", 2:"LocationData", 3:"LocationData"};
}

DataCache.prototype.storeData=function (dataArray) {
	for (var i=0; i<dataArray.length; i++) {
		this.addData(dataArray[i]);
		this.storeSubtypeNames(dataArray[i]);
	}
};

DataCache.prototype.storeSubtypeNames=function (locationsData) {
	if (typeof this.subtypeNames[locationsData["type"]]=="undefined") {
		this.subtypeNames[locationsData["type"]]={};
	}
	this.subtypeNames[locationsData["type"]][locationsData["subtype"]]=locationsData["subtype_name"];
}

DataCache.prototype.storeMarkers=function (markersArray) {
	var markerType,markerSubtype;
	for (var i=0; i<markersArray.length; i++) {
		markerType=markersArray[i]["type"];
		markerSubtype=markersArray[i]["subtype"];
		if (typeof this.markersByType[markerType]=="undefined") {
			this.markersByType[markerType]=[];
		}
		if (typeof this.markersByType[markerType][markerSubtype]=="undefined") {
			this.markersByType[markerType][markerSubtype]=[];
		}
		this.markersByType[markerType][markerSubtype].push(markersArray[i]);
	}
};

DataCache.prototype.addData=function (locationData) {
	var dataObject;
	dataObject=this.createDataObject(locationData["type"],locationData["id"],locationData["data"]);
	this.data[locationData["id"]]=dataObject;
	if (typeof this.dataByType[locationData["type"]]=="undefined") {
		this.dataByType[locationData["type"]]=[];
	}
	if (typeof this.dataByType[locationData["type"]][locationData["subtype"]]=="undefined") {
		this.dataByType[locationData["type"]][locationData["subtype"]]=[];
	}
	this.dataByType[locationData["type"]][locationData["subtype"]].push(locationData["id"]);
};

DataCache.prototype.createDataObject=function(type,id,data) {
	var dataObject;
	//eval("dataObject=new "+this.dataClasses[type]+"(id,type,data);");
	dataObject=new LocationData(id,type,data);
	return dataObject;
};

DataCache.prototype.getDataObject=function (id) {
	if (typeof this.data[id]== "undefined") {
		return false;
	} else {
		return this.data[id];
	}
};

DataCache.prototype.getDataObjectIdsByType=function (type) {
	if (typeof this.dataByType[type]== "undefined") {
		return false;
	} else {
		return this.dataByType[type];
	}
};

DataCache.prototype.getDataObjectIdsBySubtype=function (type,subtype) {
	var dataIds;
	if (typeof this.dataByType[type]=="undefined" || typeof this.dataByType[type][subtype]== "undefined") {
		return false;
	} else {
		dataIds=[];
		dataIds[subtype]=this.dataByType[type][subtype];
		return dataIds;
	}
};

DataCache.prototype.getMarkersByType=function(type) {
	var markers=[];
	if (typeof this.markersByType[type]== "undefined") {
		return false;
	} else {
		for (subtype in this.markersByType[type]) {
			for (var i=0; i<this.markersByType[type][subtype]; i++) {
				markers.push(this.markersByType[type][subtype][i]);
			}
		}
		return this.markersByType[type];
	}
};

DataCache.prototype.getMarkersBySubtype=function(type,subtype) {
	var markersArray;
	if (typeof this.markersByType[type]=="undefined" || typeof this.markersByType[type][subtype]== "undefined") {
		return false;
	} else {
		markersArray=[];
		markersArray[subtype]=this.markersByType[type][subtype];
		return markersArray;
	}
};

DataCache.prototype.getLocationsDataList=function (type, subtypes, onlySubtypeNames) {
	var listElement, locationIds, title, locationItem;
	var list=[];
	if (onlySubtypeNames===true) {
		for (var i=0; i<subtypes.length; i++) {
			listElement={};
			listElement["title"]=this.subtypeNames[type][subtypes[i]];
			listElement["htmldata"]=this.data[this.dataByType[type][subtypes[i]][0]].getListingHtml();
			list.push(listElement);
		}
	} else {
		for (var i=0; i<subtypes.length; i++) {
			listElement={};
			if (typeof this.subtypeNames[type][subtypes[i]]=="undefined") continue;
			listElement["title"]=this.subtypeNames[type][subtypes[i]];
			listElement["locations"]=[];
			locationIds=this.dataByType[type][subtypes[i]];
			for (var j=0; j<locationIds.length; j++) {
				locationItem={};
				locationItem["title"]=this.data[locationIds[j]].data.title;
				locationItem["htmldata"]=this.data[locationIds[j]].getListingHtml();
				listElement["locations"].push(locationItem);
			}
			list.push(listElement);
		}
	}
	return list;
}

DataCache.prototype.setTypeIsLoaded=function (type) {
	this.loadedTypes.push(type);
}

DataCache.prototype.isTypeLoaded=function (type) {
	for (var i=0; i<this.loadedTypes.length; i++) {
		if (this.loadedTypes[i]==type) return true;
	}
	return false;
}

DataCache.prototype.isSubtypeLoaded=function (type,subtype) {
	if (typeof this.dataByType[type]== "undefined" || typeof this.dataByType[type][subtype]== "undefined") {
		return false;
	}
	return true;
}


////////////////////////
// class LocationData //
////////////////////////

function LocationData(adId,type,data) {
	this.id=adId;
	this.type=type;
	this.data=data;
}


LocationData.prototype.getMarkerHtml=function() {
	var str;
	str='<div class="baloon"><div class="baloon_title">'+this.getTitle()+'</div><div class="pic_holder"><img  src="'+this.data.tn_uri+'"/></div><div class="baloon_text">'+this.getAddressHtml()+this.getPhoneHtml()+this.getWebHtml()+'</div></div>';
	return str;
};

LocationData.prototype.getListingHtml=function() {
	str=this.getAddressListingHtml()+this.getPhoneListingHtml()+this.getWebListingHtml();
	return str;
}

LocationData.prototype.getTitle=function () {
	if (this.data.title.length>60) {
		return this.data.title.substr(0,57)+"...";
	}
	return this.data.title;
}

LocationData.prototype.getAddressHtml=function () {
	var str;
	if (this.data.address!="") {
		str=this.data.address+'<br>'+this.data.city+'<br>'+this.data.postal_code+'<br>';
	} else {
		str=this.data.city+'<br>'+this.data.postal_code+'<br>';
	}
	return str;
}

LocationData.prototype.getAddressListingHtml=function () {
	var str;
	if (this.data.address!="") {
		str=this.data.address+', '+this.data.postal_code+" "+this.data.city;
	} else {
		str=this.data.postal_code+" "+this.data.city;
	}
	return str;
}

LocationData.prototype.getWebListingHtml=function () {
	return ', <a href="http://'+this.data.web+'" target="_blank">'+this.data.web+'</a>';
}

LocationData.prototype.getPhoneListingHtml=function () {
	var str;
	if (this.data.phone=="") {
		str="";
	} else {
		str=', tel: '+this.data.phone;
	}
	return str;
}

LocationData.prototype.getWebHtml=function () {
	if (this.data.web=="") return "";
	if (this.data.web.length<25) {
		return '<a href="http://'+this.data.web+'" target="_blank">'+this.data.web+'</a>';
	}
	return '<a href="http://'+this.data.web+'" target="_blank">web</a>';
}

LocationData.prototype.getPhoneHtml=function () {
	if (this.data.phone=="") return "";
	return 'tel: '+this.data.phone+'<br>';
}

LocationData.prototype.getValue=function (databaseField) {
	return this.data[databaseField];
}
	
LocationData.prototype.getType=function () {
	return this.type;
}

///////////////////////////
// Class MapLocationList //
///////////////////////////

/* locationList= [{element: HTMLElement, pos: {lat: float, lng: float, zoom: int},] */

function MapLocationList(map,locationList,countyImageElement) {
	this.map=map;
	this.selectedElement=null;
	this.countyImageElement=countyImageElement;
	this.locationList=locationList;
	this.init();
}
						   
MapLocationList.prototype.init=function () {
	var obj=this;
	for (var i=0; i< this.locationList.length; i++) {
		(function () {
			var j=i;
			DOMEvent.addDomListener(obj.locationList[j].element, "mouseover", function () {
				DHTMLApi.CSS.setClass(obj.locationList[j].element,["selected"],["not_selected"]);
			});
			
			DOMEvent.addDomListener(obj.locationList[j].element, "mouseout", function () {
				if (obj.selectedElement!=this) {
					DHTMLApi.CSS.setClass(obj.locationList[j].element,["not_selected"],["selected"]);
				}
			});
			DOMEvent.addDomListener(obj.locationList[j].element, "click", function () {
				if (obj.selectedElement !==null) {
					DHTMLApi.CSS.setClass(obj.selectedElement,["not_selected"],["selected"]);
				}
				obj.selectedElement=obj.locationList[j].element;
				obj.map.positionGMap(obj.locationList[j].pos);
				DHTMLApi.Visibility.hide(obj.countyImageElement);
			});
		})();
	}
}

////////////////////////////////////
// class NavigatorLocationListing //
////////////////////////////////////

function NavigatorLocationListing(container) {
	this.container=container;
}

NavigatorLocationListing.prototype.clear=function () {
	this.container.innerHTML="";
}

/* data - [{title: string, locations: [string, ]}] */

NavigatorLocationListing.prototype.display=function (data) {
	this.clear();
	for (var i=0; i<data.length; i++) {
		if (typeof data[i]["locations"] != "undefined") {
			this.displayTitle(data[i]["title"],false);
			this.displayLocations(data[i]["locations"]);
		} else {
			this.displayTitle(data[i]["title"],true);
			this.displayData(data[i]["htmldata"]);
		}
	}
}

NavigatorLocationListing.prototype.displayTitle=function (title,smallTitle) {
	var element;
	if (smallTitle===true) {
		element=document.createElement("P");
	} else {
		element=document.createElement("H1");
	}
	element.appendChild(document.createTextNode(title));
	this.container.appendChild(element);
}

NavigatorLocationListing.prototype.displayLocations=function (locations) {
	var element;
	for (var i=0; i<locations.length; i++) {
		element=document.createElement("P");
		element.appendChild(document.createTextNode(locations[i]['title']));
		this.container.appendChild(element);
		this.displayData(locations[i]["htmldata"]);
	}
}

NavigatorLocationListing.prototype.displayData=function (data) {
	var dataContainer=document.createElement("DIV");
	this.container.appendChild(dataContainer);
	dataContainer.innerHTML=data;
	
}

/////////////////////////
// Class NavigatorMenu //
/////////////////////////

function NavigatorMenu(dataLoader,map,listing,countyViewButton,countyImageElement) {
	this.dataLoader=dataLoader;
	this.map=map;
	this.listing=listing;
	this.countyViewButton=countyViewButton;
	this.countyImageElement=countyImageElement;
	this.menuHeadElements={};
	this.subMenuContainers={};
	this.subMenuItems={};
	this.subTypeSelected={};
	this.subMenuVisible={};
	this.subTypeMenuOrder={};
	this.selectedType=null;
	this.initType=false;
	this.initSubtype=false;
	this.dataLoader.addListener(this);
}

NavigatorMenu.prototype.addTypeMenu=function (type,menuHeadElement,subMenuContainer) {
	var spanElements,spanElementId,subtypeValue;
	this.menuHeadElements[type]=menuHeadElement;
	this.subMenuContainers[type]=subMenuContainer;
	this.subMenuItems[type]={};
	this.subMenuVisible[type]=false;
	this.subTypeSelected[type]={};
	this.subTypeMenuOrder[type]=[];
	// searching for span elements in subMenuContainer with id="subtype_<integer>"
	spanElements=subMenuContainer.getElementsByTagName("span");
	for (var i=0; i<spanElements.length; i++) {
		spanElementId=spanElements[i].getAttribute("id");
		if (spanElementId=="" || spanElementId===null) continue;
		if (spanElementId.indexOf("subtype_")!==-1) {
			subtypeValue=spanElementId.substr(8);
			this.subMenuItems[type][subtypeValue]=spanElements[i];
			this.subTypeSelected[type][subtypeValue]=false;
			this.subTypeMenuOrder[type].push(subtypeValue);
		}
	}
}

NavigatorMenu.prototype.setInitValue=function (initType,initSubtype) {
	if (initType===false) {
		DHTMLApi.Visibility.show(this.countyImageElement);
		DHTMLApi.Visibility.setOpacity(this.countyImageElement,50);
		return;
	}
	if (typeof(initType)!="undefined") {
		this.initType=initType;
		this.selectedType=initType;
		if (typeof(this.subMenuVisible[initType])!="undefined") {
			this.subMenuVisible[initType]=true;
		}
	}
	if (initSubtype===false) {
		this.dataLoader.requestDataByType(initType);
		return;
	}
	if (typeof(initSubtype)!="undefined") {
		this.initSubtype=initSubtype;
		if (typeof(this.subTypeSelected[initType])!="undefined") {
			if (typeof(this.subTypeSelected[initType][initSubtype])!="undefined") {
				this.subTypeSelected[initType][initSubtype]=true;
			}
			this.dataLoader.requestDataBySubtype(initType,initSubtype);
		}
	}
}

NavigatorMenu.prototype.init=function () {
	var obj=this;
	for (type in this.subMenuItems) {
		for (subtype in this.subMenuItems[type]) {
			(function () {
				var t,s;
				t=type;
				s=subtype;
				DOMEvent.addDomListener(obj.subMenuItems[type][subtype],"click",function () {
					if (obj.subTypeSelected[t][s]===false) {
						//alert ("activated");
						obj.subTypeSelected[t][s]=true;
						obj.displaySelectedSubmenu(t,s);
						obj.dataLoader.requestDataBySubtype(t,s);
					} else {
						//alert ("deactivated");
						obj.map.removeMarkersOfSubtype(t,s);
						obj.subTypeSelected[t][s]=false;
						obj.displayUnselectedSubmenu(t,s);
						obj.updateListing();
					}
					//alert ("type:"+t+" subtype:"+s);
				});
			})();
		}
		
		(function () {
				var t;
				t=type;
				DHTMLApi.Visibility.hide(obj.subMenuContainers[t]);
				if (obj.initType!==false && obj.initType==t) {
					DHTMLApi.Visibility.show(obj.subMenuContainers[t]);
					DHTMLApi.CSS.setClass(obj.menuHeadElements[t],["category_title_arrow_selected"],[]);
					if (obj.initSubtype!==false && typeof 	obj.subMenuItems[t][obj.initSubtype]!="undefined") {
						obj.displaySelectedSubmenu(t,obj.initSubtype);
						obj.subTypeSelected[t][obj.initSubtype]=true;
					} else {
						for (var subtype in obj.subMenuItems[t]) {
							obj.displaySelectedSubmenu(t,subtype);
							obj.subTypeSelected[t][subtype]=true;
						}
					}
				}
				DOMEvent.addDomListener(obj.menuHeadElements[t],"click",function () {
					//alert(obj.selectedType+" "+t);
					
					if(obj.selectedType!=t) {
						obj.hideCounty();
						//obj.map.removeAllMarkers();
						if (obj.selectedType!==null) {
							obj.map.removeAllMarkers();
							obj.unselectSubmenusByType(obj.selectedType);
							DHTMLApi.Visibility.hide(obj.subMenuContainers[obj.selectedType]);
							DHTMLApi.CSS.setClass(obj.menuHeadElements[obj.selectedType],[],["category_title_arrow_selected"]);
						}
						obj.selectSubmenusByType(t);
						obj.selectedType=t;
						obj.dataLoader.requestDataByType(t);
						DHTMLApi.Visibility.show(obj.subMenuContainers[t]);
						DHTMLApi.CSS.setClass(obj.menuHeadElements[t],["category_title_arrow_selected"],[]);
						obj.map.setCountyView();
					}
				});
		})();		
	}
	
	DOMEvent.addDomListener(this.countyViewButton,"click",function () {
		obj.displayCounty();
	});
}

NavigatorMenu.prototype.getSelectedSubtypes=function (type) {
	var subtype;
	var subtypes=[];
	if (typeof type=="undefined") return [];
	for (var i=0; i<this.subTypeMenuOrder[type].length; i++) {
		subtype=this.subTypeMenuOrder[type][i];
		if (this.subTypeSelected[type][subtype]) {
			subtypes.push(subtype);
		}
	}
	return subtypes;
}

NavigatorMenu.prototype.unselectSubmenusByType=function (type) {
	for (var subtype in this.subTypeSelected[type]) {
		this.subTypeSelected[type][subtype]=false;
		this.displayUnselectedSubmenu(type,subtype);
	}
}

NavigatorMenu.prototype.selectSubmenusByType=function (type) {
	for (var subtype in this.subTypeSelected[type]) {
		this.subTypeSelected[type][subtype]=true;
		this.displaySelectedSubmenu(type,subtype);
	}
}

NavigatorMenu.prototype.displaySelectedSubmenu=function (type,subtype) {
	//this.subMenuItems[type][subtype]
	DHTMLApi.CSS.setClass(this.subMenuItems[type][subtype],["selected"],[]);
}

NavigatorMenu.prototype.displayUnselectedSubmenu=function (type,subtype) {
	//this.subMenuItems[type][subtype]
	DHTMLApi.CSS.setClass(this.subMenuItems[type][subtype],[],["selected"]);
}

NavigatorMenu.prototype.displayCounty=function () {
	if (this.selectedType!==null) {
		this.unselectSubmenusByType(this.selectedType);
		DHTMLApi.Visibility.hide(this.subMenuContainers[this.selectedType]);
		DHTMLApi.CSS.setClass(this.menuHeadElements[this.selectedType],[],["category_title_arrow_selected"]);
		this.selectedType=null;
		this.map.removeAllMarkers();
	}
	this.map.setCountyView();
	DHTMLApi.Visibility.show(this.countyImageElement);
	DHTMLApi.Visibility.setOpacity(this.countyImageElement,50);
}

NavigatorMenu.prototype.hideCounty=function () {
	DHTMLApi.Visibility.hide(this.countyImageElement);
}

NavigatorMenu.prototype.updateListing=function () {
	var selectedSubtypes,listingData;
	selectedSubtypes=this.getSelectedSubtypes(this.selectedType);
	if (this.selectedType==1 || this.selectedType==2 || this.selectedType==3 || this.selectedType==6) {
		listingData=this.dataLoader.dataCache.getLocationsDataList(this.selectedType, selectedSubtypes, true);
	} else {
		listingData=this.dataLoader.dataCache.getLocationsDataList(this.selectedType, selectedSubtypes, false);
	}
	this.listing.display(listingData);
}

NavigatorMenu.prototype.onDataLoad=function (data) {
	this.updateListing();
}

////////////////////////////
// Class CountyViewButton //
////////////////////////////

function CountyViewButton(map,buttonElement,countyImageElement,navigatorMapObject) {
	this.map=map;
	this.buttonElement=buttonElement;
	this.countyImageElement=countyImageElement;
	this.navigatorMapObject=navigatorMapObject;
	this.init();
}

CountyViewButton.prototype.init=function () {
	var obj=this;
	DOMEvent.addDomListener(this.buttonElement,"click",function () {
		obj.buttonElement.setSelectedTypeToNull();
		obj.map.removeAllMarkers();
		obj.map.setCountyView();
	});
}


////////////////////////
// Class NavigatorMap //
////////////////////////

function NavigatorMap(mapContainerElement, dataLoaderObject, countyImageElement) {
	this.mapContainer=mapContainerElement;
	this.dataLoaderObject=dataLoaderObject;
	this.countyImageElement=countyImageElement;
	this.latDistance = null;
	this.lngDistance = null;
	this.currentlySelectedAdId=null;
	this.mapZoomControls=null;
	this.markers={};
	this.gMap=null;
	this.infoBaloonOverlay=null;
	this.infoToolTip=null;
	this.dataLoaderObject.addListener(this);
	this.createGMap();
}

NavigatorMap.prototype.createGMap=function() {
	if (GBrowserIsCompatible()) {
		this.gMap=new GMap2(this.mapContainer);		
		this.mapZoomControls=new MapZoomControls(this);
		this.gMap.addControl(this.mapZoomControls);
		this.gMap.addControl(new MapTypeControls(this.gMap, G_NORMAL_MAP));
		//this.positionGMap({lat: 45.81332572044041, lng: 15.977280735969543, zoom: 9});
		this.setCountyView();
		this.initMapHandlers();
	}
}

NavigatorMap.prototype.setCountyView=function () {
	this.positionGMap({lat: 45.81332572044041, lng: 15.977280735969543, zoom: 8});
}
	
NavigatorMap.prototype.positionGMap=function(mapData) {		
	this.mapPosition=new GLatLng(mapData.lat, mapData.lng);
	this.gMap.setCenter(this.mapPosition, mapData.zoom);
}
	
NavigatorMap.prototype.initMapHandlers=function() {
	var obj=this;
	GEvent.addListener(this.gMap,"dblclick",function(latlng) {
		this.zoomIn();
	});
	
	GEvent.addListener(this.gMap,"dragend",function() {
		var tempId;
		if (obj.infoBaloonOverlay!==null) {
			if (!obj.isLatLngWithinView(obj.markers[obj.currentlySelectedAdId].marker.getLatLng())) {
				obj.onAdUnselect();
			} else {
				tempId=obj.currentlySelectedAdId;
				obj.onAdUnselect();
				obj.displayAdBaloon(tempId);
			}
		}
	});
	
	GEvent.addListener(this.gMap,"zoomend", function() {
		obj.onAdUnselect();
	});
}
	
NavigatorMap.prototype.isLatLngWithinView=function (latLngObject) {
	var bounds=this.gMap.getBounds();
	return bounds.containsLatLng(latLngObject);
}

NavigatorMap.prototype.onAdUnselect=function() {
	if (typeof this.markers[this.currentlySelectedAdId] != "undefined") {
		this.markers[this.currentlySelectedAdId].displayUnselectedState();
	}
	this.hideInfoBaloon();
	this.currentlySelectedAdId=null;
}

// type - array or string or int

NavigatorMap.prototype.displayMarkersOfType=function (type) {
	this.dataLoaderObject.requestData(type);
}

NavigatorMap.prototype.addMarkers=function(markersData) {
	for (subtype in markersData) {
		for (var i=0; i<markersData[subtype].length; i++) {
			if (typeof this.markers[markersData[subtype][i].id]=="undefined") {
				this.markers[markersData[subtype][i].id]=new NavigatorMarker(markersData[subtype][i].id,markersData[subtype][i].type,markersData[subtype][i].lat,markersData[subtype][i].lng,markersData[subtype][i].text,this);
				this.gMap.addOverlay(this.markers[markersData[subtype][i].id].getGMarkerObject());
			}
		}
	}
}

// type - string or int

NavigatorMap.prototype.removeMarkersOfSubtype=function (type,subtype) {
	var removeMarkersData;
	removeMarkersData=this.dataLoaderObject.dataCache.getMarkersBySubtype(type,subtype);
	if (removeMarkersData===false) return;
	this.hideInfoBaloon();
	for (var i=0; i<removeMarkersData[subtype].length; i++) {
		if (typeof this.markers[removeMarkersData[subtype][i].id]!="undefined") {
			this.gMap.removeOverlay(this.markers[removeMarkersData[subtype][i].id].getGMarkerObject());
			delete this.markers[removeMarkersData[subtype][i].id];
		}
	}
}
	
NavigatorMap.prototype.removeAllMarkers=function () {
	this.hideInfoBaloon();
	for (var markerId in this.markers) this.gMap.removeOverlay(this.markers[markerId].getGMarkerObject());
	this.markers={};
}

NavigatorMap.prototype.showAdMarkerToolTip=function(adId) {
	if (this.infoToolTip!==null) this.hideToolTip();
	this.infoToolTip=this.markers[adId].getMarkerToolTip();
	this.gMap.addOverlay(this.infoToolTip);
}
		
NavigatorMap.prototype.hideToolTip=function() {
	if (this.infoToolTip===null) return;
	this.gMap.removeOverlay(this.infoToolTip);
	this.infoToolTip=null;
}
	
NavigatorMap.prototype.hideInfoBaloon=function() {
	if (this.infoBaloonOverlay!==null) {
		this.gMap.removeOverlay(this.infoBaloonOverlay);
		this.infoBaloonOverlay=null;
	}
}

NavigatorMap.prototype.displayAdBaloon=function (id) {
	this.infoBaloonOverlay=new NavigatorMapBaloon(id, this.markers[id].type, this.markers[id].marker,this.dataLoaderObject.getMarkerHtml(id),{width: 260, height: 120, horizontalPadding: 5, verticalPadding: 5, baloonAnchorImage: "/static/images/ui/icons/baloon_anchor.png", reversedBaloonAnchorImage: "/static/images/ui/icons/baloon_anchor_rev.png", closeImage: "/static/images/ui/icons/close_btn.gif", closeImagePaddingFromEdge: 5, baloonAnchorImageWidth: 11, baloonAnchorImageHeight: 11, baloonAnchorDistanceFromEdge: 20},this);
	this.currentlySelectedAdId=id;
	this.gMap.addOverlay(this.infoBaloonOverlay);
};

NavigatorMap.prototype.onMarkersLoad=function (markersData) {
	this.addMarkers(markersData);
}

NavigatorMap.prototype.hideCounty=function () {
	DHTMLApi.Visibility.hide(this.countyImageElement);
}

///////////////////////////
// Class MapZoomControls //
///////////////////////////

function MapZoomControls(adMap) {
	this.adMap=adMap;
	this.zoomOutButton=null;
}

MapZoomControls.prototype=new GControl(true);

MapZoomControls.prototype.initialize=function(map) {
	var controlsContainer, zoomInButton;
	var obj=this;
	controlsContainer=document.createElement("DIV");
	DHTMLApi.CSS.setClass(controlsContainer,["mapzoomcontrolscontainer"],[]);
	zoomInButton=document.createElement("DIV");
	zoomInButton.appendChild(document.createTextNode("+"));
	DHTMLApi.CSS.setClass(zoomInButton,["mapzoombutton"],[]);
	this.zoomOutButton=document.createElement("DIV");
	this.zoomOutButton.appendChild(document.createTextNode("-"));
	DHTMLApi.CSS.setClass(this.zoomOutButton,["mapzoombutton"],[]);
	controlsContainer.appendChild(zoomInButton);
	controlsContainer.appendChild(this.zoomOutButton);
	map.getContainer().appendChild(controlsContainer);
	
	DOMEvent.addDomListener(zoomInButton, "mouseover", function () {
		DHTMLApi.CSS.setClass(zoomInButton,["mapbuttonrollover"],[]);
	});
	
	DOMEvent.addDomListener(zoomInButton, "mouseout", function () {
		DHTMLApi.CSS.setClass(zoomInButton,[],["mapbuttonrollover"]);
	});
	
	DOMEvent.addDomListener(zoomInButton, "click", function () {
		obj.adMap.hideCounty();
		map.zoomIn();
	});
	
	DOMEvent.addDomListener(this.zoomOutButton, "mouseover", function () {
		DHTMLApi.CSS.setClass(obj.zoomOutButton,["mapbuttonrollover"],[]);
	});
	
	DOMEvent.addDomListener(this.zoomOutButton, "mouseout", function () {
		DHTMLApi.CSS.setClass(obj.zoomOutButton,[],["mapbuttonrollover"]);
	});
	
	DOMEvent.addDomListener(this.zoomOutButton, "click", function () {
		obj.adMap.hideCounty();
		map.zoomOut();
	});
	
	return controlsContainer;
};

MapZoomControls.prototype.getDefaultPosition=function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,5));
};


///////////////////////////
// Class MapTypeControls //
///////////////////////////

/* parameters: initType - int (index in type list or google map type)
*/

function MapTypeControls(gMap,initType) {
	this.selectedType=G_NORMAL_MAP;
	this.typeList=[G_NORMAL_MAP,G_HYBRID_MAP,G_SATELLITE_MAP];
	if (typeof initType=="number") {
		this.selectedType=initType;
	} else {
		for (var i=0; i<this.typeList.length; i++) {
			if (this.typeList[i]==initType) {
				this.selectedType=i;
				break;
			}
		}
	}
	this.buttons=[];
	gMap.setMapType(this.typeList[this.selectedType]);
}

MapTypeControls.prototype=new GControl(true);

MapTypeControls.prototype.initialize=function(map) {
	var controlsContainer, mapButton, hybridButton, sateliteButton;
	var obj=this;
	controlsContainer=document.createElement("DIV");
	DHTMLApi.CSS.setClass(controlsContainer,["maptypecontrolscontainer"],[]);
	this.buttons[0]=document.createElement("DIV");
	this.buttons[0].appendChild(document.createTextNode("map"));
	DHTMLApi.CSS.setClass(this.buttons[0],["maptypebutton"],[]);
	this.buttons[1]=document.createElement("DIV");
	this.buttons[1].appendChild(document.createTextNode("hybrid"));
	DHTMLApi.CSS.setClass(this.buttons[1],["maptypebutton"],[]);
	this.buttons[2]=document.createElement("DIV");
	this.buttons[2].appendChild(document.createTextNode("satellite"));
	DHTMLApi.CSS.setClass(this.buttons[2],["maptypebutton"],[]);
	controlsContainer.appendChild(this.buttons[2]);
	controlsContainer.appendChild(this.buttons[1]);
	controlsContainer.appendChild(this.buttons[0]);
	map.getContainer().appendChild(controlsContainer);
	
	if (this.selectedType!==null) {
		DHTMLApi.CSS.setClass(this.buttons[this.selectedType],["mapbuttonrollover"],[]);
	}
	
	for (var i=0; i<this.buttons.length;i++) {
		(function () {
			var j=i;

			DOMEvent.addDomListener(obj.buttons[j], "mouseover", function () {
				DHTMLApi.CSS.setClass(obj.buttons[j],["mapbuttonrollover"],[]);
			});
	
			DOMEvent.addDomListener(obj.buttons[j], "mouseout", function () {
				if (obj.selectedType!=j) {
					DHTMLApi.CSS.setClass(obj.buttons[j],[],["mapbuttonrollover"]);
				}
			});
	
			DOMEvent.addDomListener(obj.buttons[j], "click", function () {
				if (obj.selectedType!=j) {
					map.setMapType(obj.typeList[j]);
					DHTMLApi.CSS.setClass(obj.buttons[obj.selectedType],[],["mapbuttonrollover"]);
					obj.selectedType=j;
				}
			});
		}
		)();
	}
	
	return controlsContainer;
};

MapTypeControls.prototype.getDefaultPosition=function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,5));
};

///////////////////////////
// Class NavigatorMarker //
///////////////////////////

function NavigatorMarker(id,type,lat,lng,rolloverText,adMapObject) {
	this.id=id;
	this.type=type;	
	this.adMapObject=adMapObject;
	this.rolloverText=rolloverText;
	this.mouseOverHandler=null;
	this.mouseOutHandler=null;
	this.clickHandler=null;
	this.marker=new GMarker(new GLatLng(lat,lng),this.getGIcon());;
	this.initHandlers();
}

NavigatorMarker.prototype.getGIcon=function() {
	var adGIcon=new GIcon();
	adGIcon.image=MapIconImages[this.type].normal;
	adGIcon.iconSize=new GSize(22,35);
	adGIcon.iconAnchor=new GPoint(22,35);
	adGIcon.shadow=MapIconImages.shadowImage;
	adGIcon.shadowSize=new GSize(31,35);
	return adGIcon;
};

NavigatorMarker.prototype.initHandlers=function() {
	var obj=this;	
	this.mouseOverHandler=GEvent.addListener(this.marker,'mouseover', function() {
		obj.displayRollOverState(obj.id);
	});
	this.mouseOutHandler=GEvent.addListener(this.marker,'mouseout', function() {
		obj.displayRollOutState(obj.id);
	});
	
	this.clickHandler=GEvent.addListener(this.marker,'click', function() {
		obj.displaySelectedState();
	});
};

NavigatorMarker.prototype.removeHandlers=function() {
	GEvent.removeListener(this.mouseOverHandler);
	GEvent.removeListener(this.mouseOutHandler);
	GEvent.removeListener(this.clickHandler);
	this.mouseOverHandler=this.mouseOutHandler=this.clickHandler=null;
};

NavigatorMarker.prototype.displaySelectedState=function() {
	var obj=this;
	this.adMapObject.onAdUnselect();
	this.marker.setImage(MapIconImages[this.type].rollover);
	this.adMapObject.displayAdBaloon(obj.id);
	this.adMapObject.hideToolTip();
};

NavigatorMarker.prototype.displayUnselectedState=function() {
	if (this.clickHandler!==null) {
		GEvent.removeListener(this.clickHandler);
		this.clickHandler=null;
	}
	this.initHandlers();
	this.marker.setImage(MapIconImages[this.type].normal);
};

NavigatorMarker.prototype.displayRollOverState=function() {
	this.marker.setImage(MapIconImages[this.type].rollover);
	this.adMapObject.showAdMarkerToolTip(this.id);
};

NavigatorMarker.prototype.displayRollOutState=function() {
	this.marker.setImage(MapIconImages[this.type].normal);
	this.adMapObject.hideToolTip();
};

NavigatorMarker.prototype.getGMarkerObject=function() {	
	return this.marker;
};

NavigatorMarker.prototype.getMarkerToolTip=function () {
	return new NavigatorToolTip(this.marker,this.rolloverText,Math.round(this.adMapObject.gMap.getSize().width/2.5),"tooltip");
}


/////////////////////
// Class NavigatorToolTip //
/////////////////////

function NavigatorToolTip(marker,html,maxWidth,cssStyle) {
	this.marker=marker;
	this.html=html;
	this.maxWidth=maxWidth;
	this.cssStyle=cssStyle;
	this.containerElement=null;
	this.gMap=null;
	this.mapContainer=null;
}

NavigatorToolTip.prototype= new GOverlay();

NavigatorToolTip.prototype.initialize=function(map) {
	this.gMap=map;
	this.mapContainer=this.gMap.getContainer();
	this.containerElement=document.createElement("div");
	this.gMap.getPane(G_MAP_FLOAT_PANE).appendChild(this.containerElement);
	DHTMLApi.Visibility.hide(this.containerElement);
};

NavigatorToolTip.prototype.remove=function() {
	this.containerElement.parentNode.removeChild(this.containerElement);
};

NavigatorToolTip.prototype.copy=function() {
	return new NavigatorToolTip(this.marker,this.html,this.maxWidth,this.cssStyle);
};

NavigatorToolTip.prototype.redraw=function(force) {
	var toolTipPosition, toolTipWidth, toolTipHeight;
	if (!force) return;
	DHTMLApi.Visibility.setOpacity(this.containerElement,1);
	DHTMLApi.Visibility.show(this.containerElement);
	this.containerElement.innerHTML=this.html;
	DHTMLApi.CSS.setClass(this.containerElement,[this.cssStyle],[]);
	if (DHTMLApi.Size.getElementWidth(this.containerElement) > this.maxWidth) {
		DHTMLApi.CSS.setProperties(this.containerElement,{whiteSpace:"normal", width: this.maxWidth+"px"});
	} 
	toolTipWidth=DHTMLApi.Size.getElementWidth(this.containerElement);
	toolTipHeight=DHTMLApi.Size.getElementHeight(this.containerElement);
	toolTipPosition=this.getTooltipPosition(25,3,3,toolTipWidth, toolTipHeight);
	DHTMLApi.Position.setXPos(this.containerElement, toolTipPosition.x, this.mapContainer);
	DHTMLApi.Position.setYPos(this.containerElement, toolTipPosition.y, this.mapContainer);
	DHTMLApi.Visibility.setOpacity(this.containerElement,100);
};

NavigatorToolTip.prototype.getTooltipPosition=function(paddingHorizontalLeft,paddingHorizontalRight,paddingVertical,toolTipWidth,toolTipHeight) {
	var markerAnchorLocation, markerSize, mapSize, xPos, yPos;	
	markerAnchorLocation=this.gMap.fromLatLngToContainerPixel(this.marker.getLatLng()); // GPoint
	mapSize=this.gMap.getSize(); // GSize
	markerSize=this.marker.getIcon().iconSize; // GSize
	if (markerAnchorLocation.x < Math.round(mapSize.width/2)) {
		xPos=markerAnchorLocation.x + Math.round(markerSize.width/2) + paddingHorizontalRight;
	} else {
		xPos=markerAnchorLocation.x - Math.round(markerSize.width/2) - toolTipWidth - paddingHorizontalLeft;
	}
	if (markerAnchorLocation.y < markerSize.height) {
		yPos=markerAnchorLocation.y + paddingVertical;
	} else if (markerAnchorLocation.y >= mapSize.height) {
		yPos=markerAnchorLocation.y - markerSize.height - paddingVertical - toolTipHeight;
	} else {
		yPos=markerAnchorLocation.y - markerSize.height;
	}
	return new GPoint(xPos, yPos);
};

//////////////////////////
// class NavigatorMapBaloon //
//////////////////////////

/*
adBaloonData= {
width: baloon width, 
height: baloon height, 
horizontalPadding: horizontal baloon content padding, 
verticalPadding: veritcal baloon content padding, 
baloonAnchorImage: baloon root image file name, 
reversedBaloonAnchorImage: reversed baloon root image file name,
closeImage: close baloon image file name,
closeImagePaddingFromEdge: padding form edge of baloon window, 
baloonAnchorImageWidth: img width, 
baloonAnchorImageHeight: img height
baloonAnchorDistanceFromEdge: distance of baloon anchor from left and right edges of baloon
}
*/

function NavigatorMapBaloon(adId,adType,marker,html,adBaloonData,mapObject) {
	this.id=adId;
	this.adType=adType;
	this.marker=marker;
	this.html=html;
	this.adBaloonData=adBaloonData;
	this.mapObject=mapObject;
	this.containerElement=null;
	this.baloonElement=null;
	this.baloonContentElement=null;
	this.baloonAnchorImageElement=null;
	this.closeBaloonButtonImageElement=null;
	this.closeBaloonHandler=null;
	this.gMap=null;
	this.mapContainer=null;
}

NavigatorMapBaloon.prototype= new GOverlay()

NavigatorMapBaloon.prototype.addCloseBaloonHandler=function () {
	var obj=this;
	this.closeBaloonHandler=DOMEvent.addDomListener(this.closeBaloonButtonImageElement, "click", function () {obj.mapObject.onAdUnselect();});
};

NavigatorMapBaloon.prototype.removeHandlers=function () {
	DOMEvent.removeListener(this.closeBaloonHandler);
	this.closeBaloonHandler=null;
};

NavigatorMapBaloon.prototype.remove=function() {
	this.removeHandlers();
	this.containerElement.parentNode.removeChild(this.containerElement);
};

NavigatorMapBaloon.prototype.copy=function() {
	return new NavigatorMapBaloon(this.id,this.type,this.marker,this.html,this.adBaloonData,this.mapObject);
};

NavigatorMapBaloon.prototype.redraw=function(force) {
	var baloonPosition;
	if (!force) return;
	DHTMLApi.Visibility.setOpacity(this.containerElement,1);
	DHTMLApi.Visibility.show(this.containerElement);
	this.baloonContentElement.innerHTML=this.html;
	baloonPosition=this.getBaloonPosition(3);
	this.arrangeBaloonElements(baloonPosition.pos.x,baloonPosition.pos.y,baloonPosition.reversePosition, baloonPosition.anchorOrientationLeft);
	DHTMLApi.Position.setXPos(this.containerElement, baloonPosition.pos.x, this.mapContainer);
	DHTMLApi.Position.setYPos(this.containerElement, baloonPosition.pos.y, this.mapContainer);
	DHTMLApi.Visibility.setOpacity(this.containerElement,100);
}

NavigatorMapBaloon.prototype.initialize=function(map) {
	this.gMap=map;
	this.mapContainer=this.gMap.getContainer();
	this.createBaloonElements();
	this.gMap.getPane(G_MAP_FLOAT_PANE).appendChild(this.containerElement);
	DHTMLApi.Visibility.hide(this.containerElement);
	this.addCloseBaloonHandler();
}

NavigatorMapBaloon.prototype.getBaloonPosition=function(paddingVertical) {
	var markerAnchorLocation, markerSize, markerVerticalAnchor, mapSize, xPos, yPos, reversePos, anchorOrientationLeft;	
	markerAnchorLocation=this.gMap.fromLatLngToContainerPixel(this.marker.getLatLng()); // GPoint
	mapSize=this.gMap.getSize(); // GSize
	markerSize=this.marker.getIcon().iconSize; // GSize
	markerVerticalAnchor=this.marker.getIcon().iconAnchor.y;
	
	if (markerAnchorLocation.x < this.adBaloonData.baloonAnchorDistanceFromEdge) {
		xPos=0;
	} else if (markerAnchorLocation.x > mapSize.width-this.adBaloonData.baloonAnchorDistanceFromEdge) {
		xPos=mapSize.width - this.adBaloonData.width;
	} else if (markerAnchorLocation.x < Math.round((mapSize.width - this.adBaloonData.width)/2) + this.adBaloonData.baloonAnchorDistanceFromEdge) {
		xPos=markerAnchorLocation.x - this.adBaloonData.baloonAnchorDistanceFromEdge;
	} else if (markerAnchorLocation.x > Math.round((mapSize.width + this.adBaloonData.width)/2) - this.adBaloonData.baloonAnchorDistanceFromEdge) {
		xPos=markerAnchorLocation.x - this.adBaloonData.width + this.adBaloonData.baloonAnchorDistanceFromEdge;
	} else {
		xPos=Math.round((mapSize.width - this.adBaloonData.width)/2);
	}
	
	if (markerAnchorLocation.y > Math.round(mapSize.height/2)+20) {
		yPos=markerAnchorLocation.y - paddingVertical - markerVerticalAnchor - this.adBaloonData.height - this.adBaloonData.baloonAnchorImageHeight;
		reversePos=false;
	} else {
		yPos=markerAnchorLocation.y + markerSize.height - markerVerticalAnchor + paddingVertical;
		reversePos=true;
	}
	return {pos: new GPoint(xPos, yPos), reversePosition: reversePos};
}

NavigatorMapBaloon.prototype.setBaloonAnchorXPosition=function (posX) {
	var markerAnchorLocation, mapWidth, leftPos;
	
	markerAnchorLocation=this.gMap.fromLatLngToContainerPixel(this.marker.getLatLng()); // GPoint
	mapWidth=this.gMap.getSize().width;
	leftPos=markerAnchorLocation.x-posX-Math.round(this.adBaloonData.baloonAnchorImageWidth/2);
	if (leftPos < 0) leftPos=0;
	if (leftPos > this.adBaloonData.width-this.adBaloonData.baloonAnchorImageWidth) leftPos=this.adBaloonData.width-this.adBaloonData.baloonAnchorImageWidth;
	DHTMLApi.CSS.setProperties(this.baloonAnchorImageElement,{left: leftPos + "px"});
}

NavigatorMapBaloon.prototype.getAdId=function () {
	return this.id;
}
	
NavigatorMapBaloon.prototype.getAdType=function () {
	return this.adType;
}
	
NavigatorMapBaloon.prototype.createBaloonElements=function() {
	this.containerElement=document.createElement("div");
	this.baloonElement=document.createElement("div");
	this.containerElement.appendChild(this.baloonElement);
	this.baloonContentElement=document.createElement("div");
	this.baloonElement.appendChild(this.baloonContentElement);
	this.baloonAnchorImageElement=document.createElement("img");
	this.containerElement.appendChild(this.baloonAnchorImageElement);
	this.closeBaloonButtonImageElement=document.createElement("img");
	this.baloonElement.appendChild(this.closeBaloonButtonImageElement);
}
	
NavigatorMapBaloon.prototype.arrangeBaloonElements=function(posX,posY,reversePosition, anchorOrientationLeft) {
	DHTMLApi.CSS.setProperties(this.containerElement,{width: this.adBaloonData.width+"px", height: (this.adBaloonData.height+this.adBaloonData.baloonAnchorImageHeight)+"px", position:"absolute"});
	DHTMLApi.CSS.setProperties(this.baloonContentElement,{width: (this.adBaloonData.width-2*(this.adBaloonData.horizontalPadding+1))+"px", height: (this.adBaloonData.height-2*(this.adBaloonData.verticalPadding+1))+"px", position: "absolute", top: this.adBaloonData.verticalPadding+"px", left: this.adBaloonData.horizontalPadding+"px"});
	this.closeBaloonButtonImageElement.setAttribute("src",this.adBaloonData.closeImage);
	DHTMLApi.CSS.setProperties(this.closeBaloonButtonImageElement, {position: "absolute", top: this.adBaloonData.closeImagePaddingFromEdge +"px", right: this.adBaloonData.closeImagePaddingFromEdge +"px", cursor: "pointer"});
	if (reversePosition) {
		DHTMLApi.CSS.setProperties(this.baloonElement,{width: (this.adBaloonData.width-2)+"px", height: (this.adBaloonData.height-2)+"px", position: "absolute", left: "0px", top: (this.adBaloonData.baloonAnchorImageHeight-1)+"px",backgroundColor: "#FFFFFF", border: "1px solid #000000", zIndex:1});
		this.baloonAnchorImageElement.setAttribute("src",this.adBaloonData.reversedBaloonAnchorImage);
		DHTMLApi.CSS.setProperties(this.baloonAnchorImageElement,{position: "absolute", top: "0px", zIndex:2});
	} else {
		DHTMLApi.CSS.setProperties(this.baloonElement,{width: (this.adBaloonData.width-2)+"px", height: (this.adBaloonData.height-2)+"px", position: "absolute", left: "0px", top: "1px", backgroundColor: "#FFFFFF", border: "1px solid #000000", zIndex:1});
		this.baloonAnchorImageElement.setAttribute("src",this.adBaloonData.baloonAnchorImage);
		DHTMLApi.CSS.setProperties(this.baloonAnchorImageElement,{position: "absolute", bottom:"0px", zIndex:2});
	}
	DHTMLApi.CSS.setProperties(this.baloonAnchorImageElement, {width: this.adBaloonData.baloonAnchorImageWidth+"px", height: this.adBaloonData.baloonAnchorImageHeight+"px"});
	this.setBaloonAnchorXPosition(posX);
}
