function adjustMenuDiv()
{
	var alto = screen.height;
	var ancho = screen.width;
	
	var div = document.getElementById('ajustable');
	var div_texto = document.getElementById('caja_texto');
	var div_menu = document.getElementById('caja_menu');
	
	if (div_texto!=undefined)
	{
		array_temp = document.location.href.split("/");
		if (div_menu!=undefined)
		{
			
			switch (array_temp[3])
			{
				case "sumando":
				case "multiplicando":
				case "invirtiendo":
					altura_temp = 10;
					break;
				default:
					altura_temp = div_menu.offsetHeight;;
					break;
			}
		} else {
			
			switch (array_temp[3])
			{
				case "empresas_suman":
					altura_temp = -36;
					break;
			}
		}
		div.style.height=((altura_temp+div_texto.offsetHeight)-315)+'px';
	}
}

/*
Elementos collapsables
------------------------------*/
var Collapsables = {
	init:function(){
		var list = $$("a.collapse_target");
		list.each(function(e){
			target = e.href.split("#")[1];
			e.fx = new Fx.Slide(target);
			e.fx.hide();
			e.addEvent('click', function(el){
							ev = new Event(el);
							this.fx.toggle();
							este = this;
							list.each(function(objeto)
							{
								if (objeto!=este)
								{
									objeto.fx.hide();
								}
							});
							e.fx.addEvent('onComplete',function(){adjustMenuDiv()});
							ev.stop();
						});
			//e.fx.hide();
		});
	}
}

var Acordeon2 = {
	init:function()
	{
		var trig = $$("a.collapse_target");
		var box = $$(".paneles");
		var imagen = $$(".imagen_r");
		la_imagen = "";
		imagen.each(function(e)
		{
			e.addEvent('click', function(el)
			{
				la_imagen = this;
				imagen.each(function(objeto)
				{
					ruta = objeto.src.split("/");
					fichero = objeto.src.split("/")[5];
					if (objeto==la_imagen)
					{
						partido = fichero.split(".");
						if (objeto.src.indexOf("_on")==-1)
						{
							fichero_final = partido[0]+"_on."+partido[1];
						} else {
							partido = fichero.split(".");
							guiones = partido[0].split("_");
							fichero_final = guiones[0]+"_"+guiones[1]+"."+partido[1];
						}
					} else {
						partido = fichero.split(".");
						guiones = partido[0].split("_");
						fichero_final = guiones[0]+"_"+guiones[1]+"."+partido[1];
					}
					file = ruta[0]+"/"+ruta[1]+"/"+ruta[2]+"/"+ruta[3]+"/"+ruta[4]+"/"+fichero_final;
					objeto.src = file;
				});
			});
		});
		var ac = new Accordion(trig, box, {
			onComplete: function()
			{
				adjustMenuDiv();
			},
			alwaysHide: true,
			display: 999
		});
	}
}

function veteA(objeto)
{
	var myFx = new Fx.Scroll(window).toElement(objeto);
}

var Acordeon = {
	init:function()
	{
		var trig = $$(".trigger");
		var box = $$(".slider");
		var ac = new Accordion(trig, box, {
			onComplete: function()
			{
				adjustMenuDiv();
			},
			alwaysHide: true,
			display: 999
		});
		$$(".trigger").addEvent('click', function()
		{
			elemento_clicado = this;
			window.setTimeout ("veteA(elemento_clicado);", 500);
		});
		$$(".tematica2").addEvent('mouseover', function()
		{
			var myFx = new Fx.Elements(this).set({
			    '0': {
			        'opacity': 0.7
			    }
			});
		});
		$$(".tematica2").addEvent('mouseout', function()
		{
			var myFx = new Fx.Elements(this).set({
			    '0': {
			        'opacity': 1
			    }
			});
		});
	}
}

/*
onload
-----------------------------------*/
window.addEvent('domready', Acordeon.init);
window.addEvent('domready', Acordeon2.init);
window.addEvent('load', adjustMenuDiv);

var tiempo1 = window.setTimeout ("adjustMenuDiv();", 1000);
clearInterval(tiempo1);
var tiempo2 = window.setTimeout ("adjustMenuDiv();", 1500);
clearInterval(tiempo2);
var tiempo3 = window.setTimeout ("adjustMenuDiv();", 2000);
clearInterval(tiempo3);
/*window.setTimeout ("adjustMenuDiv();", 2500);
window.setTimeout ("adjustMenuDiv();", 3000);
window.setTimeout ("adjustMenuDiv();", 3500);
window.setTimeout ("adjustMenuDiv();", 4000);*/



function validateFields()
{
	if (validarEmail(document.form_contacto.email.value))
	{
		if (document.form_contacto.nombre_empresa.value.length==0){
			alert("Campo Nombre empresa obligatorio.");
			document.form_contacto.nombre_empresa.focus();
			return 0;
		} else if (document.form_contacto.cif_empresa.value.length==0)
		{
			alert("Campo CIF obligatorio.");
			document.form_contacto.cif_empresa.focus();
			return 0;
		} else if (document.form_contacto.persona_contacto.value.length==0)
		{
			alert("Campo Persona contacto obligatorio.");
			document.form_contacto.persona_contacto.focus();
			return 0;
		} else if (!document.form_contacto.politica_checkbox.checked)
		{
			alert("Debe aceptar las condiciones de uso y política de privacidad.");
			document.form_contacto.politica_checkbox.focus();
			return 0;
		} else if (document.form_contacto.telefono_contacto.value.length==0)
		{
			alert("Campo Teléfono contacto obligatorio.");
			document.form_contacto.telefono_contacto.focus();
			return 0;
		} else if (document.form_contacto.email.value.length==0)
		{
			alert("Campo Email obligatorio.");
			document.form_contacto.email.focus();
			return 0;
		} else {
			document.form_contacto.submit();
		}
	}
}

function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return (true);
	} else {
		alert("La dirección de email es incorrecta.");
		document.form_contacto.email.focus();
		return (false);
	}
}

function changeOpacity(objeto, valor)
{
	var myFx = new Fx.Elements(objeto).set({
		'0': {
			'opacity': valor
		}
	});
}


