///////////////////////////////////////////////////////////////////////////////////////
// Scripts
///////////////////////////////////////////////////////////////////////////////////////
var NoIniciat = true;
var mcontador = 1;

function veurepr(capa, pid) {
  document.getElementById('projecte' + capa).style.display = 'inline';
  switch (capa) {
    case 1:
      {
        document.getElementById('projecte' + capa).style.color = '#ABA000';
        document.getElementById(pid).style.borderColor = '#ABA000';
        document.getElementById(pid).style.borderWidth = '2px';
        document.getElementById(pid).style.borderStyle = 'solid';
      }; break;
    case 2:
      {
        document.getElementById('projecte' + capa).style.color = '#F04E23';
        this.style.borderColor = '#F04E23';
        this.style.borderWidth = '2px';
        this.style.borderStyle = 'solid';
      }; break;
    case 3:
      {
        document.getElementById('projecte' + capa).style.color = '#006B9D';
        document.getElementById(pid).style.borderColor = '#006B9D';
        document.getElementById(pid).style.borderWidth = '2px';
        document.getElementById(pid).style.borderStyle = 'solid';
      }; break;
    case 4:
         {
           document.getElementById('projecte' + capa).style.color = '#1C813F';
           document.getElementById(pid).style.borderColor = '#1C813F';
           document.getElementById(pid).style.borderWidth = '2px';
           document.getElementById(pid).style.borderStyle = 'solid';
         }; break;
    case 5:
         {
           document.getElementById('projecte' + capa).style.color = '#E39F15';
           document.getElementById(pid).style.borderColor = '#E39F15';
           document.getElementById(pid).style.borderWidth = '2px';
           document.getElementById(pid).style.borderStyle = 'solid';
         }; break; 
    case 6:
      {
        document.getElementById('projecte' + capa).style.color = '#3A95B9';
        document.getElementById(pid).style.borderColor = '#3A95B9';
        document.getElementById(pid).style.borderWidth = '2px';
        document.getElementById(pid).style.borderStyle = 'solid';
      }; break; 
    case 7:
      {
        document.getElementById('projecte' + capa).style.color = '#B21E23';
        document.getElementById(pid).style.borderColor = '#B21E23';
        document.getElementById(pid).style.borderWidth = '2px';
        document.getElementById(pid).style.borderStyle = 'solid';
      }; break;
    case 8:
      {
        document.getElementById('projecte' + capa).style.color = '#79820E';
        document.getElementById(pid).style.borderColor = '#79820E';
        document.getElementById(pid).style.borderWidth = '2px';
        document.getElementById(pid).style.borderStyle = 'solid';
      }; break; 

  }
}
function ocultarpr(capa, pid) {
  document.getElementById('projecte' + capa).style.display = 'none';
  document.getElementById(pid).style.borderColor = 'transparent';
  document.getElementById(pid).style.borderWidth = '2px';
  document.getElementById(pid).style.borderStyle = 'solid';
}
function veure(capa) {
  document.getElementById('projecte' + capa).style.display = 'inline';

}
function ocultar(capa){
	document.getElementById('projecte'+capa).style.display='none';
}
function canviidioma() {
  document.getElementById('idiomaes').style.color = '#BBBDAE';
  document.getElementById('idiomaes').backgroundPosition = "top center";
}
function tornaidioma() {
  document.getElementById('idiomaes').style.color = '#063C52';
  document.getElementById('idiomaes').backgroundPosition = "bottom center";

}
function CanviImatge(p1, p2, p3) {

  NoIniciat = false;

  if (p1 == '-') {mcontador--; }
  else { mcontador++; }
  if (mcontador < 1) {mcontador = 1}
  if (mcontador > p3) {mcontador = p3}
  spr = mcontador;
  document.getElementById('imatgeprojecte').src = "img/ProyectosImagenes/Y" + p2 + "_A" + spr + ".jpg";

  if (spr != 2 ) { document.getElementById('comentariprojecte').style.display= 'none' ; }
  else { document.getElementById('comentariprojecte').style.display = "block"; }
}
function OcultaImatge(p1) {
  document.getElementById('imatgeprojecte').src='img/blanc95.png'; 
  if (mcontador < 2 ) {
    document.getElementById('diviconos').style.display='none';
	  document.getElementById('comentariprojecte').style.display='none';
	}
}

