
/*
Aplica efecto de despliegue a elementos invisibles al apretar links.
Los links deben seguir el siguiente esquema:
<a href="/#blind2" class="vermas">Ver M&aacute;s</a>

MOD: con title="id" no necesariamente es necesario un link, sino de <li>, <span> etc tb funciona, sin estar antecedido por /#
esto se cambia en la linea 26 de este mismo JS: target_from:'title',

- class="vermas" gatilla el efecto en cualquier link que tenga esa clase.
- href contiene la id del elemento a desplegar. La id debe estar antecedida por /# *ver MOD
- Agrega la class "open" a elemento abiertos y "cerrar" a los links cuyos elementos estan abiertos
- Al abrir un elemento cierra todos los demás que esten abiertos.
- duración de efecto se configura en Blinds.efectos
REQUIERE:
- prototype (http://prototype.conio.net/)
- scriptaculous y archivos asociados (http://script.aculo.us/)
@Ismael Celis para Taisa Chile S.A. Febrero 2006
MOD: Jorge Epuñan - nov 2006
-----------------------------------------------------------*/
Blinds = 
{
	efectos:{duration:0.7},
	links:null,
	abiertos:[],
	target_from:'title',
	default_open:6,
	init:function()
	{
		this.links = document.getElementsByClassName("vermas");
		if(this.links && this.links.length>0)
		{
			for(var i=0;i<this.links.length;i++){
				nodo = this.links[i];
				var href = nodo[Blinds.target_from];
				
				//nodo[Blinds.target_from] = "";
				nodo.old_content = nodo.innerHTML;
				nodo.target_id = href; 
				if($(nodo.target_id)){
					$(nodo.target_id).el_link = nodo;
					nodo.onclick = Blinds.clickAction;
					nodo.onmousedown = function(){return false;}
					if(Blinds.default_open != i){
						//alert(Blinds.default_open+" "+i);
						$(nodo.target_id).style.display="none";
						//Blinds.Cierra(nodo.target_id);
					}
					else{
						Element.addClassName(nodo,"cerrar");
						Blinds.abiertos.push(nodo.target_id);
						Blinds.open_fist = nodo.target_id;
					}
				}
				else alert(nodo.target_id+" no existe");
			}
		}
		//Blinds.Abre(Blinds.open_first);
		//alert(Blinds.open_fist);
	},
	clickAction:function(){
		//Element.toggle(this.target_id);
		this.old_content = this.innerHTML;
		if(this.rel)this.innerHTML = this.rel;
		this.rel = this.old_content;
		
		if($(this.target_id).className.indexOf("open")<0){
			//Element.addClassName(this,"cerrar");
			Blinds.Abre(this.target_id,this);
		}
		else{
			//Element.removeClassName(this,"cerrar");
			Blinds.Cierra(this.target_id,this);
		}
		this.blur();
		return true;
	},
	Abre:function(id){
		Element.addClassName(id,"open");
		Blinds.cierraAbiertos();
		Blinds.abiertos.push(id);
		Element.addClassName($(id).el_link,"cerrar");
		$(id).el_link.checked = true;
		//new Effect.Appear(id,Blinds.efectos);	
		//Element.toggle(id);
		new Effect.BlindDown(id,Blinds.efectos);
		new Effect.Appear(id,Blinds.efectos);
	},
	Cierra:function(id){
		Element.removeClassName(id,"open");
		Element.removeClassName($(id).el_link,"cerrar");
		Element.toggle(id);
		$(id).el_link.checked = false;
		//new Effect.Fade(id,Blinds.efectos);
		//new Effect.BlindUp(id,Blinds.efectos);
	},
	cierraAbiertos:function(){
		if(this.abiertos.length == 0)return false;
		for(var i=0;i<this.abiertos.length;i++){
			this.Cierra(this.abiertos[i]);	
		}
		this.abiertos = [];
	}
}
Event.observe(window,"load",Blinds.init);
function getEventSrc(e) {
	if (!e) e = window.event;

	if (e.originalTarget)
	return e.originalTarget;
	else if (e.srcElement)
	return e.srcElement;
}
var toolTipLib = { 
	xCord : 0,
	yCord : 0,
	obj : null,
	tipElements : ['a','abbr','acronym'],
	attachToolTipBehavior: function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		Event.observe(document,'mousemove',toolTipLib.updateXY,false);
		if ( document.captureEvents ) {
				document.captureEvents(Event.MOUSEMOVE);
		}
		for ( i=0;i<toolTipLib.tipElements.length;i++ ) {
			var current = document.getElementsByTagName(toolTipLib.tipElements[i]);
			for ( j=0;j<current.length;j++ ) {
				if(current[j].className.indexOf("help")>-1 && current[j].title){
					Event.observe(current[j],'mouseover',toolTipLib.tipOver,false);
					Event.observe(current[j],'mouseout',toolTipLib.tipOut,false);
					current[j].setAttribute('tip',current[j].title);
					
					current[j].removeAttribute('title');
				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			toolTipLib.xCord = e.pageX;
			toolTipLib.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			toolTipLib.xCord = window.event.clientX+document.documentElement.scrollLeft;
			toolTipLib.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function(e) {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		var l = getEventSrc(e);
		var div = document.getElementById('toolTip');
		if ( div ) {
			div.parentNode.removeChild(div);
		}
	},
	checkNode : function(obj) {
		var trueObj = obj;
		if ( trueObj.nodeName.toLowerCase() == 'a' || trueObj.nodeName.toLowerCase() == 'acronym' || trueObj.nodeName.toLowerCase() == 'abbr' ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		toolTipLib.obj = getEventSrc(e);
		tID = setTimeout("toolTipLib.tipShow()",500)
	},
	tipShow : function() {
		var newDiv = document.createElement('div');
		var scrX = Number(toolTipLib.xCord);
		var scrY = Number(toolTipLib.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = toolTipLib.checkNode(toolTipLib.obj);
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else {
			addy = anch.firstChild.nodeValue;
		}
		newDiv.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(newDiv);
		newDiv.style.opacity = '.1';
		newDiv.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(newDiv.offsetWidth+lt) ) {
			newDiv.style.left = parseInt(lt-(newDiv.offsetWidth+10))+'px';
		} else {
			newDiv.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(newDiv.offsetHeight+tp) ) {
			newDiv.style.top = parseInt(tp-(newDiv.offsetHeight+10))+'px';
		} else {
			newDiv.style.top = tp+'px';
		}
		toolTipLib.tipFade('toolTip',10);
	},
	tipFade: function(div,opac) {
		var obj = document.getElementById(div);
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			obj.style.opacity = '.'+newOpac;
			obj.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = setTimeout("toolTipLib.tipFade('toolTip','"+newOpac+"')",20);
		}
		else { 
			obj.style.opacity = '.80';
			obj.style.filter = "alpha(opacity:80)";
		}
	}
};
Event.observe(window,'load',toolTipLib.attachToolTipBehavior,false);
function popup(url){
	var props = arguments[1]?arguments[1]:"width=520,height=500";
	var op = window.open(url,"popup",props+",scrollbars=yes");
}

