//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//////////////////////////////////////////////////////////////////

var qTipTag = "a"; //Which tag do you want to qTip-ize? Keep it lowercase!// ESTA VARIABLE NO HACE FALTA, SE LE PASA COMO PARÃMETRO EN EL INIT DEL TOOLTIP
var qTipX = -30; //This is qTip's X offset//
var qTipY = 25; //This is qTip's Y offset//

//There's No need to edit anything below this line//
var tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function (qTipTagN) {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle;
	var anchors = document.getElementsByTagName(qTipTagN);
	           
	for (var i = 0; i < anchors.length; i ++) {
		a = anchors[i];
		sTitle = a.getAttribute("title");
		if(sTitle) {
			a.setAttribute("tiptitle", sTitle);
			a.removeAttribute("title");
			a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
			a.onmouseout = function() {tooltip.hide()};
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

//funcion para el nuevaVentana
function reescribirEnlaces(){
	
	var className = "nuevaVentana";
	var features='toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no';
	
	if (!document.getElementsByTagName) return;
	var anchorsEnlac = document.getElementsByTagName('a');
	var r=new RegExp("(^| )"+className+"($| )");
	
	for (var i=0; i<anchorsEnlac.length; i++) {
		var enlace = anchorsEnlac[i];
		if (r.test(enlace.className)) {			
			//enlace.title = enlace.title + " (se abre en una nueva ventana)";
			enlace.title = enlace.title;
			enlace.onclick = function(){
				window.open(this.href, 'nuevaVentana', features);
				return false;
			}
		}
	}
}

//funcion para pie de foto extraido del alt
function crearPiesFotos (){
	var images = document.getElementsByTagName('img');
	for (var i = 0; i < images.length; i++) {			
	  var pieFoto = images[i].getAttribute('alt');
	  if ((pieFoto) && (pieFoto != '')) {
		var newp = document.createElement('p');
		//no le ponemos de momento ningun class al <p>    newp.className = 'caption';
		newp.appendChild(document.createTextNode(pieFoto));
		images[i].parentNode.appendChild(newp);
	  }
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  //alert(a[2]);
  document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function switchLayer(id) {
	var capa = document.getElementById(id);
	if(capa.style.display == 'none') {
		//capa.effect('height', {duration: 1500, transition: Fx.Transitions.linear}).start(0,400);
		capa.style.display = 'inline';
	}
	else {
		capa.style.display = 'none';
	}
}

function openWindow(el,width,height) {
	var newWnd = window.open(el.href, '_blank', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height+',top=300,left=400');
	newWnd.focus();
}
function focusSearchBox(e) {
	var e = new Event(e);
	if(this.value == 'Introduce texto')
		this.value = '';
	else
		this.select();
}
// Para hacer esto se requiere mootools!
window.addEvent('domready', function () {
        reescribirEnlaces();
        tooltip.init ("span");
        tooltip.init ("a");
        tooltip.init ("map");
	tooltip.init ("p");
	//$('buscador').addEvent('focus', focusSearchBox.bindWithEvent($('buscador')));
});

/*
window.onload = function () {
	reescribirEnlaces();
	tooltip.init ("span");
	tooltip.init ("a");
	tooltip.init ("map");
	
	//MM_preloadImages('/imgs/img.ContactosON.gif','/imgs/mapaMundi.americaOn.gif','/imgs/mapaMundi.africaOn.jpg','/imgs/mapaMundi.asiaOn.gif','/imgs/mapaMundi.oceaniaOn.jpg','/imgs/mapaMundi.europaOn.gif');
	//crearPiesFotos();	
}
*/

