CmdUtils.CreateCommand({
    name: "view-blogmarks-user",
    homepage: "http://labs.artis-tic.com/ubiquity",
    author: { name: "Pascal Guimier", email: "talou at timot dot net"},
    license: "MPL",
    description: "Gets blogmarks from a user",
    help: "Insert user name. The bookmarks will show up in the preview, enter will get you directly to blogmarks.net",
    icon : "http://blogmarks.net/img/ico/favicon_public.png",
    takes: {"user": noun_arb_text},
    preview: function( pblock, user) {
        pblock.innerHTML = "Will get blogmarks list";
        var baseUrl = "http://blogmarks.net/api/user/" + user.text + "/marks?format=atom";
        var tpl =  "<li style=\"font-size:80%;clear:both;text-decoration:underline;\"><a href=\"${link}\">${title}</a>"
            + "</li>";
        CmdUtils.previewGet(pblock, baseUrl, null,
            function(data) {
                pblock.innerHTML = "";
                var title = jQuery('entry title', data).text();
                if (title) {
                    var entries = jQuery('entry', data);
                    var items = [];
                    for (var i = 0; i < entries.length; i++) {
                        var entry = entries[i];
                        var item = {};
                        item.link = jQuery('link', entry).attr('href');
                        item.title = jQuery('title', entry).text();
                        items.push(item);
                        pblock.innerHTML += CmdUtils.renderTemplate(tpl, {
                            link: item.link,
                            title: item.title
                        });
                    };
                }
            },
            "xml"
        );
    },

    execute: function( user) {
        var baseUrl = "http://blogmarks.net/user/" + user.text;
        Utils.openUrlInBrowser(baseUrl);
    }
});

CmdUtils.CreateCommand({
	name: "view-blogmarks-tag",
	homepage: "http://labs.artis-tic.com/ubiquity",
	author: { name: "Pascal Guimier", email: "talou at timot dot net"},
	license: "MPL",
	description: "Gets blogmarks with a tag",
	help: "Insert tag name. The bookmarks will show up in the preview, enter will get you directly to blogmarks.net",
	icon : "http://blogmarks.net/img/ico/favicon_public.png",
	takes: {"tag": noun_arb_text},
	preview: function( pblock, tag) {
		pblock.innerHTML = "Will get blogmarks list";
		var baseUrl = "http://blogmarks.net/api/marks/tag/" + tag.text + "?format=atom";
        var tpl =  "<li style=\"font-size:80%;clear:both;text-decoration:underline;\"><a href=\"${link}\">${title}</a>"
            + "</li>";
        CmdUtils.previewGet(pblock, baseUrl, null,
            function(data) {
                pblock.innerHTML = "";
                var title = jQuery('entry title', data).text();
                if (title) {
                    var entries = jQuery('entry', data);
                    var items = [];
                    for (var i = 0; i < entries.length; i++) {
                        var entry = entries[i];
                        var item = {};
                        item.link = jQuery('link', entry).attr('href');
                        item.title = jQuery('title', entry).text();
                        items.push(item);
                        pblock.innerHTML += CmdUtils.renderTemplate(tpl, {
                            link: item.link,
                            title: item.title
                        });
                    };
                }
            },
            "xml"
        );
	},

	execute: function( tag ) {
		var baseUrl = "http://blogmarks.net/marks/tag/" + tag.text;
		Utils.openUrlInBrowser(baseUrl);
	}
});


CmdUtils.makeBookmarkletCommand({
name: "add-bm",
    description: "Saves URL to blogmarks using the bookmarklet (pending a real command)",
    icon : "http://blogmarks.net/img/ico/favicon_my.png",
url: "javascript:q='';r='';if(document.selection)q=document.selection.createRange().text;else%20if(window.getSelection)q=window.getSelection();if%20(document.referrer)%20r=document.referrer;void(location.href%20='http://blogmarks.net/my/marks,new'%20+'?title='%20+%20encodeURIComponent(%20document.title%20)+'&url='%20+%20encodeURIComponent(%20location.href%20)+'&summary='%20+%20encodeURIComponent(%20q%20)+'&via='%20+%20encodeURIComponent(%20r%20));"
})
