var GeoliveMapItem = new Class({
	options:{},
	type:"overlay",
	item:null,
	layer:null,
	active:false,
	activeState:{},
	initialize:function(item, layer){
		this.item=item;
		item.wrapper=this;
		this.layer=layer;	
//		if(item instanceof GMarker){
//			var t=item.show;
//			item.show=function(){
//				mm_debug('show');
//				var s=t.bind(item);
//				s();
//			}
//			
//		}
	},
	show:function(){
		if(this.item)
			//this.item.show();
			this.item.setMap(MapFactory.GetGMap(this));
	},	
	hide:function(){
		if(this.item)
			//this.item.hide();
			this.item.setMap(null);
	},
	getOverlay:function(){
		return this.item;
	},
	getName:function(){
		return MapFactory.GetItemName(this);
	},
	getTitle:function(){
		return this.getName();
	},
	getDescription:function(){
		return MapFactory.GetItemDescription(this);
	},
	//returns an icon that represents this item.
	getIcon:function(){
		return MapFactory.GetItemIcon(this);
	},
	isActive:function(){
		return this.active;
	},
	activate:function(){
		var me=this;
		me.active=true;
		me.activeState.icon=me.getIcon();
		me.activeState.iconFn=me.getIcon;
		me.activeState.index=me.item.getZIndex();
		me.getIcon=function(){return me.activeState.icon;};
		var iconRequest=new HighlightedIconRequest(me);
		iconRequest.addEvent('onSuccess',function(result){
			if(result.icon&&result.icon!=""){
				mm_debug('setting active icon.');

				MapFactory.EditItemIcon(me, result.icon, {width:32,height:32});
				me.item.setZIndex(999999);
				me.item.setAnimation(google.maps.Animation['BOUNCE']);
				
			}else{
				mm_debug('invalid active icon.');
				
			}			
		});
		iconRequest.execute();
		
	},
	deactivate:function(){
		this.active=false;
		this.getIcon=this.activeState.iconFn;
		MapFactory.EditItemIcon(this, this.activeState.icon);
		this.item.setZIndex(this.activeState.index);
		this.activeState={};
		this.item.setAnimation(null);
	}
		
	
});

GeoliveMapItem.implement(new Options(), new Events());


/*
 * CreateLink Static method. 
 * randomizes the GeoXml Url so that Google refreshes the layer. 
 * TODO: this should be moved to MapFactory. since it depends on Google Maps V2
 */
GeoliveMapItem.CreateLink=function(data){
	var a='?';
	if((data.url).indexOf('?') >= 0) // returns -1 if not character not found
		a='&';
	var overlay=new GGeoXml(data.url+a+"random=yes_"+Math.round(Math.random()*100)); 
	while(!overlay.hasLoaded){}
	var item=new GeoliveMapItem();
	item.name=data.name;
	item.description=data.description||"";
	item.item=overlay;
	overlay.geolivemapitem=item;
	item.type='networklink';
	return item;
};

var GeoliveMarker=GeoliveMapItem.extend({

	getLatLng:function(){
		return MapFactory.GetItemCoordinates(this.item)[0];
}

});

var GeoliveShape=GeoliveMapItem.extend({});

var GeolivePolygon=GeoliveShape.extend({


}
);

var GeoliveLine=GeoliveShape.extend({
	
});
