function carregaFoto(index){

    fotoActual += index;

    if (fotoActual >= fotos.length){
        fotoActual = 0;
    } else if (fotoActual < 0){
        fotoActual = fotos.length - 1;
    }


    img1 = new Image();
    
    img1.src = fotos[fotoActual];
    precarregaFoto();
}

function precarregaFoto(){

    if((img1.width!=0)&&(img1.height!=0)){
        obriFoto();
    }else{
        interval = setTimeout("precarregaFoto()", 20);
    }
}

function obriFoto(){

    document.getElementById("foto").innerHTML = "<img src='"+fotos[fotoActual]+"' alt='foto' />";

    if (!fotosGrans[fotoActual] || fotosGrans[fotoActual]==''){
        document.getElementById("navegacio_left").innerHTML = "&nbsp;";
    }else{
        document.getElementById("navegacio_left").innerHTML = "<a href='javascript:ampliaFotoGran();'>Ampliar</a>";
    }

}

function ampliaFotoGran() {

    window.open( "http://marinagrup.com/popup.html?"+fotosGrans[fotoActual], "", "resizable=0,HEIGHT=200,WIDTH=200,status=0,toolbar=0");

}

function posaFoto() {

		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			 //Non-IE
			 myWidth = window.innerWidth;
			 myHeight = window.innerHeight;
		} else if( document.documentElement &&
		   ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			 //IE 6+ in 'standards compliant mode'
			 myWidth = document.documentElement.clientWidth;
			 myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			 //IE 4 compatible
			 myWidth = document.body.clientWidth;
			 myHeight = document.body.clientHeight;
		}

		myWidth = document.images[0].width - myWidth;
		myHeight = document.images[0].height - myHeight;
		window.resizeBy(myWidth, myHeight);
		self.focus();

}
