/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = { 
	xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	//tipElements : ['a.tooltip','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
	tipElements : [],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;

		addEvent(this.tip,'mouseover',this.divOver);
		addEvent(this.tip,'mouseout',this.divOut);
		//temporal
		tipLen = 0;

		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
				//addEvent(current[j],'mouseover',this.tipOver);
				//addEvent(current[j],'mouseout',this.tipOut);
				//current[j].setAttribute('tip',current[j].title);
				//current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		//document.getElementById("debug").innerHTML = "tipOut";
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		apagaID = window.setTimeout("sweetTitles.tipApaga()",1000); // 200
		//sweetTitles.tipApaga();
	},
	divOver: function() {
		//document.getElementById("debug").innerHTML = "divOver " + sweetTitles.tip.firstChild.innerHTML;
		
		
		//Genero un array con la lista de los elementos que están contenidos dentro de tip
		var parrafos = sweetTitles.tip.getElementsByTagName("p");
		var anchors  = sweetTitles.tip.getElementsByTagName("a");
		
		for (var i=0;i<parrafos.length;i++) {
			addEvent(parrafos[i],'mouseover',sweetTitles.divOver);
			
		}
		
		for (var i=0;i<anchors.length;i++) {
			addEvent(anchors[i],'mouseover',sweetTitles.divOver);
			
		}
		
		
		if ( window.apagaID ) {
			clearTimeout(apagaID);
		}
	},
	tipApaga: function() {
			sweetTitles.tip.style.visibility = 'hidden';
	},
	divOut: function(e) {
		//document.getElementById("debug").innerHTML = "divOut";
		var targ;
		if (!e){
			var e = window.event;
		}
		if (e.target) {
			targ = e.target;
		}	else if (e.srcElement){
			targ = e.srcElement;
		}
		if (targ.nodeType == 3)  {
			targ = targ.parentNode;
		}
		
		if (targ.id == "toolTip") {
			apagaID = window.setTimeout("sweetTitles.tipApaga()",400);
			//sweetTitles.tipApaga();
		}
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		
		//document.getElementById("debug").innerHTML = "tipOver";
		if ( window.apagaID ) {
			clearTimeout(apagaID);
		}
		
		sweetTitles.obj = this;
		
		var targ;
		if (!e){
			var e = window.event;
		}
		if (e.target) {
			targ = e.target;
		}	else if (e.srcElement){
			targ = e.srcElement;
		}
		if (targ.nodeType == 3)  {
			targ = targ.parentNode;
		}
		
		sweetTitles.tip.innerHTML = targ.getAttribute('texto');
		tID = window.setTimeout("sweetTitles.tipShow()",5); // 500
		sweetTitles.updateXY(e);
	},
	tipShow : function() {	
	//document.getElementById("debug").innerHTML = "tipShow";
	//alert("tip show");
		var scrX = Number(sweetTitles.xCord);
		var scrY = Number(sweetTitles.yCord);
		//var tp = parseInt(scrY-30); // +15
		//var lt = parseInt(scrX+3); // + 10
		var anch = sweetTitles.checkNode();
		
		/******************************/
		debug(anch + ' ' + anch.nodeName);
		var pos = findPos(anch);
		var width = anch.offsetWidth;
		debug(pos + ' ' + width);
		var tp = pos[1] - 15; // +15
		var lt = pos[0] + (width/2); // + 10
		debug(anch.getAttribute('cuadrante'));
		if(anch.getAttribute('cuadrante') == '4'){
		width = sweetTitles.tip.offsetWidth;
		var lt = pos[0] - (width +12); // + 10			
		}
		/******************************/
		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;
		}
		//this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		//this.tip.innerHTML = "<p>hola.</p>";

		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(sweetTitles.tip.offsetWidth+lt) ) {
			/**/
			sweetTitles.tip.style.left = parseInt(lt-(this.tip.offsetWidth/3))+'px';
			/**/
} else {
			sweetTitles.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(sweetTitles.tip.offsetHeight+tp) ) {
			/**/
			sweetTitles.tip.style.top = parseInt(tp-(sweetTitles.tip.offsetHeight/2))+'px';
			/**/
		} else {
			sweetTitles.tip.style.top = tp+'px';
		}
		sweetTitles.tip.style.visibility = 'visible';
		sweetTitles.tip.style.opacity = '.1';
		sweetTitles.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+30); // 10
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",3); //20
		}
		else { 
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
	//registro.init();
	setTimeout(cargaFlashTop, 5);
	}
addEvent(window,'load',pageLoader);

function cargaFlashTop() {
	//alert("CFT");
	//document.getElementById("flashMenu").innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="435" height="180">';
		//alert("corrio ACTIVACION FLASH TOP");
		var so = new SWFObject("/buscador/imgs_www/top.swf?hola=" + Math.random(), "elflashMenu", "600", "150", "8", "#FF6600");
		so.addVariable("flashVarText", Math.random());
		so.addVariable("filtroLicPos", URLlicpos);
		so.addParam("wmode", "transparent");
		so.write("flashMenu");
		
		var so = new SWFObject("/buscador/imgs_www/registrate.swf", "elflashRegistrate", "600", "130", "8", "#FF6600");
		so.addVariable("flashVarText", "<?php echo rand();?>"); 
		so.addParam("wmode", "transparent");
		so.write("registrate");
		
}

function cargaFlashRegistro () {
		var so = new SWFObject("imgs_www/registrate.swf", "elflashRegistrate", "600", "130", "8", "#FF6600");
		so.addVariable("flashVarText", "?r=<?php echo rand();?>"); 
		so.addParam("wmode", "transparent");
		so.write("registrate");
}