// JavaScript Document
var subact = 0;
var menuNames = ["EL BLOG","QUI SOM?","VÍDEOS","QUAN S'EMET?","CONTACTA","EL MAPA"];
var menuUrls = ["http://blogs.tv3.cat/km33","http://www.tv3.cat/km33/quisom.htm","http://www.tv3.cat/ptv3/tv3TotsVideos.jsp?idint=208120573","http://www.tv3.cat/programa/208120573/tvcat","http://www.tv3.cat/km33/contacta.htm","http://blogs.cat.cat/km33"];



/* menu principal */
function menu(selected,entorn){
var i = 0;
if(entorn){
	var prePath = "";
}else{
	var prePath = ""; ///km33/
	}
	document.write('<ul>');
	for(i=0;i<menuNames.length;i++){		
		if(i == selected && i!= 4){
			document.write('<li class="selected">'+menuNames[i]+'</li>');
		}else if(i == selected && i == 4){
			document.write('<li class="selected leftspacer">'+menuNames[i]+'</li>');
		}else{
			if(i<=3){
				if(i == 1 || i == 2){
					document.write('<li><a href="'+menuUrls[i]+'" target="_blank">'+menuNames[i]+'</a></li>');
				}else if(i == 0 || i == 4){
					document.write('<li><a href="'+menuUrls[i]+'" >'+menuNames[i]+'</a></li>');
				}else{
					document.write('<li><a href="'+prePath+menuUrls[i]+'">'+menuNames[i]+'</a></li>');
				}
			}else if(i==4){
				document.write('<li class="orange leftspacer"><a href="'+prePath+menuUrls[i]+'">'+menuNames[i]+'</a></li>');
			}else{
				
				if(i==6){
					document.write('<li class="orange"><a href="'+menuUrls[i]+'">'+menuNames[i]+'</a></li>');
				}else{
					document.write('<li class="orange"><a href="'+prePath+menuUrls[i]+'">'+menuNames[i]+'</a></li>');
				}
					
			}			
		}
	}
	document.write('</ul>');
}

/* footer */

function footer(entorn){
if(entorn){
	var prePath = "http://www.tv3.cat/km33/";
}else{
	var prePath = ""; ///km33/
	}
document.write('<div class="fonsNegre"><div class="logotips"><a href="http://www.tv3.cat" target="_blank"><img src="http://www.tv3.cat/km33/img/logo_tvc.gif" alt="Televisi&oacute; de Catalunya" border="0" /></a>'+
'		<div class="text"><b>Televisi&oacute; de Catalunya, S.A.</b><div class="spacer"></div>'+
'			<ul>'+
'				<li><a href="'+prePath+'mapaweb.htm">Mapa web</a>&nbsp; |</li>'+
'				<li><a href="http://www.tv3.cat/avis/" target="_blank">Avis legal</a>&nbsp; |</li>'+
'				<li><a href="http://www.tv3.cat/iqua/" target="_blank">Segell de qualitat</a>&nbsp; |</li>'+
'				<li class="norightpadding"><a href="http://www.tv3.cat/5430">Atenció a l&prime; Audičncia</a></li>'+
'			</ul>'+
'		</div></div><script language="JavaScript" type="text/javascript" src="http://www.tv3.cat/js/tvc/ojd.js"></script>');
}



/*
PHOTO GALLERY
showPhoto(); // show current picture
startGallery(): // startup main gallery constructor
updateThumbs(); // manage thumbs collection navigation
updateGallery(); // manage global gallery navigation

showPhotoEspectador(); // show current picture and update photo desc (espectador)
updateGalleryEspectador(); // manage global gallery navigation (espectador)
*/

var galleryLenght;
var maxPhotoDisplay = 5;
var galleryStartIndex = 0;
var galleryStartEnd = galleryStartIndex+maxPhotoDisplay;
var currentFoto = galleryStartIndex+1;

function showPhoto(int)
{
	document.getElementById("fotoGaleria").src = photoCollection.foto[int];
	document.getElementById("galleryIndex").innerHTML = (int+1)+" de "+photoCollection.foto.length;
	currentFoto = int+1;;
	document.getElementById("fotoTitol").innerHTML = photoCollection.alt[int];
	document.getElementById("fotoAutor").innerHTML = photoCollection.aut[int];
	document.getElementById("fotoDia").innerHTML = photoCollection.day[int];
}

