//////////////////////////////////////////
// JavaScript Document
// -------------------
// Euromovil Extremadura
// http://www.euromovilextremadura.com
// euromovil@euromovilextremadura.com
//////////////////////////////////////////

var h=480;
var w=640;
var full=true;

// abre una ventana con los datos tecnicos del vehiculo
function ventana(nombre,direccion) {	
	full=false;
	if (document.documentElement.clientHeight < 530) { // evitamos que el boton de cerrar quede fuera del canvas
		window.location=direccion; // abrimos el cuadro con la info del coche en otra ventana
		return false;
	}
	Window.keepMultiModalWindow=true;
	new Ajax.Updater('coche', direccion+'/hidemenu/1/'); 
	var win=new Window(nombre, {className: "alphacube", title: nombre,  width:520, height:520, resizable: false, maximizable:false, minimizable:false, showEffectOptions: {duration:1}});	
	win.setContent("coche");
	win.setDestroyOnClose(); 
	win.showCenter(true);
	myObserver = { 
		onDestroy: function(eventName, eventWin) {
			if (eventWin == win) {
				$("coche").innerHTML="";
				Windows.removeObserver(this); 
			}
		},
		onShow: function(eventName, eventWin) {
			$("overlay_modal").setAttribute("onclick", "Windows.close(\""+Windows.getFocusedWindow().getId()+"\", event)");				
		},
		onClose: function(eventName, eventWin) {
			if (Windows.getFocusedWindow())
				$("overlay_modal").setAttribute("onclick", "Windows.close(\""+Windows.getFocusedWindow().getId()+"\", event)");
		}
	} 
	Windows.addObserver(myObserver); 
}

// abre una ventana con la imagen seleccionada
function verfoto(nombre) {	
	Window.keepMultiModalWindow=false; // la ventana desaparece mientras la foto esta en pantalla
	direccion=document['fotogrande'].src;
	if (document.documentElement.clientHeight>585) // si la foto cabe en el canvas, abrimos la ventana
		var win2=new Window("foto", {className: "alphacube", title: nombre, width:w+20, height:h+20, resizable: false, maximizable:false, minimizable:false, url: direccion, showEffectOptions: {duration:1}});
	else { // si no cabe, redimensionamos la ventana al tamaņo del canvas
		lowres_ratio = w/h;
		lowres_height = document.documentElement.clientHeight-45;
		lowres_width = lowres_height*lowres_ratio;		
		var win2=new Window("foto", {className: "alphacube", title: nombre, width:lowres_width, height:lowres_height, resizable: false, maximizable:false, minimizable:false, url: direccion, showEffectOptions: {duration:1}});
	}	
	win2.setDestroyOnClose(); 
	win2.showCenter(true);
	if (full) {
		myObserver = { 
			onDestroy: function(eventName, eventWin) {	
				if (eventWin == win2) {
					Windows.removeObserver(this); 
				}
			},
			onShow: function(eventName, eventWin) {
				$("overlay_modal").setAttribute("onclick", "Windows.close(\""+Windows.getFocusedWindow().getId()+"\", event)");
			}
		} 
		Windows.addObserver(myObserver); 
	}
}


/*
	Mini-navegador de imagenes en la ventana de informacion del vehiculo
	Ejemplo: navegar_foto('mifoto.jpg', 2)
	Resultado: carga en la imagen grande 'mifoto.jpg" y bordea de azul el thumbnail numero 2
	
*/
function navegar_foto(img_src,mi) {	

	// cargamos la imagen
	document.images['fotogrande'].src=img_src;
	
	// mostramos el gif de loading
	$("fotogrande").style.display="none";
	$("loading").style.display="block";
	
	// cambiamos el estilo a los thumbnails: bordear el thumbnail activo
	if (document.images['foto1']) document.images['foto1'].style.borderColor="#fff";
	if (document.images['foto2']) document.images['foto2'].style.borderColor="#fff";
	if (document.images['foto3']) document.images['foto3'].style.borderColor="#fff";
	if (document.images['foto4']) document.images['foto4'].style.borderColor="#fff";
	document.images['foto'+mi].style.borderColor="#0476bc";	
	
	// cuando la imagen se haya cargado, mostrarla y ocultar el gif
	// en opera a veces no funciona el onload
	if (window.opera){
		$("fotogrande").style.display="block";
		$("loading").style.display="none";		
	}
	else {
		document.images['fotogrande'].onload = function() {
			$("fotogrande").style.display="block";
			$("loading").style.display="none";		
		}
	}
}



