/**
 * @author Cylarcom
 */
  
var ieVer=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; case 5.8:return 8; }}()||@*/0;
if(/MSIE 6.0/i.test(navigator.userAgent)) {ieVer=6;}

//alert(ieVer);

/*Efectos Fade In*/
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

/*Rotador imagenes home*/

var contadorImagenes = 1;
var imagenesArr = new Array();

function cambiarImagenes(imagenes){
	elemento = document.getElementById('imagenPrincipal');
	imagenesArr = imagenes.split("<br>");
	
	//Llamo a la función FadeIN 
	fadeIn('imagenPrincipal',0);
	elemento.src = imagenesArr[0]
	setInterval('loopImagenes();',2500); 
}

function loopImagenes(){
	if(contadorImagenes <= imagenesArr.length && imagenesArr[contadorImagenes] != null && imagenesArr[contadorImagenes] != ''){
		
		document.getElementById('imagenPrincipal').src = imagenesArr[contadorImagenes];
		//Llamo a la función FadeIN 
		fadeIn('imagenPrincipal',0);
		contadorImagenes++;
	}else{
		contadorImagenes = 0;
	}
}


/*Rotador de frases*/
var contadorFrases = 0;
var frasesArr = new Array();

function cambiarFrases(frases){
	elemento = document.getElementById('frases');
	frasesArr = frases.split("<br>");
	
	elemento.innerHTML = frasesArr[0]
	setInterval('loopFrases();',3500); 
}

function loopFrases(){

	if(contadorFrases <= frasesArr.length && frasesArr[contadorFrases] != null){
		elemento.innerHTML = frasesArr[contadorFrases];
		contadorFrases++;
	}else{
		contadorFrases = 0;
	}
}


/* Imagenes de fondo -proyectos- */
//Cargo las imagenes con AJAX  
/* Funciones de AJAX */
var xmlhttp;


 /*Precarga de todas las imagenes*/
/*
 function preCargaImagenes(cantItems)
{

	 for (i=1; i <= cantItems ; i++){ 

		var url = document.getElementById('imagenFondo' + i ).innerHTML;
		xmlhttp=null;
		if (window.XMLHttpRequest)
			{// code for IE7, Firefox, Opera, etc.
			xmlhttp=new XMLHttpRequest();
			}
		else if (window.ActiveXObject)
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		if (xmlhttp!=null)
			{
			//xmlhttp.onreadystatechange=function () { state_Change(id,url); };
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
			}
		else
			{
			alert("Your browser does not support XMLHTTP.");
			}
    } 
	
}*/
 
 /*FIN Precarga de todas las imagenes*/
 
 

/*
function cargaImagen(id,url)
{
	//document.getElementById(id).innerHTML = '<div align="center"><img src="cmsdata/site_img/cargando.gif"></div>'; 

	xmlhttp=null;
	if (window.XMLHttpRequest)
	  {// code for IE7, Firefox, Opera, etc.
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	if (xmlhttp!=null)
	  {
	  xmlhttp.onreadystatechange=function () { state_Change(id,url); };
	  xmlhttp.open("GET",url,true);
	  xmlhttp.send(null);
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP.");
	  }
}*/
/*
function state_Change(id,url)
{
		if (xmlhttp.readyState==4)
		{// 4 = "loaded"
		if (xmlhttp.status==200)
			{// 200 = "OK"
			//document.getElementById(id).innerHTML=xmlhttp.status;
			if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
				divCargando = '';
			}else{
				divCargando = '<div id="cargando" style="width: 100px; margin-left: 400px;  position: absolute; top: 280px;"><img src="cmsdata/site_img/cargando.gif"></div>';
			}
			document.getElementById(id).innerHTML=divCargando+'<img id="'+url+'" src="'+url+'" onload="changeImg(this.id);" style="display:block;">';
			}
		}
}*/

/*FIN Funciones de AJAX*/
/*
function changeImg(imgId){
	document.getElementById('cargando').style.display='none';
  document.getElementById(imgId).style.display='block';
}
  */
  
  
