//Content Modules. 
var MGModule=new Class({

	initialize:function(mediaMap, options){
		var me=this;
		me.mediaMap=mediaMap;
		me.setOptions($merge(
				{
				},
			options));
	},
	load:function(viewer,node,pageLoader){
		var me=this;
		me.viewer=viewer;	
		me.node=node;
		me.pageLoader=pageLoader; //the page loader that loaded this module.
		me.process();		
	},
	/**
	 * This method removes (and returns) its DOM Node from the document
	 * only pageloader modules will only ever be expected to provide this
	 * method. 
	 */
	getContent:function(){
		var me=this;
		if(me.node.parentNode){
		me.node.parentNode.removeChild(me.node);
		}else{
			mm_debug(["Module Expected Parent Node: GeoliveModule.js",me]);
			
		}
		//alert('rip');
		return me.node;
	},
	/**
	 * this method should be overriden by any implementors of MGModule. 
	 * this method is called by the pageloader (or whatever) and 
	 * modifies
	 */
	process:function(){
		var me=this;
		var div=new Element('div',{'class':me.options.className||"Geolive_Module_Content"});
		me.setText(div);
		div.injectInside(me.node);
		me.fireEvent('onLoad');
	},
	/**
	 * helper method for very simple modules that simply add a div to their node and 
	 * add (plain) text to it.
	 * if a module extends this method only, then regardless of whether or not any text is
	 * appended to 'el', it is still added to the node, so warning messages, optional 
	 * data, and elements that add css styling to the node (borders etc) should not simply implement
	 * this method becuase even if it is decided to be an empty element it will still be added to the Node.
	 * 
	 * instead implement the process method and optionally add the element depending on whatever conditions are neccessary,
	 * see warningModule/statsModule
	 */
	setText:function(el){
		var text="Hello World";
		el.setText(text);
	}
});
MGModule.implement(new Options(), new Events());
/**
 * MapItemModule is not useful on it's own
 * but many modules that grab data from a map item will
 * extend this;
 */
var MapItemModule=MGModule.extend({
	initialize:function(mediaMap,item,options)
	{
	var me=this;
	me.parent(mediaMap, options);
	me.item=window.MapFactory?MapFactory.AbstractItem(item):item; //in case MapFactory is not defined. then assume user knows what they are doing.
	}
});

var TextModule=MGModule.extend({
	initialize:function(mediaMap, text, options){
		var me=this;
		me.textString=text;
		me.parent(mediaMap,options||{});	
	},
	setText:function(el){
		var me=this;
		el.setText(me.textString);
	}
});

var DomModule=MGModule.extend({
	initialize:function(mediaMap, dom, options){
		var me=this;
		me.dom=dom;
		me.parent(mediaMap,options||{});	
	},
	process:function(){
		var me=this;
		var div=new Element('div',{'class':me.options.className||"content"});
		div.appendChild(me.dom);
		div.injectInside(me.node);
		me.fireEvent('onLoad');
	}
});
var HTMLModule=MGModule.extend({
	initialize:function(mediaMap, html, options){
		var me=this;
		me.html=html;
		me.parent(mediaMap,options||{});	
	},
	process:function(){
		var me=this;
		var div=new Element('div',{'class':me.options.className||"content"});
		div.innerHTML=me.html;
		div.injectInside(me.node);
		me.fireEvent('onLoad');
	}
});

