/**
 * Funciones encargadas de mostrar elementos en "virtual box" (como imagenes)
 */

//VitualBox que esta activo
var currentVirtualBox = null;


/**
 * Muestra un virtual box
 */
function showVirtualBox (width, height, virtualBoxCode, a)
	{
	closeCurrentVirtualBox();

	
	if(a===undefined||a==null)
		a = new Element('a', {title: 'Virtual Box'});
	
	
	if(a.virtualBox==null)
		{
		var title = a.title;
		a.title = width+' :: '+height;
		a.virtualBox = new Virtual.HTML.single(a, {enable: {caption: false}, style: false, effect: ((Browser&&Browser.ie6) ? 'fix': 'slide'), content: virtualBoxCode});
		a.title = title;
		}
			
	currentVirtualBox = a.virtualBox;
	a.virtualBox.create();
	
	return false;
	}

/**
 * Cierra la actual VirtualBox
 */
function closeCurrentVirtualBox ()
	{
	if(currentVirtualBox!=null)
		{
		currentVirtualBox.remove();
		currentVirtualBox=null;
		}
	}


/**
 * Muestra una imagen con marco en un virtual box
 */
function showImagenMarco (width, height, src, alt, a)
	{
	if(src===undefined||src==null)
		return;
	
	if(a===undefined)
		a=null;

	if(alt===undefined||alt==null)
		alt=' ';


	loadImagesInChache('templates/plantilla/images/marcos/close-marco.png');

	if(Browser&&Browser.ie6)
		loadImagesInChache('templates/plantilla/images/marcos/marco-corners-ie6.png', 'templates/plantilla/images/marcos/marco-h-ie6.png', 'templates/plantilla/images/marcos/marco-v-ie6.png');
	else
		loadImagesInChache('templates/plantilla/images/marcos/marco-corners.png', 'templates/plantilla/images/marcos/marco-h.png', 'templates/plantilla/images/marcos/marco-v.png');

	loadImagesInChache(src);
		
	
	var totalWidth = width+80;
	var totalHeight = height+76;


	var totalDimensionsStyle = 'style="width:'+totalWidth+'px; height:'+totalHeight+'px;"';
	var dimensionsStyle = 'style="width:'+width+'px; height:'+height+'px;"';
	var marcoMiddleStyle = 'style="height:'+(totalHeight-120)+'px;"';
	
	
	var codeHTML = '<div id="imageMarcoBox">';

		codeHTML+= '<div class="relative" '+totalDimensionsStyle+'>';
				
			codeHTML+= '<div class="imageContainer marcoBg" '+dimensionsStyle+'><table cellspacing="0" cellpadding="0"><tr><td '+dimensionsStyle+'><img src="templates/plantilla/images/loading.gif" alt="Cargando..."/><div>Cargando...</div></td></tr></table></div>';

			codeHTML+= '<div class="imageContainer" '+dimensionsStyle+'><table cellspacing="0" cellpadding="0"><tr><td '+dimensionsStyle+'><img src="'+src+'" alt="'+alt+'" /></td></tr></table></div>';
						
			codeHTML+= '<div class="marco" '+totalDimensionsStyle+'>';
				codeHTML+= '<div class="marcoTop"><div><div></div></div></div>';
				codeHTML+= '<div class="marcoMiddle" '+marcoMiddleStyle+'><div '+marcoMiddleStyle+'></div></div>';
				codeHTML+= '<div class="marcoBottom"><div><div></div></div></div>';
			codeHTML+= '</div>';
				
		codeHTML+= '</div>';

		codeHTML+= '<center class="closeMarco"><a onclick="closeCurrentVirtualBox();" title="Cerrar"></a></center>';
		
	
	codeHTML+= '</div>';

	closeCurrentVirtualBox();

	showVirtualBox(totalWidth,totalHeight+18,codeHTML,a);
	}

/**
 * Muestra una imagen con marco en un virtual box del href de a
 */
function showImagenMarcoLink (a,width,height)
	{
	if(width===undefined||width<=0)
		width=500;

	if(height===undefined||height<=0)
		height=370;
	
	showImagenMarco(width, height,a.href,a.title,a);
	a.blur();
	return false;
	}



/**
 * Muestra una imagen con borde en un virtual box
 */
function showImagenBorder (width, height, src, alt, a, moreInfoCode)
	{
	if(src===undefined||src==null)
		return;
	
	if(a===undefined)
		a=null;

	if(alt===undefined||alt==null)
		alt=' ';

	if(moreInfoCode===undefined)
		moreInfoCode=null;
	
	loadImagesInChache(src);
	loadImagesInChache('templates/plantilla/images/images-border/border-h.png', 'templates/plantilla/images/images-border/border-v.png', 'templates/plantilla/images/images-border/corners.png', 'templates/plantilla/images/close-bullet.png', 'templates/plantilla/images/more-bullet.png');
									
	
	var totalWidth = width+14;
	var totalHeight = height+14;
		

	var dimensionsStyle = 'style="width:'+width+'px; height:'+height+'px;"';
			
	
	var codeHTML = '<div id="imageBorderBox">';

		codeHTML+= '<div class="imageBorder" style="width:'+totalWidth+'px; height:'+totalHeight+'px;">';
			codeHTML+= '<img src="'+src+'" width="'+width+'" height="'+height+'" alt="'+alt+'" />';
			codeHTML+= '<div class="right"></div><div class="left"></div><div class="top"><div><div></div></div></div><div class="bottom"><div><div></div></div></div>';
		codeHTML+= '</div>';
		
		codeHTML+= '<center><table cellspacing="0" cellpadding="0"><tr>';

			if(moreInfoCode!=null)
				codeHTML+= '<td>'+moreInfoCode+'</td>';
		
			codeHTML+= '<td><a class="closeLink" onclick="closeCurrentVirtualBox();" title="Cerrar">Cerrar</a></td>';
									
		codeHTML+='</tr></table></center>';
		
		
	codeHTML+= '</div>';

	closeCurrentVirtualBox();

	showVirtualBox(totalWidth,totalHeight+20,codeHTML,a);
	}


/**
 * Muestra la lamina de un trabajo de curriculo
 */
function showLaminaCurriculo (a, trabajoUri)
	{
	if(trabajoUri===undefined)
		trabajoUri=null;

	showImagenBorder(650,500,a.href,a.title,a,(trabajoUri!=null)?('<a class="moreInfoLink" href="curriculum/'+trabajoUri+'.html" title="Mas sobre este trabajo...">M&aacute;s Informaci&oacute;n...</a>'):null);
	a.blur();
	return false;
	}

