// cww user script
// version 0.2 BETA!
// 24-2-2008
// Copyright (c) 2005, Karol Smeczechowski
// Released under the NLA (no license agreement)
// http://www.foo.com
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Hello World", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          GM French monkey
// @namespace     http://karolsmeczechowski.net/gm
// @description   yap cww	
// @include       http://fr*yahoo.com/*
// @include       http://*.fr/*
// @include       http://fr.*/*
// @include       http://*.be/*
// @include       http://be.*/*

//@exclude       http://*.google.com/translate_t*


// ==/UserScript==


////

///


var oldv = "";
var newv = "";
d  = document.createElement("div");
d.setAttribute("id", "fr");
document.body.insertBefore(d, document.body.firstChild);

d.style.display = "block";
d.innerHTML =
			"<style  TYPE=\"text/css\">" +
			"div#fr {" +
			 "padding: 3px;" +
			 "border: 1px solid #666;" +
			 "border-right-width: 2px;" +
			 "border-bottom-width: 2px;" +
			 "display: none;" +
			 "background: #999;" +
			 "color: #FFF;" +
			 "font: bold 9px Verdana, Arial, Helvetica, sans-serif;" +
			 "text-align: left;" +
			 "position: absolute;" +
			 "z-index: 1000;" +
			"}" +
			"</style>" +
"<form action=\"/translate_t\" method=post id=\"text_form\" onsubmit=\"this.action = 'http://www.google.com/translate_t?langpair=fr|en'\">" +
	"<input type=hidden name=hl value=\"en\">" +
	"<input type=hidden name=ie value=\"UTF8\">" +
	"<table id=texttable>" +
		"<tr valign=top>" +
			"<td>" +
				"<div name=text id=source></div>" +
			"</td>" +
			"<td>" +
				"<div> ____ </div>" +
			"</td>" +
			"<td id=gap>&nbsp;</td>" +
			"<td class=almost_half_cell>" +
				"<div id=result_box dir=\"ltr\">It</div>" +
			"</td>" +
		"</tr>" +
		
	"</table>" +
"</form>";

window.ttt_times = function()
{
	txt = window.getSelection();
	document.getElementById('source').textContent = txt.toString();
	
	oldv = newv.toString();
	newv = txt.toString();

	if(oldv == newv)
	{
		window.setTimeout( ttt_times, 2000);
		return
	}
	d.style.top = window.scrollY + "px";
	d.style.left = window.scrollX + "px";
///////////////////	
	GM_xmlhttpRequest({
					method:"POST",
					url:"http://translate.google.com/translate_t",
					headers:{
							"User-Agent":"Mozilla/5.0",            // Recommend using navigator.userAgent when possible
							"Accept":"text/html",
							"Content-type":"application/x-www-form-urlencoded"
						},
					onload:function(response) {
											document.getElementById('result_box').textContent  = response.responseText.split(/result_box/)[2].split(/>/)[1].split(/</)[0];
											if(document.getElementById('sound') != null)
											{
												document.getElementById('sound').parentNode.removeChild(document.getElementById('sound'));
											}										
											el = document.createElement("A");
											el.setAttribute("id", "sound");
											uuu = "http://dictionnaire.mediadico.com/traduction/lecture.asp/definition/" + document.getElementById('source').textContent +"/parle";
											el.setAttribute("onClick", "window.open('" +uuu + "', 'xxx','height=300,width=500,scrollbars=0,resizable=0,toolbar=1'); return false");
											el.textContent = "click to hear the sound";
											document.getElementById('fr').appendChild(el);
										},
					data:'langpair=fr|en&hl=en&ie=UTF8&text=' + txt});				
					
/////////////////	
	
	window.setTimeout( ttt_times, 2000);
}

window.setTimeout( ttt_times, 2000);
				
				
				
				
	
				
				
				
				
				
				
				
				
				