/* FIN Imagenes de fondo -proyectos- */


 
 
function onoff(imgsrc) {
	imgsrc = replace(imgsrc,'_off','_oxx');
	imgsrc = replace(imgsrc,'_on','_off');
	imgsrc = replace(imgsrc,'_oxx','_on');
	return imgsrc;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function ocultarResumen(){ 
	if(ieVer==7){
		if(document.getElementById('fotosProyectosContenedor')){
			if(document.getElementById('proyectosMenu').style.display == 'none'){
				document.getElementById('fotosProyectosContenedor').style.marginTop= '-19px';
			}
		}
	}
	document.getElementById('proyectosInfo').style.display='none';
	return false;
} 
function ocultarProyecto(){ 
	if(ieVer==7){
		if(document.getElementById('fotosProyectosContenedor')){
			if(document.getElementById('proyectosInfo').style.display == 'none'){
				document.getElementById('fotosProyectosContenedor').style.marginTop= '-19px';
			}
		}
	}
	//document.getElementById('proyectosMenu').style.display='none'; 
}
function ocultarProyectosClientes(){ 
elements = document.getElementsByTagName('*');    
    for( i=0; i < elements.length; i++ ){
				if(ieVer == 8 || ieVer == 0 || ieVer == -1){
					curClass = elements[i].getAttribute('class');
				}else{
					curClass = elements[i].getAttribute('className');
				}
        if (curClass && curClass.indexOf('clientesMenu_')>-1) {
           elements[i].style.display = 'none';
        }
    }
    return true;
}

/*
function showDiv(id){
	if(document.getElementById(id)){
		if(document.getElementById(id).style.display == 'none'){
			document.getElementById(id).style.display='block';
		}else{
			document.getElementById(id).style.display='none';
		}
	}else{
		return false;
	}
}
*/

function showDiv(id){
	if(document.getElementById(id)){
		if(document.getElementById(id).style.display == 'none'){
		  if(ieVer==7){
				if(document.getElementById('fotosProyectosContenedor')){
					if(document.getElementById('fotosProyectosContenedor').style.marginTop != '0px'){
						document.getElementById('fotosProyectosContenedor').style.marginTop= '0px';
					}
				}
			}
			document.getElementById(id).style.display='block';
		}
	}else{
		return false;
	}
}


function cerrarPaneles(prefijo){
    elements = document.getElementsByTagName('*');    
    for( i=0; i < elements.length; i++ ){
				if(ieVer == 8 || ieVer == 0 || ieVer == -1){
        curClass = elements[i].getAttribute('class');
				}else{
				curClass = elements[i].getAttribute('className');
				}
        //alert(elements[i].id);
        if (curClass && curClass.indexOf(prefijo)>-1) {
           //alert(elements[i].id);
           elements[i].style.visibility = 'hidden';
           elements[i].style.display = 'none';
        }
    }
    return true;
}


function overMenu() {
	menu_open_seconds = 30;
}

function overResumen() {
	resumen_open_seconds = 30;
}

function overFromCliente() {
	clientes_open_seconds = 30;
}

function outFromMenu() {
	menu_open_seconds = 0;
}


function outFromResumen() {
	resumen_open_seconds = 0;
}

function outFromCliente() {
	clientes_open_seconds = 0;
}

function closeResumen() {
	resumen_open_seconds--;
	if (resumen_open_seconds<0) {
		ocultarResumen();
		resumen_open_seconds = 5;
	}
}

function closeProyecto() {
	menu_open_seconds--;
	if (menu_open_seconds<0) {
		ocultarProyecto();
		menu_open_seconds = 5;
	}
}

function closeProyectosClientes() {
	clientes_open_seconds--;
	if (clientes_open_seconds<0) {
		ocultarProyectosClientes();
		clientes_open_seconds = 5;
	}
}


var menu_open_seconds = 0;
var resumen_open_seconds = 0;
var clientes_open_seconds = 0;
setInterval('closeResumen();',1500); 
setInterval('closeProyecto();',1500); 
setInterval('closeProyectosClientes();',1500); 
