/*
	Custom class for marker content
	usage: new gmap.MarkerWindow(marker:GMarker);
	To completely replace the GWindow, modify similar to the following example: http://ajaxian.com/archives/custom-info-windows-with-jquery-and-google-maps
*/
gmap.MarkerWindow=(function(){
	
	var MarkerWindow=function(opts){
		var I=this;
		I.defaults = {
			marker:null, //GMarker - http://code.google.com/apis/maps/documentation/reference.html#GMarker
			maxHeight:125,
			minHeight:70,
			content:null //HTML DOM element that contains all of the locations' contents
			
		};
		j.extend(I, I.defaults, opts);

		I.init();
	
	}
	
	
	// ---- PUBLIC MEMBERS --------------------------
	MarkerWindow.prototype={
		init:function(){
			var I=this;
			var gw = gmap.map.getInfoWindow();
			if(!I.content || !I.content.nodeName){
				I.content = document.createElement("div");
				I.content.className="box-locations";
			}
			
			I.refresh();
			GEvent.addListener(I.marker, "click", function(evt){I._markerClicked(evt)});
		},
		refresh:function(){			
			var I=this;
			I.marker.getLocations();
			
			var content = j(I.content);
			content.empty();
			for(var l=0; l<I.marker.locations.length; l++){
				content.append(I.marker.locations[l].content);
			}
			I.marker.bindInfoWindow(content[0]);
			
			if(I.marker.locations.length==1){
				content.css({height:I.minHeight, overflow:"hidden"});					
			}else if(I.marker.locations.length>1){
				content.css({height:I.maxHeight, overflow:"scroll",overflowX:"hidden"});					
			}
		},
		kill:function(){
			var I=this;
			I.marker.bindInfoWindow();
			delete I;	
		},
		_markerClicked:function(evt){
			var I=this;
			I.window = gmap.map.getInfoWindow();				
			gmap.currentLocation=I.marker.locations[0];
		}
	};
	
	
	// ---- RETURN TO ENCAPSULATOR --------------------------
	return MarkerWindow;
})();