//////////////////////////////////////////////////////
// DEFINIMOS LA FUNCION WINDOW LOAD
//////////////////////////////////////////////////////

// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html

addEvent = function ( obj, type, fn ) {
    if (obj.addEventListener)
        obj.addEventListener( type, fn, false );
    else if (obj.attachEvent) {
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
        obj.attachEvent( "on"+type, obj[type+fn] );
    }
}

//////////////////////////////////////////////////////
// FUNCION PARA ENLACES EXTERNOS TARGET=BLANK
//////////////////////////////////////////////////////

// 

function fix_external_links() { 
    if (!document.getElementsByTagName) return; 
    var anchors = document.getElementsByTagName("a"); 
    for (var i = 0; i < anchors.length; i++) { 
        var anchor = anchors[i]; 
		if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external"){
			anchor.target = "_blank"; 
		}
	}
}

//////////////////////////////////////////////////////
// FUNCION PARA VALUE INPUT Y TEXTAREA EFECTO :FOCUS
//////////////////////////////////////////////////////

// http://www.niquelao.net/javascript/2006/09/05/retocando-formularios-i/

var forms =  document.getElementsByTagName("form");
var inputs = document.getElementsByTagName("input");
var textareas =  document.getElementsByTagName("textarea");

var valorinicial = new Array();

function formulario() {
	for (var i = 0; i < inputs.length; i++) {
		if((inputs[i].type == "text") || (inputs[i].type == "password")) { 
			valorinicial[inputs[i].id]=inputs[i].value;
			inputs[i].onfocus = function() {vacia(this.id,this.value)}
			inputs[i].onblur = function() {restaura(this.id,this.value)}
		}
	}
	for (var i = 0; i < textareas.length; i++) { 
		valorinicial[textareas[i].id]=textareas[i].value;
		textareas[i].onfocus = function() {vacia(this.id,this.value)}
		textareas[i].onblur = function() {restaura(this.id,this.value)}
	}
}

function vacia(id,valor){
    var targetElement = document.getElementById(id);
	var tipo = targetElement.type;
	switch ( tipo ) { 
		case "text":
			if (valorinicial[id] == valor)
				targetElement.value = "";
			break
		case "password":
			if (valorinicial[id] == valor)
				targetElement.value = "";
			break
		case "textarea":
			if (valorinicial[id] == valor) {
				targetElement.innerHTML = "";
				targetElement.value = "";
			}
			break
	}
}

function restaura(id){
    var targetElement = document.getElementById(id);
	var tipo = targetElement.type;
	switch ( tipo ) { 
		case "text":
			if (targetElement.value.replace(/ /g, '') == '')
				targetElement.value = valorinicial[id];
				break
		case "password":
			if (targetElement.value.replace(/ /g, '') == '')
				targetElement.value = valorinicial[id];
				break
		case "textarea":
			revisa = targetElement.value.replace(/ /g, '');
			// Eliminamos saltos de línea y tabulaciones
			revisa = revisa.replace(/\n/g, '')
			revisa = revisa.replace(/\t/g, '')
			revisa = revisa.replace(/\r/g, '')
			if (revisa == '') {
				targetElement.innerHTML = valorinicial[id];
				targetElement.value = valorinicial[id];
			}
			break
	}
}

//////////////////////////////////////////////////////
// FUNCION MENU HORIZONTAL DROP-DOWNS
//////////////////////////////////////////////////////

// http://www.alistapart.com/articles/horizdropdowns/

function startList() {
	if (document.all&&document.getElementById) {
	navRoot = document.getElementById("idioma");
		for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
				this.className+=" over";
				}
				node.onmouseout=function() {
				this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

//////////////////////////////////////////////////////
// POPUP
//////////////////////////////////////////////////////

  var slide = null; 
  function startSlide() { 
  slide=window.open("../soporte.hostigal.com/livezilla.php","example",'width=600,height=550,resizable=0'); 
  slide.rootWin = self; 
  slide.focus(); 
  slide.location = "../soporte.hostigal.com/livezilla.php"; 
  return false; 
  }

//////////////////////////////////////////////////////
// CARGAMOS NUESTRAS FUNCIONES
//////////////////////////////////////////////////////

addEvent(window, 'load', formulario);
addEvent(window, 'load', fix_external_links);
addEvent(window, 'load', startList);

//////////////////////////////////////////////////////
// OPACIDAD FACEBOX
//////////////////////////////////////////////////////

$("body").append("<div id='opaque' style='display: none;'></div>");

$(document).bind('loading.facebox', function() {
    	$("#opaque").show();
});

$(document).bind('close.facebox', function() {
    	$("#opaque").hide();
});

$(document).bind('afterReveal.facebox', function() {
	// this is a fix for IE6 which resets the height to 100% of the window height
	$("#opaque").height($(document).height());
});

//////////////////////////////////////////////////////
// JQUERY
//////////////////////////////////////////////////////

$.fn.cycle.defaults.speed   = 900;
$.fn.cycle.defaults.timeout = 6000;

$(document).ready(function(){
	$("a[rel*=facebox]").facebox();
	$('#banner') 
	.before('<div id="nav">') 
	.cycle({fx:'fade',pager:'#nav'});
});

$(document).ready(function(){
	
	$("#content div.toogle").hide();

	$("#content h3.trigger").toggle(function(){
		$(this).addClass("active"); 
		}, function () {
		$(this).removeClass("active");
	});
	
	$("#content h3.trigger").click(function(){
		$(this).next("#content div.toogle").slideToggle("slow,");
	});

});