/*
	-------  Popup Foto Avanzado 0.8, 2002-2005 jorge at pixarnet dot com -----------
	Modulo DOM de ventanas popup avanzado
	-------------------------------------------------------------------
	
	Requiere:
		base_1.1.js
	
	FUNCIONES PRINCIPALES
		PX_traphref.init()	-	Inicia el sistema de captura de eventos
		

	FUNCIONES AUXILIARES
		browserInfo, isset : base_1.1.js
		
	INTERFAZ HTML
		Nodos Afectados
			A, AREA - Pueden ser más si se añaden a PX_traphref.captureTags
		Parametros
			target		: plugin "_popup" por defecto, pueden definirse otros que sean llamados desde otro atributo target
			
		Atributos extra XMLNS:PX_traphref="http://pixarnet.com/NS/javascript/PX_traphref"
		
			PX_traphref:Toolbar		-> yes|no	Barra de herramientas
		 	PX_traphref:Dirs		-> yes|no	Directorios
			PX_traphref:Status		-> yes|no	Status
			PX_traphref:Menubar		-> yes|no	Menu bar
			PX_traphref:Scroll		-> yes|no	Barras de Scroll
			PX_traphref:Height		-> Integer	Altura
			PX_traphref:Width		-> Integer 	Anchura
			PX_traphref:Res			-> YES|NO	Reescalable
			PX_traphref:Name		-> String	Nombre de la ventana
			PX_traphref:Title		-> String	Título de cabecera

		
*/

// ----------------------------------------------- establece preferencias




var _br=browserInfo();


PX_traphref=isset("PX_traphref",new Object());
PX_traphref.plugins=isset("PX_traphref.plugins",new Object()) ;
PX_traphref.captureTags=["A","AREA"];

PX_traphref.capture=function (){
	
	var osrc=window.event.srcElement; 
	while (osrc.parentNode && !osrc.PX_traphref){osrc=osrc.parentNode;}

	for (var i in PX_traphref.plugins){ new PX_traphref.plugins[i](osrc);}
	
};

PX_traphref.release=function(rel){
	if (!rel){
		try{
			window.event.cancelBubble = true; window.event.returnValue = false;
			window.event.stopPropagation();	window.event.preventDefault();
		} catch (e){}
	}
};

PX_traphref.init=function(){
	var mainBody = document.getElementsByTagName("body")[0];
	for (var tag=0; tag<PX_traphref.captureTags.length;tag++){
		var parsedElm = mainBody.getElementsByTagName(PX_traphref.captureTags[tag]); 
		for (var i = 0; i < parsedElm.length; i++) {
			parsedElm[i].attachEvent("onclick", PX_traphref.capture);
			parsedElm[i].PX_traphref=true;
		}
	}
};



PX_traphref.plugins._popup=function(obj){

	var gAtr=function (atr,valor){	return (obj.getAttribute(atr)!=="" && obj.getAttribute(atr)!==null)? obj.getAttribute(atr) : (valor || false);	};
	
	var wopenPref=""; for (var i in this.preferences){ var val= gAtr("PX_traphref:"+i,this.preferences[i]); 	wopenPref+=(!wopenPref.length)? "":","; wopenPref+=(i+"="+val); }
	
	if (gAtr("target")=="_popup"){
		var wname=gAtr("name",this.preferences["Name"]);
		var w=window[wname]
		var isImg=(gAtr("href").search(/\.(jpg|png|gif)$/gi)!=-1);
		if (w){ w.close(); }
		if (isImg){
			w=window.open("about:blank",wname,wopenPref);
			w.document.write ("<html><head><title>"+gAtr("Title")+" (Imagen)</title></head><body marginheight='0' topmargin='0' leftmargin='0' marginwidth='0'><table><tr><td><img id='f' src='" +gAtr("href")+"'></td></tr></table></body></html>"); w.document.close();
			try{ if (!w.sizeToContent){ w.resizeTo(w.document.getElementById("f").width,w.document.getElementById("f").height+40)}	w.onload=function(){w.sizeToContent()}; 	} catch(e){}
		} else {
			w=window.open(gAtr("href"),wname,wopenPref);
		}
		PX_traphref.release(false);		
	}
	
};

PX_traphref.plugins._popup.prototype.preferences= { Toolbar:'no',Dirs:'no',Status:'no',Menubar:'no',Scroll:'no',Height:300,Width:300,Resizable:'yes',Name:'popupw',Title:''};



window.pxQUEadd(PX_traphref.init);


