MapIconImages ={
	store: {normal:"../../images/map_markers/lacoste.png", rollover:"../../images/map_markers/lacoste.png", selected:"../../images/map_markers/lacoste.png"},
	lacoste: {normal:"../../images/map_markers/lacoste.png", rollover:"../../images/map_markers/lacoste.png", selected:"../../images/map_markers/lacoste.png"},
	ck: {normal:"../../images/map_markers/ck.png", rollover:"../../images/map_markers/ck.png", selected:"../../images/map_markers/ck.png"},
	high: {normal:"../../images/map_markers/high.png", rollover:"../../images/map_markers/high.png", selected:"../../images/map_markers/high.png"},
	high_club: {normal:"../../images/map_markers/high_club.png", rollover:"../../images/map_markers/high_club.png", selected:"../../images/map_markers/high_club.png"},
	speedo: {normal:"../../images/map_markers/speedo.png", rollover:"../../images/map_markers/speedo.png", selected:"../../images/map_markers/speedo.png"},
	boxfresh: {normal:"../../images/map_markers/boxfresh.png", rollover:"../../images/map_markers/boxfresh.png", selected:"../../images/map_markers/boxfresh.png"},
	outlet: {normal:"../../images/map_markers/outlet.png", rollover:"../../images/map_markers/outlet.png", selected:"../../images/map_markers/outlet.png"},
	shadowImage: "../../images/map_markers/shadow.png"
};


/////////////////////
// class StoreData //
/////////////////////

function StoreData(adId,type,data) {
	this.id=adId;
	this.type=type;
	this.data=data;
}


StoreData.prototype.getMarkerHtml=function() {
	var str;
	str='<div class="baloon"><div class="baloon_title">'+this.data.title+'</div><div class="pic_holder"><img src="'+this.data.tn_uri+'"/></div><div class="baloon_text">'+this.getShopName()+this.getAddressHtml()+this.getPhone()+'<br>'+this.getEmail()+'</div></div>';
	return str;
};

StoreData.prototype.getAddressHtml=function () {
	var str;
	str="";
	if (this.data.street!="") str+=this.data.street+' '+this.data.house_nr+'<br>';
	str+=this.data.city_name;
	return str;
}

StoreData.prototype.getShopName=function () {
	if (this.data.shop_name=="") return "";
	return this.data.shop_name+'<br>'
}

StoreData.prototype.getPhone=function () {
	if (this.data.phone=="") return "";
	return '<br>tel: '+this.data.phone;
}

StoreData.prototype.getEmail=function () {
	if (this.data.email.length<25) {
		return '<a href="mailto:'+this.data.email+'">'+this.data.email+'</a>';
	} else {
		return '<a href="mailto:'+this.data.email+'">e-mail</a>';
	}
}

StoreData.prototype.getValue=function (databaseField) {
	return this.data[databaseField];
}
	
StoreData.prototype.getType=function () {
	return this.type;
}

//////////////////////
// class StoreCache //
//////////////////////

function StoreCache(markersInitArray,storeInitArray) {
	this.markersData={};
	this.adsData={};
	this.storeMarkers(markersInitArray);
	this.storeAds(storeInitArray);
}

StoreCache.prototype.storeAds=function (adsArray) {
	var adDataObject;
	for (var i=0; i<adsArray.length; i++) {
		this.addAd(adsArray[i]);
	}
};

StoreCache.prototype.storeMarkers=function (markersArray) {
	var markerType;
	for (var i=0; i<markersArray.length; i++) {
		markerType=markersArray[i].type;
		if (typeof this.markersData[markerType] == "undefined") this.markersData[markerType]=[];
		this.markersData[markerType].push(markersArray[i]);
	}
};

StoreCache.prototype.addAd=function (adData) {
	var adDataObject;
	adDataObject=new StoreData(adData["id"],adData["type"],adData["data"]);
	this.adsData[adData["id"]]=adDataObject;
};

StoreCache.prototype.getAdData=function (id) {
	if (typeof this.adsData[id]== "undefined") {
		return false;
	} else {
		return this.adsData[id];
	}
};

StoreCache.prototype.getMarkersData=function (type) {
	return this.markersData[type];
}

/////////////////////////////
// Class StoreLocationList //
/////////////////////////////

/* locationList= [{element: HTMLElement, pos: {lat: float, lng: float, zoom: int},] */

