// JavaScript Document

parar_play = false;
var resposta_play;

/**************************** MIDA DE LA FINESTRA DE L'USUARI **********************************/
function TamVentana() {
	var Tamanyo = [0, 0];
	if (typeof window.innerWidth != 'undefined'){
		Tamanyo = [window.innerWidth, window.innerHeight];
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
		Tamanyo = [document.documentElement.clientWidth,document.documentElement.clientHeight];
	}
	else
	{
		Tamanyo = [document.getElementsByTagName('body')[0].clientWidth,document.getElementsByTagName('body')[0].clientHeight];
	}
	return Tamanyo;
}

/******************************* URL ABSOLUTA DE LA IMATGE en funcio de la mida de la pantalla ***************************************************/

function ruta_img(ruta)
{	
	var mida = TamVentana();
	var ruta_abs = "/img_web/fons/";
	var url, quinaImg, i;
	if (mida[0] > 825 | mida[1] > 550) {
		if (mida[0] > 1440 | mida[1] > 683)
		{	
			// alt_gran: 1344x897
			url = ruta_abs+"alt_gran/"+ruta;
			if(mida[0]>1344){ // panoramica_gran: 1860x850
				url = ruta_abs+"alt_gran_panoramica/"+ruta;
			}
		}
		else
		{
			//alt_mitja: 1024x683
			url = ruta_abs+"alt_mitja/"+ruta;
			if(mida[0]>1024){ // panoramica_mitjana: 1440x683
				url = ruta_abs+"alt_mitja_panoramica/"+ruta;
			}
		}
	}
	else {// alt_petit: 825x538
		url = ruta_abs+"alt_petit/"+ruta;
		if(mida[0]>825){ // panoramica_petita: 1024x538 
			url = ruta_abs+"alt_petit_panoramica/"+ruta;
		}
	}
	return url;
}


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

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

/******************************** UNA SOLA IMATGE DE FONS ***************/
function img_fons(ruta, div, divfons)
{	
	var url = ruta_img(ruta);
	cont = document.getElementById(div);
	cont.style.background='url('+url+')';
	fadeIn(div,65);
}

/************************ IMATGES DE FONS - PLAY/PAUSE ************/
function img_play(ruta, quantes, div, foto, divfons)
{	
	url = ruta_img(ruta);
	var url_img = new Array(quantes);
	for(i=1;i<=quantes; i++)
	{
		url_img[i] = url+"fons"+i+".jpg";
	}
	cont = document.getElementById(div);
	document.getElementById(divfons).style.background = cont.style.background;
	cont.style.background='url('+url_img[foto]+')';
	fadeIn(div,65);
	//document.getElementById(div).style.background='url('+url_img[foto]+')';
	
	if(foto<quantes) foto++;
	else foto=1;
	resposta_play =	setTimeout("img_play('"+ruta+"',"+quantes+", '"+div+"', "+foto+", '"+divfons+"')",12000);
}

function parar(){
	parar_play = true;
}

function neteja(){
	clearTimeout(resposta_play);
}

/****************************** AUGMENTAR I REDUIR IMG i TEXT SUBMENU ***************************/

	var parar_picar=false;
	var parar_entrants=false;
	var parar_arrossos=false;
	var parar_mar=false;
	var parar_terra=false;
	
	var creixement_picar, creixement_entrants, creixement_arrossos, creixement_mar, creixement_terra;
	// x picar
	function creix_picar()
	{
		var cont = document.getElementById("x_picar");	
		if(cont.width<80 && !parar_picar){
			cont.width = parseInt(cont.width)+1;
			creixement_picar = window.setTimeout("creix_picar()");
		}
	}
	function decreix_picar()
	{
		clearTimeout(creixement_picar);
		para_picar=true;
		var cont = document.getElementById("x_picar");
		if(cont.width>48){
			cont.width = parseInt(cont.width)-1;
			window.setTimeout("decreix_picar()");
		}
		parar_picar=false;
	}
	
	// x entrants
	function creix_entrants()
	{
		var cont = document.getElementById("x_entrants");	
		if(cont.width<80 && !parar_entrants){
			cont.width = parseInt(cont.width)+2;
			creixement_entrants = window.setTimeout("creix_entrants()");
		}
	}
	function decreix_entrants()
	{
		clearTimeout(creixement_entrants);
		para_entrants=true;
		var cont = document.getElementById("x_entrants");
		if(cont.width>48){
			cont.width = parseInt(cont.width)-2;
			window.setTimeout("decreix_entrants()");
		}else{	parar_entrants=false; }
	}
	
	// x arrossos
	function creix_arrossos()
	{
		var cont = document.getElementById("x_arrossos");	
		if(cont.width<80 && !parar_arrossos){
			cont.width = parseInt(cont.width)+2;
			creixement_arrossos = window.setTimeout("creix_arrossos()");
		}
	}
	function decreix_arrossos()
	{
		clearTimeout(creixement_arrossos);
		para_arrossos=true;
		var cont = document.getElementById("x_arrossos");
		if(cont.width>48){
			cont.width = parseInt(cont.width)-2;
			window.setTimeout("decreix_arrossos()");
		}else{	parar_arrossos=false; }
	}
	
	// x mar
	function creix_mar()
	{
		var cont = document.getElementById("x_mar");	
		if(cont.width<80 && !parar_mar){
			cont.width = parseInt(cont.width)+2;
			creixement_mar = window.setTimeout("creix_mar()");
		}
	}
	function decreix_mar()
	{
		clearTimeout(creixement_mar);
		para_mar=true;
		var cont = document.getElementById("x_mar");
		if(cont.width>48){
			cont.width = parseInt(cont.width)-2;
			window.setTimeout("decreix_mar()");
		}else{	parar_mar=false; }
	}
	
	// x terra
	function creix_terra()
	{
		var cont = document.getElementById("x_terra");	
		if(cont.width<80 && !parar_terra){
			cont.width = parseInt(cont.width)+2;
			creixement_terra = window.setTimeout("creix_terra()");
		}
	}
	function decreix_terra()
	{
		clearTimeout(creixement_terra);
		para_terra=true;
		var cont = document.getElementById("x_terra");
		if(cont.width>48){
			cont.width = parseInt(cont.width)-2;
			window.setTimeout("decreix_terra()");
		}else{	parar_terra=false; }
	}


function destaca(id)
{
	document.getElementById(id).style.fontSize="14px";
}
function normal(id)
{
	document.getElementById(id).style.fontSize="11px";
}
function submenu_info(id,idt)
{
	document.getElementById(id).width=40;
	document.getElementById(idt).style.display="block";
}
function no_submenu_info(id,idt)
{
	document.getElementById(id).width=28;
	document.getElementById(idt).style.display="none";
}
/****************************** FI AUGMENTAR I REDUIR IMG SUBMENU ***************************/

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/****************** OBRIR IMATGE ENTORN *************/
function img_entorn(foto,texte) 
{
	var element_img = document.getElementById('imatge_entorn');
	element_img.src = foto; 
	document.getElementById('text_entorn').innerHTML = texte; 
}
