/**
 * Create a new instance of VCMLocationMap
 * @classDescription Class for the Location Map
 * @param {VCMContent} content Reference to VCMContent
 * @return {VCMLocationMap} Returns a new VCMLocationMap object
 * @constructor
 */
function VCMLocationMap(content) {
	this._content = content;
}

VCMLocationMap.prototype = {
	/**
	 * Reference to the VCMContent parent
	 * @type {VCMContent}
	 */
	_content: null,
	
	_locations: null,
	
	/**
	 * Initialize the Location Map
	 */
	init: function() {
		console.log('VCMLocationMap.init()');
		var me = this;
		this._locations = $('.detailLocation');
		this._locations.click(function() {
			var idLoca = VCMUtils.findNumber($(this).attr('id'));
			var command = VCMUtils.prepareCommand({id:idLoca,command:'displayLocationMap'});
			//if($('.detailLocation').parent('.representation_salle').attr('id')===undefined){
			if($(this).hasClass('bouton')){
				command += "&showButton=false";
			}else{
				command += "&showButton=true";
			}
			$("#popupContent").load(command,function() {
				me.show();
			});
			return false;
		});
	},
	
	/**
	 * Destroy the location map
	 */
	destroy: function() {
		this._locations.unbind('click');
		this._locations = null;
	},
	
	/**
	 * Show the location map
	 * @private
	 */
	show: function() {		
		var me = this;
		$('.locationDetail,.locationName').click(function() {
			me._content.showLocation(VCMUtils.findNumber($(this).attr('id')));
			me._content.getPage().getModal().close();
			me.close();
		});
		$("#closePopupLnk").click(function() {
			me._content.getPage().getModal().close();
			me.close();
		});
		$("#popupCloseArea").click(function(){
			me.close();
		});
		
		if($('#mapURL').length != 1 && GBrowserIsCompatible()){
			this.loadGoogleMap();
		}
		
		this._content.getPage().getModal().show();
	},

	/**
	 * Destroy the location map
	 */
	close: function() {
		$('.locationDetail').unbind('click');
		$("#closePopupLnk").unbind('click');
	},

	/**
	 * Load Google Map
	 */		
	loadGoogleMap: function() { 
		$('#map').empty();
		$('#popupCloseArea').click(GUnload);
		$("#closePopupLnk").click(GUnload);
		var lat = $('#lat').text();
		var longi = $('#long').text();	
		var locationName = $('#dvlocationMapTitle').html();
		var locationAddress = $('#dvLocationMapAddress').html();
	  	var divMap = document.getElementById('map');
	    var map = new GMap2(divMap);
		map.setCenter(new GLatLng(lat,longi), 15);
		map.setUIToDefault();
		var point = new GLatLng(lat, longi);
		var gMarker = new GMarker(point);
		map.addOverlay(gMarker);
		map.openInfoWindowHtml(map.getCenter(), locationName+"<br/>"+locationAddress);
	}
};


