/**
 * Digalego for web pages that allow 
 *
 * This file is part of jquery.digalego
 *
 * jquery.digalego is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * jquery.digalego is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with jquery.digalego. If not, see <http://www.gnu.org/licenses/>.
 *
 * @author      Sergio Carracedo Martinez <info@sergiocarracedo.es>
 * @copyright   2009 Sergio Carracedo Martinez
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL 3.0
 * @version     SVN: $Id: jquery.digalego.js 1 2010-01-19 14:00:00Z gasman406f $
 */

jQuery.fn.digalego = function(options) {
	var defaults = { 
				
	};
 	var options = $.extend(defaults, options);
 	

	
	return this.each(function(){   
		$(this).bind("dblclick",function(){
			diccionary();
		})
		
	});
	
	function diccionary() {
		if (navigator.appName != 'Microsoft Internet Explorer') {
			var t = document.getSelection();
			od(t);
		} else {
			var t = document.selection.createRange();
			if(document.selection.type == 'Text' && t.text>'') {
				document.selection.empty();
				od(t.text);
			}
		}
		
	}
	
	
	function od(t) {
		dominio=location.hostname;

		if (navigator.appName!='Microsoft Internet Explorer') {
			window.open('http://www.digalego.com/diccionario/Html/muestra_palabra.php?op=ver&dominio='+dominio+'&buscado='+encodeURIComponent(t), 'dict', 'width=700,height=500,resizable=1,menubar=0,scrollbars=1,status=1,titlebar=1,toolbar=0,location=0,personalbar=0');		
		} else {
			t=t.replace(/[!.:?,;"]/, '');
			while (t.substr(t.length-1,1)==' ') 
				t=t.substr(0,t.length-1);
			while (t.substr(0,1)==' ') 
				t=t.substr(1);
			if (t) {
				window.open('http://www.digalego.com/diccionario/Html/muestra_palabra.php?op=ver&dominio='+dominio+'&buscado='+encodeURIComponent(t), 'dict', 'width=700,height=500,resizable=1,menubar=0,scrollbars=1,status=1,titlebar=1,toolbar=0,location=0,personalbar=0');
			}
		}
	}

};