function StoreLocationList(map,locationList) {
	this.map=map;
	this.selectedElement=null;
	this.locationList=locationList;
	this.init();
}
						   
StoreLocationList.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);
			});
		})();
	}
}

////////////////////
// Class StoreMap //
////////////////////

function StoreMap(mapContainerElement, storeCache) {
	this.mapContainer=mapContainerElement;
	this.storeCache=storeCache;
	this.latDistance = null;
	this.lngDistance = null;
	this.currentlySelectedAdId=null;
	this.mapZoomControls=null;
	this.adMarkers={};
	this.gMap=null;
	this.infoBaloonOverlay=null;
	this.infoToolTip=null;
	this.createGMap();
}

StoreMap.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: 44.59046718130883, lng: 16.54541015625, zoom: 6});
		this.initMapHandlers();
	}
}
	
StoreMap.prototype.positionGMap=function(mapData) {		
	this.mapPosition=new GLatLng(mapData.lat, mapData.lng);
	this.gMap.setCenter(this.mapPosition, mapData.zoom);
}
	
StoreMap.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.adMarkers[obj.currentlySelectedAdId].marker.getLatLng())) {
				obj.onAdUnselect();
			} else {
				tempId=obj.currentlySelectedAdId;
				obj.onAdUnselect();
				obj.displayAdBaloon(tempId);
			}
		}
	});
	
	GEvent.addListener(this.gMap,"zoomend", function() {
		obj.onAdUnselect();
	});
}
	
StoreMap.prototype.isLatLngWithinView=function (latLngObject) {
	var bounds=this.gMap.getBounds();
	return bounds.containsLatLng(latLngObject);
}

StoreMap.prototype.onAdUnselect=function() {
	if (typeof this.adMarkers[this.currentlySelectedAdId] != "undefined") {
		this.adMarkers[this.currentlySelectedAdId].displayUnselectedState();
	}
	this.hideInfoBaloon();
	this.currentlySelectedAdId=null;
}

StoreMap.prototype.displayMarkersOfType=function (type) {
	this.hideInfoBaloon();
	this.removeAllMarkers();
	this.addMarkers(this.storeCache.getMarkersData(type));
}

StoreMap.prototype.addMarkers=function(markersData) {
	for (var i=0; i<markersData.length; i++) {
		if (typeof this.adMarkers[markersData[i].id]=="undefined") {
			this.adMarkers[markersData[i].id]=new StoreMarker(markersData[i].id,markersData[i].type,markersData[i].lat,markersData[i].lng,markersData[i].text,this);
			this.gMap.addOverlay(this.adMarkers[markersData[i].id].getGMarkerObject());
		}
	}
}
	
StoreMap.prototype.removeAllMarkers=function () {
	for (var markerId in this.adMarkers) this.gMap.removeOverlay(this.adMarkers[markerId].getGMarkerObject());
	this.adMarkers={};
}

StoreMap.prototype.showAdMarkerToolTip=function(adId) {
	if (this.infoToolTip!==null) this.hideToolTip();
	this.infoToolTip=this.adMarkers[adId].getMarkerToolTip();
	this.gMap.addOverlay(this.infoToolTip);
}
		
StoreMap.prototype.hideToolTip=function() {
	if (this.infoToolTip===null) return;
	this.gMap.removeOverlay(this.infoToolTip);
	this.infoToolTip=null;
}
	
StoreMap.prototype.hideInfoBaloon=function() {
	if (this.infoBaloonOverlay!==null) {
		this.gMap.removeOverlay(this.infoBaloonOverlay);
		this.infoBaloonOverlay=null;
	}
}

StoreMap.prototype.displayAdBaloon=function (id) {
	this.infoBaloonOverlay=new StoreMapBaloon(id, this.adMarkers[id].type, this.adMarkers[id].marker,this.storeCache.getAdData(id).getMarkerHtml(),{width: 260, height: 120, horizontalPadding: 5, verticalPadding: 5, baloonAnchorImage: "../../images/map_markers/baloon_anchor.png", reversedBaloonAnchorImage: "../../images/map_markers/baloon_anchor_rev.png", closeImage: "../../images/map_markers/close_btn.gif", closeImagePaddingFromEdge: 5, baloonAnchorImageWidth: 11, baloonAnchorImageHeight: 11, baloonAnchorDistanceFromEdge: 20},this);
	this.currentlySelectedAdId=id;
	this.gMap.addOverlay(this.infoBaloonOverlay);
};


