function pageWidth() { return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} 
function pageHeight() { return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
function posLeft() { return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0; }
function posTop() { return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} 
function posRight() {return posLeft()+pageWidth();} 
function posBottom() {return posTop()+pageHeight();}
function e(obj) { return document.getElementById(obj); }
function dimensionar() {
	e('loader_img').style.marginTop=h2+'px';
	e('loader').style.height=h+'px';
	e('bgloader').style.height=h+'px';
	e('submenu1').style.marginTop=alto52+"px";
	e('submenu1').style.marginLeft="130px";
	e('submenu2').style.marginTop=alto52+"px";
	e('submenu2').style.marginLeft="130px";

	e('shower').style.marginTop=alto52+"px";	
	var w=parseInt(pageWidth());
	var porc_usado=((100*255)/w);
	var porc_shower=(100-parseInt(porc_usado));
	e('shower').style.width=porc_shower+"%";
	e('shower').style.marginLeft="255px";
}
function maximizar() {
	window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}	
}
window.onresize = maximizar;

function carga(i1,i2,i3,i4,i5) {
// i1, i2.. i5 = numeros de imagenes azar escogidas.

dimensionar();
jQuery.preload([ 'images/bg/mod'+i1+'.jpg', 'images/bg/mod'+i2+'.jpg', 'images/bg/mod'+i3+'.jpg', 'images/bg/mod'+i4+'.png', 'images/bg/mod'+i5+'.jpg' ], {
onFinish:init,
base:'',
ext:'',
threshold:2
});
}
function rotar() {
	var data=e('fondo').value;
	if (parseInt(data)==1 || e('retro').value==1) {
		e('retro').value=1;
		if (data==1) { data=2; }
		var capa="#bg_img"+data;
		jQuery(capa).animate({marginTop:"0px"},1400);
		e('fondo').value=parseInt(data)+1;
		if (parseInt(data)==5) { e('retro').value=0; }
	}
	else {
		var capa="#bg_img"+data;
		jQuery(capa).animate({marginTop:"2000px"},1400);
		e('fondo').value=parseInt(data)-1;
	}
}
function play_reel() {
  var s = new SWFObject('mediaplayer.swf','single','512','238','8');
  s.addParam('allowfullscreen','true');
  s.addVariable('file','reel2010.flv');
  s.addVariable('displaywidth','512');
  s.addVariable('autostart','true');
  s.addVariable('displayheight','218');
  s.addVariable('screencolor','0x000000');
  s.addVariable('overstretch','fit');
  s.write('video');	
  rotar();
}
function init() {
	e('loader_img').innerHTML='';
	jQuery("#menu_web").animate({marginTop:alto52+"px",height:"200px"},1000,function() { jQuery("#menu_web").animate({width:"240px"},1000); });
	e('loader').className='act60'; 
	jQuery("#loader").animate({marginTop:alto52+"px",height:"200px"},1000,function() { jQuery("#loader").animate({width:"240px"},800,function() { e('menu_web').style.display=''; jQuery("#bgloader").animate({height:"0px",width:"0px"},1400);  }); });
}
function navega(destino,ncapa,parametros,elemento) {
  
  if (e('video_reel').style.marginLeft!="100%") { stop_reel(); }
	if (destino=="reel") {
    e('video_reel').style.display=''; jQuery("#video_reel").animate({marginLeft:lv+"%"},800,function() { rotar(); setTimeout("play_reel();",1000); }); 
	}
	else {
		if (elemento) {	
			for (i=1;i<=6;i++) {
			  e('menu'+i).className='menugris';	
			}
			e(elemento).className='menublanco';
		
		e('submenu1').style.display='none';
		e('submenu2').style.display='none';
		}
		
		if (e('loader').style.width=="100%") { e('shower').innerHTML=''; jQuery("#loader").animate({width:"240px"},900,function() { navega2(destino,ncapa,parametros); });  }
		else { navega2(destino,ncapa,parametros); }
		 
  }
}
function navega2(destino,ncapa,parametros) {
	jQuery("#loader").animate({width:"100%"},1500,function() { rotar(); if (destino=="empresa") { e('submenu1').style.display=''; } if (destino=="servicios") { e('submenu2').style.display=''; }  ajaxload(destino,ncapa,parametros); });	
}
function stop_reel() {
	e('video').innerHTML='';
	jQuery("#video_reel").animate({marginLeft:"100%"},800);
}
function ajaxload(destino,ncapa,parametros) {
	aux=destino;
    destino = destino + '.php?randomize=' + Math.random()*10;	
    ajax = nuevoAjax();
    activado = function () {
		
		var capa = document.getElementById(ncapa);
		if (ajax.readyState == 1) {
			capa.innerHTML='<br /><br /><br /><center><span style="font-weight: bold; font-family: Verdana; font-size: 14px;">Cargando contenidos...</span></center>';
		}
		else if ((ajax.readyState == 4) && (ajax.status == 200)) {
			capa.innerHTML = ajax.responseText;
		}
    }
    ajax.onreadystatechange = activado;
    ajax.open("POST", destino,true);
    ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if (parametros) { ajax.send(parametros); }
	else { ajax.send(null); }  
}
function nuevoAjax(){
    var xmlhttp=false;
     try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
         try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");    }
        catch (E) { xmlhttp = false; }
      }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
    return xmlhttp;
}
function checkCTForm() {
	var d1=e('nombre').value;	
	var d2=e('email').value;
	var d5=e('consulta').value;

	if (d1=="" || d2=="") {
		alert('Nombre y Email son campos obligatorios');
	}
  	else if (d2.indexOf('@', 0) == -1 || d2.indexOf('.', 0) == -1) { 
  		alert("Email invalido"); 
	}
	else if (d5=="") {
		alert('Indiquenos su consulta');
	}
	else {
		ajaxload('contacto','shower','nombre='+d1+'&consulta='+d5+'&email='+d2);
	}
}

