(function($){
	jQuery.fn.presentationStreamLoader = function(options){
		var $sl = jQuery(this);
		
		var options = jQuery.extend({

		},options);
		
		var lastData = null;
		
		$sl.getLastData = function(){
			return lastData;
		};
		
		$sl.loadStream = function(kind,specifier,page){ // nearby:"World Trade Center, New York City, New York"
			ns11mmPresentation.trigger("streamLoaderBegin");
			var url = "";
			if(page != null){
				url = "/streams/"+urlencode(kind)+"/"+urlencode(specifier)+"/"+urlencode(page);
			} else {
				url = "/streams/"+urlencode(kind)+"/"+urlencode(specifier);
			}
			jQuery.ajax({
				url:url,
				method:"GET",
				dataType:"json",
				error:function(XMLHttpRequest, textStatus, errorThrown){
					var ui = {};
					ui.message = "There was an error loading this stream.";
					ui.textStatus = textStatus;
					if(errorThrown != undefined && errorThrown != null) ui.errorThrown = errorThrown;
					ui.kind = kind;
					ui.specifier = specifier;
					ns11mmPresentation.trigger("streamLoaderError",ui);
				},
				success:function(data, textStatus){
					var ui = {};
					ui.message = "Stream successfully loaded.";
					ui.kind = kind;
					ui.specifier = specifier;
					ui.data = data;
					ns11mmPresentation.trigger("streamLoaded",ui);
					lastData = data;
				}
			});
		};
		
		ns11mmPresentationLoader.trigger("loadStatusEvent",{pct:10,msg:"Stream Loader Initialized"});
		return $sl;
	}	
})(ns11mmPresentation);