CmdUtils.CreateCommand({
	names: [ "mixx", "share using mixx" ],
	homepage: "http://erikvold.com/tools/ubiquity/mixx/mixx.cfm",
	icon: "http://www.mixx.com/favicon.ico",
	author: { name:"Erik Vergobbi Vold", email: "erikvvold@gmail.com" },
	description: "Submit this page or a url string to Mixx.",
	help: "Submit this page or a url string to Mixx.",
	license: "GPL",
	version: "0.2",
	execute: function( args ){
		var selectedURL = CmdUtils.getWindow().location;

		jQuery.ajax( {
			type: "GET",
			dataType: "text",
			url: "http://api.mixx.com/services/v1r1/thingies/show?api_key=044MUnUaL8DfUqYeXOvKDQ&url="+encodeURIComponent(selectedURL),
			error: function() {
				displayMessage("There was an error connecting to Mixx.");
			},
			success: function( response ) {
				var responseJquery = jQuery( response );
				var numberOfPoints = responseJquery.find("vote_count").html();
				var linkURLString = "";

				if(numberOfPoints == '' || numberOfPoints == null){
					numberOfPoints = 0;
				}
				else{
					numberOfPoints = numberOfPoints.replace( ",", "" )*1;
				}

				if(numberOfPoints <= 0){
					linkURLString = "http://www.mixx.com/submit?page_url=" + encodeURIComponent(selectedURL);
				}
				else{
					linkURLString = responseJquery.find( "permalink" ).html();
				}

				Utils.openUrlInBrowser( linkURLString );
				return true;
			}
		});
	},
	preview: function( pblock, args ){
		var selectedURL = CmdUtils.getWindow().location;

		CmdUtils.previewAjax( pblock, {
			type: "GET",
			dataType: "text",
			url: "http://api.mixx.com/services/v1r1/thingies/show?api_key=044MUnUaL8DfUqYeXOvKDQ&url="+encodeURIComponent(selectedURL),
			error: function(){
				pblock.innerHTML = _( "Mixx this page." );
			},
			success: function( response ) {
				var numberOfPoints = jQuery( response ).find("vote_count").html();

				if(numberOfPoints == '' || numberOfPoints == null){
					numberOfPoints = 0;
				}

				pblock.innerHTML = _( "Mixx this page. This page has been Mixxed " + numberOfPoints + " times." );
				return true;
			}
		});
		return true;
	}
});