var numero=0;
var array_imagenes;
function cambioimg(modo)
{
	//var ruta=document.location.href.split("=");
	//var parametro=ruta[1];
			
	numero=(modo==0)? numero-1:numero+1;
	if(numero<0)						
		numero=((array_imagenes.length)-1);
	if(numero>((array_imagenes.length)-1))	
		numero=0;
	
	opacity('foto',  100, 0, 500);
	document.getElementById('foto').style.visibility=	"hidden";
		setTimeout(redimensionar,800);
	
	document.getElementById('contar').innerHTML=(numero+1)+" / "+array_imagenes.length;
	
	
	document.getElementById('foto').src='http://www.volumetric.es/img/promociones/'+array_imagenes[numero];

}

function redimensionar()
{
var pic = document.getElementById('foto');
var h = pic.offsetHeight;
var w = pic.offsetWidth;
//alert ('The image size is '+w+'*'+h);
document.getElementById('foto').style.opacity=0;
	if (w>h){
	document.getElementById('foto').width=340;
	}else{
		document.getElementById('foto').width=221;
	}

document.getElementById('foto').style.visibility=	"visible";

opacity('foto',  0, 100, 500);

document.getElementById('foto').className ="corner iradius10 ishadow15 ";

}

function cambioinicial(cual)
{
	numero=0;
	array_imagenes=(cual==1)? imagenes:imagenes2;
	
	
	var texto='<div class="caja_foto">';
    texto+='<img  style="opacity: 0;visibility:hidden;border:0px solid #000;" title="Promocion" src="http://www.volumetric.es/img/promociones/'+array_imagenes[0]+'" id="foto" alt="Inmueble" />';
   	texto+='</div>';
    texto+='<div class="h3fila">';
    texto+='<h3 class="gris"><a title="<<" href="javascript:cambioimg(0)">&lt; Anterior</a></h3>';
    texto+='<h3 class="gris" id="contar">1 / '+array_imagenes.length+'</h3>';
    texto+='<h3 class="gris"><a title=">>" href="javascript:cambioimg(1)">Siguiente &gt;</a></h3>';
    texto+='</div>';

	document.getElementById("zfoto").innerHTML=texto;
	opacity('foto',  100, 0, 500);
	setTimeout(redimensionar,800);

	
}
function cambiocontenido(texto)
{
	document.getElementById("zfoto").innerHTML=texto;    
}
function refrescar()
{
	window.location.reload();
	//window.history.go(0);
}
function formatear_numero(num)
{
	var texto=num.toString();
	var texto_devuelto;
	if(texto.indexOf(".")!=-1)
	{
		var partes=texto.split(".");
		texto_devuelto=(partes[1].length==1)?	partes[0]+"."+partes[1]+"0":partes[0]+"."+partes[1].substr(0,2);
	}
	else
		texto_devuelto=num+".00";
	return(texto_devuelto);	
}






function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}



function showHide(id)
{

	if (document.getElementById("texto"+id).style.display=='block'){
			document.getElementById("info"+id).innerHTML='+Info';
	document.getElementById("texto"+id).style.display='none';

	}else{
					document.getElementById("info"+id).innerHTML='-Info';
		document.getElementById("texto"+id).style.display='block';

	}

}
