// JavaScript Document
( function($) {
	$.fn.crearMasInfo = function(opciones){
		var defaults = {
			id				: 'masInfo' + $.fn.crearMasInfo.Aleatorio(1,1000),
			enlace 			: '#',
			target			: 'self',
			texto			: 'Más info.',
			posicion		: 'right',
			colorTexto		: '#666666',
			colorTextoSobre	: '#0561eb',
			imagen			: 'imagenes/flecha_azul.gif',
			punteroRaton	: 'pointer',
			ancho			: '66',
			alto			: '13',
			margen			: '-5'
		}
	//cargamos los parametros establecidos por el usuario
		var opts = $.extend(defaults, opciones);
		var ele = $(this);
		
		var anchoc = ele.width();
		var altoc = ele.height();
		var posi = ele.offset();
		
	/*	var tt = parseInt(altoc) - parseInt(opts.alto) - parseInt(opts.margen);
		var ll = parseInt(anchoc) - parseInt(opts.ancho) - parseInt(opts.margen);*/
		
		var tt = parseInt(altoc) + parseInt(posi.top)- parseInt(opts.alto) - parseInt(opts.margen);
		var ll = parseInt(opts.ancho) - parseInt(opts.margen);
		
	//aqui comineza realmente el plugin
		
		ele.append('<div id="' + opts.id + '" style="position:relative; float:' + opts.posicion + '"></div>');
		
		$('#'+opts.id).css({
			color 				: opts.colorTexto,
			cursor				: opts.punteroRaton,
			background			: 'url(' + opts.imagen + ')',
			backgroundPosition	: 'right',
			backgroundRepeat	: 'no-repeat',
			width				: opts.ancho + 'px',
			height				: opts.alto + 'px',
			marginTop			: opts.margen + 'px'
		});
		
		$('#'+opts.id).html(opts.texto);
		
		$('#'+opts.id).mouseover(function(e){
			$(this).css("color",opts.colorTextoSobre);
		});
		$('#'+opts.id).mouseout(function(e){
			$(this).css("color",opts.colorTexto);
		});
		$('#'+opts.id).click(function(e){
			switch(opts.target){
				case 'self':
					document.location.href = opts.enlace;
					break;
				case 'blank':
					window.open(opts.enlace);
				default:
					document.location.href = opts.enlace;
			}
		});
		
	}
	
	$.fn.crearMasInfo.Aleatorio = function(inferior,superior){ 
		numPosibilidades = superior - inferior;
		aleat = Math.random() * numPosibilidades; 
		aleat = Math.round(aleat); 
		return parseInt(inferior) + aleat; 
	} 

})(jQuery);
