// JavaScript Document


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 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 MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}


function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function attachEventListener(target, eventType, functionRef, capture) {
    if (typeof target.addEventListener != "undefined") {
        target.addEventListener(eventType, functionRef, capture);
    } else if (typeof target.attachEvent != "undefined") {
        target.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = "*";
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function target_blank() {
	if (!document.getElementsByTagName) return;
	var i;
	var enlaces = document.getElementsByTagName("a");
	var cuantos = enlaces.length;
	for (i = 0; i < cuantos; i++) {
		if (enlaces[i].getAttribute("href") && enlaces[i].getAttribute("rel") == "external") enlaces[i].target = "_blank";
	}
}

function reset_form() {
	if (!document.getElementsByTagName) return;
	var i, cuantos;
	var los_inputs = document.getElementsByTagName("input");
	var los_textareas = document.getElementsByTagName("textarea");
	cuantos = los_inputs.length;
	for (i = 0; i < cuantos; i++) {
		if (los_inputs[i].getAttribute("type").toLowerCase() == "text" || los_inputs[i].getAttribute("type").toLowerCase() == "password") {
			los_inputs[i].onfocus = function() {
				if ((this.value.charCodeAt(0) == 32 || this.value.charCodeAt(0) == 160) && this.value.length == 1) this.value = "";
			};
		}
	}
	cuantos = los_textareas.length;
	for (i = 0; i < cuantos; i++) {
		los_textareas[i].onfocus = function() {
			if (this.value.charCodeAt(0) == 32 || this.value.charCodeAt(0) == 160 && this.value.length == 1) this.value = "";
		};
	}
}

function mmn() {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var elementos, cuantos, i;
	
	// Array con cada uno de los menús multinivel.
	var elementos = getElementsByClass("mmn",document,"ul");
	// Si hay menús multinivel, procesamos cada uno.
	if (elementos) {
		cuantos = elementos.length;
		for (i = 0; i < cuantos; i++) {
			mmn_procesar_menu(elementos[i]);
		}
	}
}

function mmn_procesar_menu(menu) {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var lis, submenu, enlaces, cuantos, i;

	// Inicializar el menú (abrir los submenús que procedan).
	lis = menu.getElementsByTagName("li");
	cuantos = lis.length;
	for (i = 0; i < cuantos; i++) {
		if (lis[i].className.indexOf("seleccionado") >= 0) {
			submenus = lis[i].getElementsByTagName("ul");
			if (submenus.length > 0) {
				submenus[0].style.display = "block";
			}
		}
	}

	// Aplicar comportamiento a todos los enlaces (abrir/cerrar submenú).
	enlaces = menu.getElementsByTagName("a");
	cuantos = enlaces.length;
	for (i = 0; i < cuantos; i++) {
		enlaces[i].onclick = function() {
			return mmn_procesar_enlace(this);
		}
	}
}

function mmn_procesar_enlace(enlace) {
	if (!document.getElementById) return;
	if (!document.getElementsByTagName) return;
	var padre_enlace, submenus, cuantos, i, sublis;
	
	padre_enlace = enlace.parentNode;
	submenus = padre_enlace.getElementsByTagName("ul");
	cuantos = submenus.length;
	if (padre_enlace.className.indexOf("seleccionado") >= 0) {
		if (cuantos == 0) {
			// Por no tener submenú y estar seleccionado no se hace nada.
		} else {
			if (padre_enlace.className == "") {
				padre_enlace.className = "";
			} else {
				padre_enlace.className = padre_enlace.className.replace("seleccionado","");
			}
			
		}
		for (i = 0; i < cuantos; i++) {
			submenus[i].style.display = "none";
		}
		sublis = padre_enlace.getElementsByTagName("li");
		cuantos = sublis.length;
		for (i = 0; i < cuantos; i++) {
			sublis[i].className = "";
		}
	} else {
		if (cuantos == 0) {
			// Por no tener submenú y estar seleccionado no se hace nada.
			return true;
		} else {
			if (padre_enlace.className == "") {
				padre_enlace.className = "seleccionado";
			} else {
				padre_enlace.className = "seleccionado " + padre_enlace.className;
			}
			submenus = padre_enlace.getElementsByTagName("ul");
			submenus[0].style.display = "block";
		}
	}
	enlace.blur();
	return false;
}


/* GALERIA DE IMAGENES  */
$(document).ready(function(){
			$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 40, /* padding for each side of the picture */
				opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: true, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
				callback: function(){}
			});
		});




/* BLOQUEO VÍDEO DEMO  */
$(document).ready(function(){
	$("a.boton_video, a.imagen_video").click(function() {
		$.blockUI({ message: $('#video_explicativo'), css: { padding: '0 0 0 0', margin: '-225px 0 0 -300px', width: '600px', height: '450px', top: '50%', left: '50%', textAlign: 'left', color: '#000', border: 'none', backgroundColor:'#000', cursor: 'default' }, overlayCSS: { backgroundColor:'#000', opacity: '0.70', cursor: 'pointer'}, baseZ: 10000, centerX: true, centerY: true, allowBodyStretch: true, constrainTabKey: true, fadeOut: 400, applyPlatformOpacityRules: true });
		$('.blockOverlay').click($.unblockUI);
		return false;
	});
});



attachEventListener(window, "load", target_blank, false);
attachEventListener(window, "load", reset_form, false);
attachEventListener(window, "load", mmn, false);
