/**
 * @author Martin Trenker
 */
 
jMap = function() {
  var map;
  var options;
	  
  // private functions
  var initMap = function(container, options) {
		map = new GMap2(container);
		this.map = map;
		this.map.addControl(new GSmallMapControl());
    this.options = options;
    center(this.options.Lat, this.options.Lng, this.options.Zoom);
		
    return this.map;
  };
  
  var center = function(lat, lng, zoom) {
    this.map.setCenter(new GLatLng(lat, lng), zoom);
  }
  
  var clearMarkers = function() {
    this.map.clearOverlays();
  }
	
	var addOverlay = function(marker) {
		this.map.addOverlay(marker)
	}
	
  // public space
  return {
    // Public vars
    markers: Array(),
 
    // public methods
    init: function(container, options) {
      return initMap(container, options);
    },
		   
    setCenter: function(lat, lng, zoom) {
      center(lat, lng, zoom);
    },
    
    addMarker: function(marker) {
      addOverlay(marker);
    },
    
    clearMarkers: function() {
      clearMarkers();
    },
		
		//lockMap: function() {
		//	div = document.createElement('div');
		//	content = $("#content");
		//	coords = content.offset();
		//	div.id = 'overlay'
		//	div.style.backgroundColor = '#000'
		//	div.style.position = 'absolute'
		//	div.style.top = parseInt(coords.top)+'px'
		//	div.style.left = parseInt(coords.left)+'px'
		//  div.style.filter = 'alpha(opacity=33)'
		//	div.style.mozOpacity = '.33'
		//	div.style.opacity = '.33'
		//	div.style.width = content.width()+20+'px'
		//	div.style.height = content.height()+'px'
		//	document.body.appendChild(div)
		//},
		
		//releaseMap: function() {
		//	$('#overlay').hide();
		//},
    		
		addMarkers: function(i) {
			marker = this.markers[i++];
			if(!marker) {
				//jMap.releaseMap();
				return;
			}
			setTimeout(function(){
				addOverlay(marker);
				if(marker.hideMe) marker.hide();
				jMap.addMarkers(i)
			}, 0);
		}
  };
}();