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

//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;
	}


/**
 * Retorna el codigo para un video de YouYube
 */
function getYouTubeVideoCode (videoId, autoPlay)
	{
	return '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+videoId+'&hl=es_MX&fs=1'+((autoPlay)?'&autoplay=1':'')+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videoId+'&hl=es_MX&fs=1'+((autoPlay)?'&autoplay=1':'')+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
	}

/**
 * Muestra un video de YouYube
 */
function showYouTubeVideo (videoId, a)
	{
	if(Browser&&Browser.Plugins&&Browser.Plugins.Flash&&(Browser.Plugins.Flash.version===undefined||Browser.Plugins.Flash.version<=0))
		return true;
		
	a.blur();
	
	var virtualBoxCode = '<div class="showVideoVirtualBox">';
	virtualBoxCode+='<div class="closeZone"><button type="button" title="Cerrar" onclick="closeCurrentVirtualBox();"></button></div>';
	virtualBoxCode+='<div class="videoPadding">'+getYouTubeVideoCode(videoId,true)+'</div>';
	virtualBoxCode+='</div>';

	return showVirtualBox(433,397, virtualBoxCode, a);
	}

/**
 * Escribe el codigo para ver un video de YouTube embebido
 */
function writeYouTubeVideo (videoId, autoPlay, description)
	{
	if(autoPlay===undefined)
		autoPlay = false;

	if(description===undefined||description.length<=0)
		description = null;
		
	if(Browser&&Browser.Plugins&&Browser.Plugins.Flash&&(Browser.Plugins.Flash.version===undefined||Browser.Plugins.Flash.version<=0))
		{
		document.write('<center class="showVideoZone"><a href="http://www.youtube.com/watch?v='+videoId+'" title="Ver Video..." target="_blank" rel="external nofollow"></a>');
		if(description!=null)
			document.write('<div class="pieImagen">'+description+'</div>');
		document.write('</center>');
		return;
		}
	
	document.write('<center class="embedVideoZone"><div class="video"><div>'+getYouTubeVideoCode(videoId,autoPlay)+'</div></div>');
	if(description!=null)
		document.write('<div class="pieImagen">'+description+'</div>');
	document.write('</center>');
	}


/**
 * Muestra un aviso en VirtualBox
 */
function showAvisoVirtualBox (avisoContent, id_aviso)
	{
	var htmlCode = '<div class="avisosModule"><form action="avisos/" method="post" onsubmit="return sendCodecAjaxRequest(this);"><table cellspacing="0" cellpadding="0"><tr><td class="avisoMiddle">';

	htmlCode+= '<div class="aviso"><div class="avisoTop"></div> <div class="avisoPadding"><table cellspacing="0" cellpadding="0"><tr><td class="avisoIcon">&nbsp;</td><td class="avisoContent">';

	htmlCode+= avisoContent;

	htmlCode+= '<div class="submitZone"><button type="submit" title="Confirmar...">Confirmar de Enterado</button></div>';
		
	htmlCode+= '<input type="hidden" name="id_aviso" value="'+id_aviso+'" />';
	
	htmlCode+= '</td></tr></table></div><div class="avisoBottom"></div></div>';
	
	htmlCode+= '</td></tr></table></form></div>';

	window.addEvent('load', function() {showVirtualBox(704,600,htmlCode);});
	}

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

/*********** Google Maps ***********/

/**
 * Mustra el componente de Google Maps
 */
function showGooleMap (a)
	{
	var code = '<div id="googleMap">';
		code+='<div class="frameWrapper">';
			code+='<iframe width="485" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.mx/maps/ms?ie=UTF8&amp;hl=es&amp;msa=0&amp;msid=204441302468310989111.00049ef0bbe469c90c4ba&amp;ll=19.627794,-99.110069&amp;spn=0,0&amp;output=embed"></iframe>';
		code+='</div>';

		code+='<div class="closeZone"><a onclick="closeCurrentVirtualBox();" title="Cerrar"></a></div>';
		
		
	code+='</div>';
	return showVirtualBox(505,452,code,a);
	}