function startGallery(int,dataObj)
{
	dataObj=dataObj;
	galleryLenght = dataObj.foto.length;
	var thumbsToShow = Math.min(maxPhotoDisplay,galleryLenght);
	var galleryCode = '<div class="thumbsbutton"><img src="img/prev_big.gif" alt="Anterior" border="0" /></div>';
	galleryCode += '<div class="images" id="galleryThumbsList">';	
	galleryCode += '<ul>';	
	for(var i=0;i<thumbsToShow;i++){		
		galleryCode += '<li id="f'+i+'"><a href="javascript:showPhoto('+i+');"><img src="'+dataObj.foto[i]+'" alt="'+dataObj.alt[i]+' (foto: '+dataObj.aut[i]+')" border="0" /></a></li>'            
		}		
		galleryCode += '</ul>';		
		if(thumbsToShow < galleryLenght){
			galleryCode += '</div><div class="thumbsbutton"><a href="javascript:updateThumbs(\'next\');"><img src="img/next_big.gif" alt="Anterior" border="0" onmouseover="this.src=\'img/next_big_on.gif\'"  onmouseout="this.src=\'img/next_big.gif\'" /></a></div>';
		}else{
			galleryCode += '</div><div class="thumbsbutton"><img src="img/next_big.gif" alt="Anterior" border="0" />/div>';
			}		
		document.getElementById("galleryThumbs").innerHTML = galleryCode;
		document.getElementById("galleryIndex").innerHTML = (int+1)+" de "+galleryLenght;
		document.getElementById("fotoTitol").innerHTML = dataObj.alt[0];
		document.getElementById("fotoAutor").innerHTML = dataObj.aut[0];
		document.getElementById("fotoDia").innerHTML = dataObj.day[0];
	showPhoto(int);
}



function updateThumbs(which)
{
	
	if(which == "next"){galleryStartIndex++}else{galleryStartIndex--};	
	if(galleryStartIndex > 0){
		var galleryCode = '<div class="thumbsbutton"><a href="javascript:updateThumbs(\'prev\');"><img src="img/prev_big.gif" alt="Anterior" border="0" onmouseover="this.src=\'img/prev_big_on.gif\'"  onmouseout="this.src=\'img/prev_big.gif\'" /></a></div>';
		}else{
		var galleryCode = '<div class="thumbsbutton"><img src="img/prev_big.gif" alt="Anterior" border="0" /></div>';
		}	
	galleryCode += '<div class="images" id="galleryThumbsList">';	
	galleryCode += '<ul>';
	var g = 0;	
	for(var i=galleryStartIndex;i<galleryStartIndex+maxPhotoDisplay;i++){		
		galleryCode += '<li id="f'+g+'"><a href="javascript:showPhoto('+i+');"><img src="'+photoCollection.foto[i]+'" alt="'+photoCollection.alt[i]+'" border="0" /></a></li>' ;g++;
		}		
		galleryCode += '</ul>';		
		if((galleryStartIndex+maxPhotoDisplay) < galleryLenght){
			galleryCode += '</div><div class="thumbsbutton"><a href="javascript:updateThumbs(\'next\');"><img src="img/next_big.gif" alt="Anterior" border="0" onmouseover="this.src=\'img/next_big_on.gif\'"  onmouseout="this.src=\'img/next_big.gif\'" /></a></div>';
		}else{
			galleryCode += '</div><div class="thumbsbutton"><img src="img/next_big.gif" alt="Anterior" border="0" /></div>';
			}		
		document.getElementById("galleryThumbs").innerHTML = galleryCode;	
}
	
	

function updateGallery(which)
{
	if(which == "next" && currentFoto < galleryLenght){
			currentFoto++;
			showPhoto(currentFoto-1);
		}else if(which == "prev" && currentFoto > 1){
			currentFoto--;
			showPhoto(currentFoto-1);
		}	
	if((currentFoto-1) >= (galleryStartIndex+maxPhotoDisplay) && (currentFoto-1) < galleryLenght){
			updateThumbs('next');
		}else if((currentFoto-1) <= galleryStartIndex && (currentFoto-1) > 0){
			updateThumbs('prev');
		}
}




function showPhotoEspectador(int)
{
	document.getElementById("fotoGaleria").src = photoCollection.foto[int];
	document.getElementById("galleryIndex").innerHTML = (int+1)+" de "+photoCollection.foto.length;
	currentFoto = int+1;
	document.getElementById("photoTitle").innerHTML = photoCollection.alt[currentFoto-1];
	document.getElementById("photoDescription").innerHTML = "<strong>AUTOR</strong>  "+photoCollection.author[currentFoto-1]+" &bull;  <strong>UBICACIÓ</strong>  "+photoCollection.country[currentFoto-1]+" &bull;  <strong>DATA</strong>  "+photoCollection.data[currentFoto-1];
    document.getElementById("photoLongDesc").innerHTML = photoCollection.desc[currentFoto-1];
}


function updateGalleryEspectador(which)
{
	galleryLenght = photoCollection.foto.length;
	if(which == "next" && currentFoto < galleryLenght){
			currentFoto++;
			showPhotoEspectador(currentFoto-1);
		}else if(which == "prev" && currentFoto > 1){
			currentFoto--;
			showPhotoEspectador(currentFoto-1);
		}
}
	