function MarcaImatge(p1, p2) {
  var bool;
  var anterior;
  var seguent;
  var ni;
  if (NoIniciat) {
    mcontador = p1;
    ni = p1;
  }
  else {
    ni = mcontador;
  }
  seguent = (ni + 1);
  bool = false;
  bool = CheckImage("img/ProyectosImagenes/Y" + p2 + "_A" + seguent + ".jpg");
  if (bool) { document.getElementById('fltxd').style.display = 'none'; }
  else { document.getElementById('fltxd').style.display = 'inline'; }
  anterior = (ni - 1);
  bool = false;
  bool = CheckImage("img/ProyectosImagenes/Y" + p2 + "_A" + anterior + ".jpg");
  if (bool) { document.getElementById('fltxe').style.display = 'none'; }
  else { document.getElementById('fltxe').style.display = 'inline'; }
  
}

function CheckImage(URL) {
  var mErrorImg = false;
  var i = new Image();
  i.src = URL;
  // Error - només funciona si l'imatge es a la cache del navegador
  //if (i.width == 0) {mErrorImg=true}
  return mErrorImg;
}

/*rollover boto home:*/
if (typeof($)=='function') {
	$(document).ready(function() {
		$('input.boto_entrar')
			.hover(function() { 
				$(this).css("background-position", "0px -21px");
			})
			.mouseout(function() {
				$(this).css("background-position", "0px -1px");
			});
		$('input.boto_entrar_en')
			.hover(function() { 
				$(this).css("background-position", "0px -21px");
			})
			.mouseout(function() {
				$(this).css("background-position", "0px -1px");
			});
		$('div.form_cerca .boto')
			.hover(function() { 
				$(this).css("background-position", "0px -21px");
			})
			.mouseout(function() {
				$(this).css("background-position", "0px -1px");
			});
		$('div.form_cerca .boto_en')
			.hover(function() { 
				$(this).css("background-position", "0px -21px");
			})
			.mouseout(function() {
				$(this).css("background-position", "0px -1px");
			});
	});
}

// Moure scroll

function mouScroll (quinaCapa, linies) {
if (quinaCapa!='' && linies!='') {
	if(document.getElementById(quinaCapa + '_vscrollerbase') && document.getElementById(quinaCapa + '_contentwrapper')) {
		var minCursor=4;
		var maxCursor=parseFloat(document.getElementById(quinaCapa + '_vscrollerbase').style.height)-4;
		var altCont=parseFloat(document.getElementById(quinaCapa + '_contentwrapper').offsetHeight);
		var altFinestra=parseFloat(document.getElementById(quinaCapa + '_mcontentwrapper').offsetHeight);
		var desplaPix=Math.floor(linies * 18.25 - maxCursor/2);
		maxCursor=maxCursor-parseFloat(document.getElementById(quinaCapa + '_vscrollerbar').offsetHeight);
		if (desplaPix>0) {
			if (altCont-desplaPix<altFinestra) {
				desplaPix=altCont-altFinestra;
			}
			//alert('minCursor: ' + minCursor + ', ' + 'maxCursor: ' + maxCursor + ', ' + 'desplaPix: ' + desplaPix + ', ' + 'altCont-altFinestra: ' + (altCont-altFinestra));
			document.getElementById(quinaCapa + '_contentwrapper').style.top='-' + desplaPix + 'px';
			document.getElementById(quinaCapa + '_vscrollerbar').style.top=Math.floor( minCursor + (maxCursor-minCursor) * (desplaPix / (altCont-altFinestra) ) ) + 'px';
		}
	} else {
		setTimeout("mouScroll('"+quinaCapa+"',"+linies+")",100);
	}
}
}