var noun_type_url = {
  _name: "url",

  suggest: function( text, html ) {
  
	var location = String(Application.activeWindow.activeTab.document.location);
    var suggestions  = [];
	suggestions.push( CmdUtils.makeSugg(location) );
	suggestions.push( CmdUtils.makeSugg( CmdUtils.getSelection() ) );
	
	return suggestions;
	
  }
}


CmdUtils.CreateCommand({
	name: "scouter",
	
	homepage: "http://www.memorycraft.jp/",
	author: { name: "memorycraft", email: "memorycraft(at)gmail(dot)com"},
	description: "Determine URL on WebScouter",
	icon : "http://faviapi.sidetools.com/?url=http%3A%2F%2Fja.webscouter.net%2F&c=366144d9",

	takes: {"url": noun_type_url},
  
	preview: function( pblock, targeturl ) {
		if (targeturl.length < 1) targeturl = String(Application.activeWindow.activeTab.document.location);
		var out = "Determine <strong>" + targeturl.text + "</strong> on <a href='http://ja.webscouter.net/' style='text-decoration: underline; color:#00B8FD'>Web Scouter</a>";
                pblock.innerHTML = out;

		jQuery.ajax({
                  url: "http://ja.webscouter.net/api.phtml",
                  type: "GET",
                  data: {ver :2, u :targeturl.text, p:1},
                  dataType: "xml",
                  timeout: 3000,
                  success: function(xml){
                       var scouterValue = xml.getElementsByTagName("scouterValue")[0].firstChild.nodeValue;
                       pblock.innerHTML = out + "<br><h1 style='font-family:Verdana,Helvetica,Osaka,Arial,sans-serif; font-size: 38px;font-weight: bold; color: #CCCC00;'>" + scouterValue + "</h1>";
                  }
                });



	},
	  
	execute: function( url ) {
		var baseurl = "http://ja.webscouter.net/info.phtml?u=" + url.text;
		Utils.openUrlInBrowser( baseurl);
	}
})