///////////////////////////
// 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 () {
		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 () {
		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 StoreMarker //
///////////////////////

function StoreMarker(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();
}

StoreMarker.prototype.getGIcon=function() {
	var adGIcon=new GIcon();
	adGIcon.image=MapIconImages[this.type].normal;
	adGIcon.iconSize=new GSize(32,35);
	adGIcon.iconAnchor=new GPoint(10,35);
	adGIcon.shadow=MapIconImages.shadowImage;
	adGIcon.shadowSize=new GSize(43,35);
	return adGIcon;
};

StoreMarker.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();
	});
};

StoreMarker.prototype.removeHandlers=function() {
	GEvent.removeListener(this.mouseOverHandler);
	GEvent.removeListener(this.mouseOutHandler);
	GEvent.removeListener(this.clickHandler);
	this.mouseOverHandler=this.mouseOutHandler=this.clickHandler=null;
};

StoreMarker.prototype.displaySelectedState=function() {
	var obj=this;
	this.adMapObject.onAdUnselect();
	this.marker.setImage(MapIconImages[this.type].rollover);
	this.adMapObject.displayAdBaloon(obj.id);
	this.adMapObject.hideToolTip();
};

StoreMarker.prototype.displayUnselectedState=function() {
	if (this.clickHandler!==null) {
		GEvent.removeListener(this.clickHandler);
		this.clickHandler=null;
	}
	this.initHandlers();
	this.marker.setImage(MapIconImages[this.type].normal);
};

StoreMarker.prototype.displayRollOverState=function() {
	this.marker.setImage(MapIconImages[this.type].rollover);
	this.adMapObject.showAdMarkerToolTip(this.id);
};

StoreMarker.prototype.displayRollOutState=function() {
	this.marker.setImage(MapIconImages[this.type].normal);
	this.adMapObject.hideToolTip();
};

StoreMarker.prototype.getGMarkerObject=function() {	
	return this.marker;
};

StoreMarker.prototype.getMarkerToolTip=function () {
	return new AdToolTip(this.marker,this.rolloverText,Math.round(this.adMapObject.gMap.getSize().width/2.5),"tooltip");
}


/////////////////////
// Class AdToolTip //
/////////////////////

function AdToolTip(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;
}

AdToolTip.prototype= new GOverlay();

AdToolTip.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);
};

AdToolTip.prototype.remove=function() {
	this.containerElement.parentNode.removeChild(this.containerElement);
};

AdToolTip.prototype.copy=function() {
	return new AdToolTip(this.marker,this.html,this.maxWidth,this.cssStyle);
};

AdToolTip.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(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);
};

AdToolTip.prototype.getTooltipPosition=function(paddingHorizontal,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) + paddingHorizontal;
	} else {
		xPos=markerAnchorLocation.x - Math.round(markerSize.width/2) - toolTipWidth - paddingHorizontal;
	}
	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 StoreMapBaloon //
//////////////////////////

/*
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 StoreMapBaloon(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;
}

StoreMapBaloon.prototype= new GOverlay()

StoreMapBaloon.prototype.addCloseBaloonHandler=function () {
	var obj=this;
	this.closeBaloonHandler=DOMEvent.addDomListener(this.closeBaloonButtonImageElement, "click", function () {obj.mapObject.onAdUnselect();});
};

StoreMapBaloon.prototype.removeHandlers=function () {
	DOMEvent.removeListener(this.closeBaloonHandler);
	this.closeBaloonHandler=null;
};

StoreMapBaloon.prototype.remove=function() {
	this.removeHandlers();
	this.containerElement.parentNode.removeChild(this.containerElement);
};

StoreMapBaloon.prototype.copy=function() {
	return new StoreMapBaloon(this.id,this.type,this.marker,this.html,this.adBaloonData,this.mapObject);
};

StoreMapBaloon.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);
}

StoreMapBaloon.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();
}

StoreMapBaloon.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};
}

StoreMapBaloon.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"});
}

StoreMapBaloon.prototype.getAdId=function () {
	return this.id;
}
	
StoreMapBaloon.prototype.getAdType=function () {
	return this.adType;
}
	
StoreMapBaloon.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);
}
	
StoreMapBaloon.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);
}