CmdUtils.CreateCommand({
	names: [ 'dictionary', 'dictionary search' ],
	arguments: [ {role: 'object', nountype: noun_arb_text, label: 'word'} ],
	homepage: "http://www.erikvold.com/tools/ubiquity/dictionary/dictionary.cfm",
	icon:"http://dictionary.reference.com/favicon.ico",
	description:"Search Dictionary.com for a word.",
	help:"Type or highlight a word to lookup the definition on dictionary.com",
	author: { name: "Erik Vold", email: "erikvvold@gmail.com"},
	contributors: ["Erik Vold"],
	license: "MPL",
	version: "0.2",
	preview: function ( pblock, args ) {
		var word = jQuery.trim( args.object.text );
		var url = "http://dictionary.reference.com/browse/";

		// if the word is blank then display a default message
		if ( word.length == 0 ) {
			pblock.innerHTML = 'Provide a word to search <a title="Dictionary.com" href="http://dictionary.reference.com/">dictionary.com</a>, or hit enter now to go there.';

			return true;
		}

		// display the word which will be searched
		pblock.innerHTML = "Searching for " + word + ' on <a title="Dictionary.com" target="_blank" href="http://dictionary.reference.com/">dictionary.com...</a>';

		// search dictionary.com for the provided word
		CmdUtils.previewAjax( pblock, {
			type:"GET",
			dataType:"text",
			url: url+word,
			error:function(){
				pblock.innerHTML = "There was an error.";
			},
			success:function(response){
				var responseStr = jQuery.trim(response+"");
				var doc = context.focusedWindow.document;
				var domDiv = doc.createElement( "div" );
				domDiv.innerHTML = response;
				var content = jQuery( "div.lunatext", domDiv );

				if( content.length == 0 ){
					pblock.innerHTML = "No direct matches.<br> <b>Hit enter for suggested alternative searches...</b>";
					return true;
				}

				pblock.innerHTML = "";
				for( var i =0; i < content.length; i++ ) {
					pblock.innerHTML += content.eq(i).html() + ",";
				}

				pblock.innerHTML += "<p><b>Hit enter for more information...</b></p>";
			}
		});

		return true;
	},
	execute: function( args ) {
		var word = jQuery.trim( args.object.text );

		// if the string is blank then go directly to dictionary.com
		if ( word.length == 0 ) {
			Utils.openUrlInBrowser( "http://dictionary.reference.com/" );
			return true;
		}

		// if the string is not blank then assume it is a word, and go to the dictionary.com page for the word
		Utils.openUrlInBrowser( 'http://dictionary.reference.com/browse/' + word );
		return true;
	}
});
