$(document).ready(function() {
    function NavigationElement() {
    
        this._riverDiv = null;
        this._riverClient = null;
        this._authPlugin = null;
        this._riverCache = [];
        
        this.absoluteUrl = function (url){
            if (url.substr(0, 7) == "http://")
			    return url;
		    else
			    return "http://" + window.location.hostname + url;
        };
        this.getAuthPlugin = function(){
	        if (typeof($.fn.enableCapture) === 'function') {
		        this._authPlugin = {
			        name: "FormAuth",
			        submitPermissions: "forceLogin",
			        nestedPlugins: [{name: "UCIDLogin"}]
		        };
	        }
	        else {
		        this._authPlugin = {
			        name: "FormAuth",
			        identityManagerLogin: {
				        width: 420,
				        height: 260,
				        url: "http://signup.universalmusic.com/openid/embed?flags=stay_in_window,no_immediate&token_url=" + encodeURIComponent(this.absoluteUrl("/_global/rpx.ashx") + "?bp_channel=" + Backplane.getChannelID()) + "&bp_channel="
			        },
			        submitPermissions: "forceLogin"
		        };
	        }
	        return this._authPlugin;
        };
        this.instantiateEchoStream = function (riverDiv, queryString){
                
            this._riverCache[queryString] = this._riverClient =  new Echo.Stream({
			    target: riverDiv,
			    appkey: "dev.umg",
			    query: queryString,
			    plugins: [{
				    name: "Whirlpools",
				    after: 2,
				    clickable: true
			    }, {
				    name: "Like"
			    }, {
				    name: "Reply",
				    actionString: "Reply...",
				    nestedPlugins: [this.getAuthPlugin()]
			    }, {
				    name: "Curation"
			    }, {
				    name: "Edit"
			    }, {
				    name: "Regex",
				    filters: [{
					    target: "object.title",
					    pattern: /^(<.*?>|\s)*@/,
					    className: "twitter-at-reply"
				    }]
			    }, {
				    name: "AvatarLink"
			    }],
			    maxBodyCharacters: 2000,
			    viaLabel: {icon: true, text: false},
			    reTag: false,
			    streamStateLabel: {icon: false, text: false},
			    aggressiveSanitization: false,
			    liveUpdates: false
		    });
    	
		    return this._riverClient;
        };
   }
    window.NavigationElement = NavigationElement;
});

