/**
 * popIt - un plugin de jQuery para crear popups de Javascript
 * http://lab.soyunduro.com/popit || Version 1.0.0 - 03/03/2010
 *
 * Copyright (c) 2010 Hector Cabrera || www.soyunduro.com
 * Bajo la licencia GNU GPLv3 || http://www.opensource.org/licenses/gpl-3.0.html
 */

/**
 * MODO DE USO: $(ele).popIt()
 *
 * Ejemplos:
 *     $("a[rel='pop-up']").popIt();
 *     $("a#my_link_id").popIt( {center:1, toolbar:1} );
 */

(function($){
	$.fn.popIt = function (options){		
		// valores por defecto de popIt
		var defaults = {
			width: 600, // define el ancho en pixeles de la ventana.
			height: 600, // define el alto en pixeles de la ventana.            
            toolbar: 0, // define si se muestra la barra de herramientas (0 = no, 1 = si). 
            scrollbars: 1, // define si se muestran el scroll en la ventana (0 = no, 1 = si). 
            status: 0, // define si se muestra la barra de estado (0 = no, 1 = si). 
            resizable: 0, // define si se puede modificar el tamano de la ventana (0 = no, 1 = si). 
            left: 50, // posicion izquierda del popup con respecto a la pantalla. 
            top: 50, // posicion tope del popup con respecto a la pantalla. 
            center: 0, // define si el script debe centrar horizontalmente el popup (0 = no, 1 = si).
            location: 0 // define si se muestra la barra de direcciones (0 = no, 1 = si)
		}, settings = $.extend({}, defaults, options);
		
		return this.each(function(i){
			var $this = $(this);
			
			$this.click(function(){
				if ($this.attr("href") == "#" || $this.attr("href") == "") {return false;} // si no hay una URL definida, die.
				
				var features = (settings.center) ? "width="+settings.width+",height="+settings.height+",resizable="+settings.resizable+",scrollbars="+settings.scrollbars+",location="+settings.location+",left="+parseInt( ($(document).width()-settings.width)/2 , 10)+",top=100,toolbar="+settings.toolbar : "width="+settings.width+",height="+settings.height+",resizable="+settings.resizable+",scrollbars="+settings.scrollbars+",location="+settings.location+",left="+settings.left+",top="+settings.top+",toolbar="+settings.toolbar;
				
				window.open($this.attr("href"), null, features).focus(); // creamos el popup
				return false;
			});
		});
	};
})(jQuery);
