var indicemodal		= 0
var indicelabel 	= 0
var indiceloading 	= 0
var first 			= 0
var NLayer 			= new Array()

function Clayer(mensaje, ancho, alto, colorTrans)
{
	var self 
	var label
	 
	this.errorTimeout 	= 5
	this.hideTimeout  	= 2
	this.nav 			= navigator.appName
	
	this.top 	= '<div class="CLayerRowTitClayer" id="ClayerBottom_$idLayer$" style="text-align:left; $mode$">'+
				  '<a href="javascript:;" title="Cerrar" class="buttonRed18" style="float:right; visibility:$visibility_aspa$" onclick="$action_aspa$">X</a>'+
				  '<span class="CLayerNaranja CLayerNormal CLayerBold">&raquo;</span>'+
				  '<span class="font16 bold"> $titulo_layer$</span></div>'
			   
	this.modal 	= '<div class="$BgColor$" style="$mode2$" id="$idLayer$">' +
				  '$ClayerTop$' +
				  '<div class="$ClayerRow$" style="$altura_layer$$mode$" id="ClayerContent_$idLayer$">$ClayerMensaje$</div>' +
				  '$ClayerBottom$'
				  '</div>'
				 
	this.button 		= '<a href="$ancla_boton$" $id$ onclick="$action$" title="$text_button$" class="$styleButton$" style=" float:right; margin-left:5px;">$text_button$</a>'
	this.button_return 	= '<a href="#" $id$ onclick="$action_return$;return false;" title="$text_button_return$" class="$styleButtonReturn$" style=" float:left; margin-left:5px;">$text_button_return$</a>'
	this.button_close 	= '<a href="#" onclick="$action_button_close$;return false;" title="$text_button_close$" class="buttonRed18" style=" float:right; margin-left:5px;">$text_button_close$</a>'
	
	this.init = function ()  
	{
		this.texto 					= mensaje
		this.buttons 				= new Array()
		this.Stylesbuttons 			= new Array()
		this.actions 				= new Array()
		this.anclas 				= new Array()
		this.ids 					= new Array()
		this.numbuttons 			= 0
		this.needbuttonsdefault 	= 1
		this.ancla 					= 0
		this.NoFlash 				= 1
		this.width 					= ancho
		this.lanzador 				= "layer"
		this.topandbottom 			= 1
		this.titulo 				= "Aviso"
		this.ActionAspa 			= ""
		this.visibility_aspa 		= 'visible'
		this.botones_duplicados		= 0
		this.id_layer 				= Math.random()
		this.BClose 				= 0 // Si vale cero el button_close será 'Cerrar', si vale 1 'Cancelar' y si vale 2 'Se deshabilita el BClose'
		this.BReturn 				= 0 // Si vale cero no saldrá el botón 'Volver'
		this.ActionBClose 			= ''
		this.BgColor 				= 'CLayerBox'
		this.actionsReturn			= ''
		this.buttonsReturn			= ''
		this.StylesbuttonsReturn	= ''
		
		if (alto)
			this.height = alto
		else 
			this.height = 100
		
		if (colorTrans)
			this.colorTrans = colorTrans
		else
			this.colorTrans = 'CLayerDefaultColor'
		
		if (first == 0)
		{
			var html_doc = $_('head').item(0)
			var st = document.createElement('link')
			st.setAttribute('rel', 'stylesheet')
			st.setAttribute('href','http://www.facilisimo.com/css/layerV2-src.css')
			//st.setAttribute('href','http://facilisimo/css/layerV2-src.css')
			html_doc.appendChild(st)
			first++
		}
	}
	
	this.init()
	
	this.open = function(tipo)
	{
		var caja_layer 	= ''
		var m1 			= this.top
		var m2 			= this.modal
		var m3 			= ''
				
		// Titulo
		m1 = m1.replace(/\$titulo_layer\$/, this.titulo)
		if (this.ActionAspa == "")
			m1 = m1.replace(/\$action_aspa\$/,"$ocultarAviso("+this.id_layer+");")
		else
			m1 = m1.replace(/\$action_aspa\$/,this.ActionAspa)
		m1 = m1.replace(/\$visibility_aspa\$/, this.visibility_aspa)
		
		// Cuerpo
		if (this.topandbottom == 1)
		{
			m2 = m2.replace('$ClayerTop$', m1)
			if (this.numbuttons > 0)
				m2 = m2.replace('$ClayerRow$','CLayerRow')
			else
			{
				if(this.BClose < 2)
					m2 = m2.replace('$ClayerRow$','CLayerRow')
				else
					m2 = m2.replace('$ClayerRow$','CLayerRowWithoutBottom')
			}
		}
		else
		{
			if (this.BClose < 2)
			{
				m2 = m2.replace(/\$ClayerTop\$/,"")
				m2 = m2.replace(/\$ClayerRow\$/,"CLayerRowWithoutTopBottom")
			}
			else
			{
				m2 = m2.replace(/\$ClayerTop\$/,"")
				m2 = m2.replace(/\$ClayerRow\$/,"CLayerRowWithoutTop")
			}
		}
		
		// Botones
		for (i = 0; i < this.numbuttons; i++)
		{
			var aux = this.button
			aux = aux.replace(/\$text_button\$/g, this.buttons[i])
			aux = aux.replace(/\$styleButton\$/g, this.Stylesbuttons[i])
			aux = aux.replace("$action$",this.actions[i] + ";return false;")
			// Establecemos los ids
			if (this.ids[i] != "")
				aux = aux.replace("$id$",'id="' + this.ids[i] + '"')
			else
				aux = aux.replace("$id$",'')
			// Establecemos las anclas
			if (this.anclas[i] == 0 && this.ancla == 1)
				aux = aux.replace("$ancla_boton$","#")
			else
				aux = aux.replace("$ancla_boton$","javascript:;")
			m3 = m3 + aux
		}
		// Añadimos los botones, el boton close y el boton volver
		m3_aux = '<div style=" float:left; $mode$; " id="ClayerBottons_'+this.id_layer+'">'
		if (this.BClose != 2)
			m3_aux += this.button_close
		if (this.BReturn != 0)
		{
			m3_aux += this.button_return
			m3_aux = m3_aux.replace("$id$","BLayerVolver")
			m3_aux = m3_aux.replace("$action_return$",this.actionsReturn)
			m3_aux = m3_aux.replace(/\$text_button_return\$/g,this.buttonsReturn)
			m3_aux = m3_aux.replace("$styleButtonReturn$",this.StylesbuttonsReturn)
		}
		m3_aux += m3 + '</div>'
		m3 = m3_aux
		
		// Juntamos todo
		caja = m2.replace("$ClayerMensaje$", "$ClayerDuplicateBottons$" + this.texto)
		if (this.botones_duplicados == 1)
			caja = caja.replace("$ClayerDuplicateBottons$","<div style='margin-bottom:30px;'>"+m3+"</div>")
		else	
			caja = caja.replace("$ClayerDuplicateBottons$","")
		caja = caja.replace("$ClayerBottom$", m3)
		caja = caja.replace(/\$mode2\$/g,"width:" + this.width + "px;")
		caja = caja.replace(/\$mode\$/g,"width:" + this.width + "px;")
		caja = caja.replace(/\$idLayer\$/g,this.id_layer)
		caja = caja.replace(/\$BgColor\$/g,this.BgColor)
		if (this.BClose != 2) 
		{
			if (this.BClose == 0)
				text_button_close = 'CERRAR'
			else
				text_button_close = 'CANCELAR'
			caja = caja.replace(/\$text_button_close\$/g,text_button_close)
			if (this.ActionBClose == '')
				caja = caja.replace(/\$action_button_close\$/g,"$ocultarAviso("+this.id_layer+");")
			else
				caja = caja.replace(/\$action_button_close\$/g,this.ActionBClose)
		}
		
		if (this.topandbottom == 1)
			AltoContenido = this.height - 60 // Para firefox.
		else
			AltoContenido = this.height - 35
		
		
		if (tipo!='undefined' && tipo=='mens')
		{
			caja = caja.replace(/\$altura_layer\$/g,'')
			this.showModal(caja,'si','mens')
		}
		else
		{
			caja = caja.replace(/\$altura_layer\$/g,'height:'+AltoContenido+'px;')
			this.showModal(caja)
		}
	}
	
	this.openScroll = function()
	{
		this.showModal(this.texto,'no')
	}
	
	this.AddButton = function(text,action,styleButton)
	{
		this.buttons[this.numbuttons] = text.toUpperCase()
		this.actions[this.numbuttons] = action
		
		if (styleButton)
			this.Stylesbuttons[this.numbuttons] = styleButton
		else
			this.Stylesbuttons[this.numbuttons] = "buttonExpo18"
		this.ids[this.numbuttons] = ""
		this.numbuttons++
	}
	
	this.ActivateButtonReturn = function(text,action,styleButton)
	{
		this.BReturn = 1
		this.buttonsReturn = text.toUpperCase()
		this.actionsReturn = action
		
		if(styleButton)
			this.StylesbuttonsReturn = styleButton
		else
			this.StylesbuttonsReturn = "buttonExpo18"
	}
	
	this.setMensaje = function(mensaje)
	{
		this.texto = mensaje
		this.buttons = new Array()
		this.actions = new Array()
		this.numbuttons = 0
	}
	
	this.addButton 				 	= function(text,action){this.AddButton(text, action)}
	this.setNoNeedButtonsDefault 	= function(){this.needbuttonsdefault = 0}
	this.setYesNeedButtonsDefault 	= function(){this.needbuttonsdefault = 1}
	this.setLanzador 				= function(launch){this.lanzador = launch}
	this.setActionDefault 			= function(action){this.ActionAspa = action; this.ActionBClose = action}
	this.setModeBClose				= function(num){this.BClose = num}
	
	this.AddIdButton 				= function(pos,id){this.ids[pos] = id}
	this.addIdButton 				= function(pos,id){this.AddIdButton(pos,id)}
	
	this.SinTopAndBottom 			= function(){this.topandbottom = 0}
	this.ConTopAndBottom 			= function(){this.topandbottom = 1}
	this.setTitulo 					= function(texto){this.titulo = texto}	
	
	this.getIndiceModal 			= function(){return indicemodal}
	this.setAlto 					= function(num){this.height = num}
	this.setAncho 					= function(num){this.width = num}
	this.setVisibleAspa 			= function(){this.visibility_aspa = 'visible'}
	this.setHiddenAspa 				= function(){this.visibility_aspa = 'hidden'}
	this.Cerrar						= function(){this.hideModal()}
	this.setBgColor					= function(color){this.BgColor = color}
	this.setNoFlash					= function(){this.NoFlash = 0}
	
	this.setAncla 					= function(numBottom){this.ancla = 1; this.anclas[numBottom] = 1}
	this.setDuplicateButtons 		= function(){this.botones_duplicados = 1}
	this.setColorTrans				= function(color){this.colorTrans = color}
	
	// Funciones de etiquetas label
	this.errorLabel = function(msg)
	{
		crearEtiqueta()
		label.style.color = '#FFF'
		label.style.background = '#C30'
		label.innerHTML = msg
		setTimeout(function(){if($('_ajax_label')) document.body.removeChild($('_ajax_label'))},this.errorTimeout*1000)
	}
	
	this.showLabel = function(msg)
	{
		crearEtiqueta()
		label.style.color = '#000'
		label.style.background = '#FD6'
		label.innerHTML = msg
		label.style.display = ''
	}
	
	this.hideLabel = function(msg)
	{
		indicelabel--
		if(msg){
			crearEtiqueta()
			label.style.color = '#FFF'
			label.style.background = '#093'
			label.innerHTML = msg
			setTimeout(function(){if($('_ajax_label')) document.body.removeChild($('_ajax_label'))},this.hideTimeout*1000)
		}
		else 
			if($("_ajax_label")) 
				document.body.removeChild($("_ajax_label"))
	}
	
	// Funciones de redimensionamiento del layer
	this.NewAlto = function(nAlto)
	{
		var idventana = this.id_layer
		if (nAlto > this.height)
		{
			var diferencia = nAlto - this.height
			var NuevoAlto = this.height + diferencia
		}
		else
		{
			if (this.height > nAlto)
			{
				var diferencia = this.height - nAlto
				var NuevoAlto = this.height - diferencia
			}
			else
				var NuevoAlto = this.height
		}
		$(idventana).style.height = NuevoAlto +'px'
		
		if (this.topandbottom == 1)
		   AltoContenido = NuevoAlto - 70 // Para firefox.
		else
		   AltoContenido = NuevoAlto - 35
		$('ClayerContent_'+this.id_layer).style.height = AltoContenido + 'px'
	}
	
	this.NewAncho = function(nAncho)
	{
		var nav = navigator.appName
		if (nav == "Microsoft Internet Explorer") 
			NuevoAncho = nAncho - 10
		else
			NuevoAncho = nAncho
		var idventana = this.id_layer
		
		$(idventana).style.width = NuevoAncho + 'px'
		$('ClayerBottom_'+this.id_layer).style.width = NuevoAncho + 'px'
		$('ClayerContent_'+this.id_layer).style.width = NuevoAncho + 'px'
		$('ClayerBottons_'+this.id_layer).style.width = NuevoAncho + 'px'
	}
	
	// Funciones utilizadas para no depender de la clase Ajax.
	this.showModal = function(html,trans,tipo)
	{
		
		if (trans == 'no'){
			//indicemodal++
			NLayer[indicemodal] = idventana
			var idventana = '_ajax_modalcontent_' + this.id_layer + '_' + indicemodal 
			if(!$(idventana))
			{
				modal = document.createElement('DIV')
				modal.style.cssText = 'z-index:'+((10000*indicemodal)+1)+';'
				modal.id = idventana
				document.body.appendChild(modal)
			}
			
			$(idventana).innerHTML = html;
			document.body.style.height = '100%'
			$(idventana).style.top = getScrollY() + 'px'			
		}
		else{
			
				indicemodal++
				var idventana = '_ajax_color_' + indicemodal 
				var navegador = navigator.userAgent;
				if (navegador.indexOf('Chrome') > 0)
					var altura = document.body.scrollHeight
				else
					var altura = document.documentElement.scrollHeight
				
				modal = ''
				if(!$(idventana))
				{
					modal = document.createElement('DIV')
					modal.style.cssText = 'position:absolute; left: 0px; top: 0px; width: 100%; height: ' + altura + 'px; z-index:'+((10000*indicemodal)+1)+'; filter:alpha(opacity=70);opacity:.70;'
					modal.className = this.colorTrans
					modal.id = idventana
					document.body.appendChild(modal)
				}
				
				indicemodal++
			
				var idframe_trans = '_ajax_frame_trans_' + indicemodal
				var modal = ''
				
				
				if (!$(idframe_trans))
				{
					modal = document.createElement('IFRAME')
					modal.id = idframe_trans
					modal.name = idframe_trans
					modal.scrolling = "no" 
					modal.frameBorder = "0"
					if (this.nav == "Microsoft Internet Explorer" && this.colorTrans != 'default_color')  
						modal.src = "http://www.facilisimo.com/js/layer_trans.cfm?altura=" + altura //+ "&className=" + this.colorTrans
					modal.style.cssText = "background:transparent;border:none;width:100%; height:" + altura + "px; position:absolute; top:0; left:0; z-index:"+((10000*indicemodal)+1)+"; filter:alpha(opacity=0);opacity:.0;"
					if (this.colorTrans != 'CLayerTransparente')
						modal.className = this.colorTrans
					else 
						modal.className = "CLayerDefaultColor"
					document.body.appendChild(modal)
				}
				
				indicemodal++
				NLayer[indicemodal] = idventana
				var idventana = '_ajax_modalcontent_' + this.id_layer + '_' + indicemodal 
				modal = ''
				if(!$(idventana))
				{
					modal = document.createElement('DIV')
					modal.style.cssText = 'position:absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index:'+((10000*indicemodal)+1)+';'
					if (this.colorTrans == 'CLayerTransparente')
						modal.className = this.colorTrans
					modal.id = idventana
					document.body.appendChild(modal)
				}

				var heightTabla = 'height="100%"';
				if (tipo!='undefined' && tipo=='mens')
					heightTabla = '';

				if (this.colorTrans == 'CLayerTransparente')
					$(idventana).innerHTML = '<table border="0" width="100%" '+heightTabla+' align="center" class="CLayerTransparente"><tr><td align="center"><div class="CLayerModalStyle">' + html + '<div style="clear:both"></div></div></td></tr></table>'
				else
					$(idventana).innerHTML = '<table border="0" width="100%" '+heightTabla+' align="center"><tr><td align="center"><div class="CLayerModalStyle">' + html + '<div style="clear:both"></div></div></td></tr></table>'
					
				document.body.style.height = '100%'
				
				if (tipo!='undefined' && tipo=='mens')
					$(idventana).style.top = '50px'
				else	
					$(idventana).style.top = getScrollY() + 'px'
				
				if (this.NoFlash == 1)
				{
					var arr_obj = document.getElementsByTagName('object');
					for(i = 0; i < arr_obj.length; i++)
						arr_obj[i].style.visibility = 'hidden';	
				}
		}
	}
	
	this.hideModal = function()
	{
		if($('_ajax_modalcontent_'+this.id_layer+'_'+indicemodal)){
			document.body.removeChild($('_ajax_modalcontent_'+this.id_layer+'_'+indicemodal))
			indicemodal--
			document.body.removeChild($('_ajax_frame_trans_'+indicemodal))
			NLayer[indicemodal] = null
			indicemodal--
			document.body.removeChild($('_ajax_color_'+indicemodal))
			indicemodal--
		}
		if(indicemodal>0 && $('_ajax_modalcontent_'+this.id_layer+'_'+indicemodal))
			$('_ajax_modalcontent_'+this.id_layer+'_'+indicemodal).style.top = getScrollY()

		
		if (this.NoFlash == 1 && indicemodal < 1)
		{	
			var arr_obj = document.getElementsByTagName('object');
			for(i = 0; i < arr_obj.length; i++)
				arr_obj[i].style.visibility = 'visible';	
		}
	}
	
	function crearEtiqueta()
	{
		if($('_ajax_label'))
			label = $('_ajax_label')
		else{
			indicelabel++
			label = document.createElement('SPAN')
			label.style.cssText = 'position: absolute; right:0px; padding: 2px 20px 2px 20px; font-family: arial; font-size: 13px; font-weight: bold; z-index:'+((10000*indicelabel)+2)
			label.id = '_ajax_label'
			document.body.appendChild(label)
		}

		label.style.top = getScrollY()+'px'
	}
	
	function getScrollY()
	{
		var scrollY = 0
		
		if ( document.documentElement && document.documentElement.scrollTop )		
		{
			scrollY = document.documentElement.scrollTop
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset
		}else if ( window.scrollY ){
			scrollY = window.scrollY
		}

		return scrollY
	}
	
	function $(id){return document.getElementById(id)}
	
	function $_(name){return document.getElementsByTagName(name)}
	
	self = this
}

// Funcion que monta un layer básico para sacar avisos.
function $aviso(texto,colorT)
{
	if (colorT)
		var miLayer = new Clayer(texto, 344, 120, colorT)
	else
		var miLayer = new Clayer(texto, 344, 120)
	var id_layer = miLayer.id_layer
	var indicemodal = miLayer.getIndiceModal()
	miLayer.ConTopAndBottom()
	miLayer.setTitulo('Aviso')
	miLayer.setVisibleAspa()
	miLayer.setModeBClose(2)
	miLayer.addButton('Aceptar','$ocultarAviso('+id_layer+')')
	miLayer.setActionDefault('$ocultarAviso('+id_layer+')')
	miLayer.open()
} 

var miLayerLoading = new Clayer('',260,140)
function $Loading(texto,colorTrans)
{
	indiceloading++
	var Capaloading = '<div style="width:252px; margin: 0 auto; ">'+
	'<div style="padding:5px 0; width:252px; text-align:center; font-size:14px; color:#e83b45;">'+
	'   <a href="javascript:;" title="Cerrar" class="buttonRed18" style="float:right;" onclick="miLayerLoading.Cerrar()">X</a>'+
	'	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="80" height="52">'+
	'   <param name="movie" value="http://www.facilisimo.com/comun/swf/preloader-orange.swf" />'+
	'   <param name="quality" value="high" />'+
	'	<param name="wmode" value="transparent" />'+
	'   <embed src="http://www.facilisimo.com/comun/swf/preloader-orange.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="80" height="52" wmode="transparent" ></embed>'+
	'  	</object>'+
	'</div>'+
	'<div style="padding:5px 0; text-align:center; font-size:14px; font-weight:bold;">' + texto + '<BR />ESPERA UN MOMENTO POR FAVOR</div>'+
	'</div>'
	
	miLayerLoading.setMensaje(Capaloading)
	if (colorTrans)	
		miLayerLoading.setColorTrans(colorTrans)
	else
		miLayerLoading.setColorTrans("CLayerDefaultColor")
	miLayerLoading.setAlto(140);
	miLayerLoading.setAncho(260);
	miLayerLoading.setNoFlash();
	miLayerLoading.SinTopAndBottom();
	miLayerLoading.setModeBClose(2);
	miLayerLoading.open();
}	

function $CloseLoading()
{
	indiceloading--
	miLayerLoading.Cerrar()	
}

// Funcion que monta el label de error
function $LError(msg)
{
	var miLabel = new Clayer('',0,0)
	miLabel.errorLabel(msg)
}

// Funcion que monta el label tipo google
function $LAviso(msg)
{
	var miLabel = new Clayer('',0,0)
	miLabel.showLabel(msg)
}

// Funcion que saca un label verde que se cierra solo a los 2 segundos
function $Label(msg)
{
	var miLabel = new Clayer('',0,0)
	miLabel.hideLabel(msg)
}

// Funciones externas a la clase que buscan el layer cuando se pierde el objeto una vez pintado
// Esto es necesario en los casos de $aviso y cuando sale la barra de titulo por defecto.
function $ocultarAviso(id)
{
		if(document.getElementById('_ajax_modalcontent_'+id+'_'+indicemodal)){
			document.body.removeChild(document.getElementById('_ajax_modalcontent_'+id+'_'+indicemodal))
			indicemodal--
			document.body.removeChild(document.getElementById('_ajax_frame_trans_'+indicemodal))
			NLayer[indicemodal] = null
			indicemodal--
			document.body.removeChild($('_ajax_color_'+indicemodal))
			indicemodal--
		}

		if(document.getElementById('_ajax_modalcontent_'+id+'_'+indicemodal))
			document.getElementById('_ajax_modalcontent_'+id+'_'+indicemodal).style.top = getScrollY()
			
		if (indicemodal < 1)
		{	
			var arr_obj = document.getElementsByTagName('object');
			for(i = 0; i < arr_obj.length; i++)
				arr_obj[i].style.visibility = 'visible';	
		}	
}

function getScrollY()
{
	var scrollY = 0
	
	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset
	}else if ( window.scrollY ){
		scrollY = window.scrollY
	}
	
	return scrollY
}

var mostrando_aviso=new Array();//array con los aviso mostrados

// Clase para los avisos emergentes 
function avisoEmergente(titulo,texto, alto, x)
{
	var clase = this
	this.texto = ''
	this.alto = alto
	this.posBottom = 0
	this.titulo = titulo
	this.msg
	this.idx
	this.espacio = (es_ie()?15:5)//le damos mas pixeles en IE
	this.tiempo = (es_ie()?15:5)//le damos mas tiempo en IE
	
	this.init = function()
	{		
		mostrando_aviso.push(clase) //lo meto en el array		
		clase.idx = mostrando_aviso.length - 1
		clase.msg = document.createElement('div')
		clase.msg.id = 'mostrando_aviso' + clase.idx
		clase.msg.className = 'CLayerFixedClass'
		
		if ( x == 'left')
			clase.msg.style.left = "0px";
		else
			clase.msg.style.right = "0px";
		
		clase.msg.innerHTML = '<div class="CLayer_promo" id="idVentanaPromo" style="display:block;">'+
							  '		<div class="contS">'+
				    		  '			<div class="headS">'+
							  '				<a href="#" onClick="mostrando_aviso['+clase.idx+'].hide();return false;" class="buttonRed18" style="float:right">X</a>facilisimo/ <span class="font14">Aviso</span>'+
							  '			</div>'+
    						  '			<div class="cuerpoS" style="background:#FFF url(http://api.facilisimo/api/html/images/degVentanaPromo1.gif) repeat-x;">'+
							  '				<p id="txtPromo"><span style="font-size:16px"></span><span class="font20 bold" style="margin-bottom:10px; color:#469dbe;">'+ this.titulo +'</span><br /><br /></p>'+
							  '				<p>' + this.texto + '</p>'+
	    					  '			</div>'+
							  '		</div>'+
							  '</div>'
			
		//al hacer click en cualquier link debe cerrar la capa
		var link_arr = clase.msg.getElementsByTagName('a')
		for (i=0;i<link_arr.length;i++)			
			addListen('click',link_arr[i],function(){mostrando_aviso[clase.idx].hide()})
		
		clase.msg.style.bottom = -alto + 'px'//fuera de lo que se ve
		if(clase.idx == 0)
			clase.posBottom = (clase.idx * alto) + 215
		else
			clase.posBottom = mostrando_aviso[clase.idx-1].posBottom + alto + 75
			
		document.body.appendChild(clase.msg)
		clase.show()
	}
	
	this.show = function()
	{
		var valor = parseInt(clase.msg.style.bottom.replace('px',''))
		if (valor<clase.posBottom)
		{
			clase.msg.style.bottom = (valor + clase.espacio)  + 'px'
			setTimeout('mostrando_aviso['+clase.idx+'].show()', clase.tiempo)
		}
		else
			setTimeout('mostrando_aviso['+clase.idx+'].hide()',15000)
	}
	
	this.hide = function()
	{
		var valor = parseInt(clase.msg.style.bottom.replace('px',''))
		if (valor>-clase.alto)
		{			
			clase.msg.style.bottom = (valor - clase.espacio) + 'px'
			setTimeout('mostrando_aviso['+clase.idx+'].hide()', clase.tiempo)
		}
		else
		{
			clase.msg.style.display = 'none'
			//mostrando_aviso[clase.idx].posBottom=0-mostrando_aviso[clase.idx].alto;
			mostrando_aviso[clase.idx].posBottom = 0;
		}
	}	
	
	//lanzamos el mensaje 
	if(texto!=null)
	{
		this.texto=texto
		this.init()//si viene el texto directamente sale
	}
}

function es_ie(){
	return (navigator.userAgent.toLowerCase().indexOf("msie") != -1)&&(navigator.userAgent.toLowerCase().indexOf("opera") == -1);
}

function addListen(event, elem, func)
{  
	if (elem.addEventListener)
		elem.addEventListener(event,func,false)
	else if (elem.attachEvent) 
	{ 
		var r = elem.attachEvent("on"+event, func)
		return r
	}
	else throw 'No es posible añadir evento'
}

function $avisoEmergente(titulo,texto,alto)
{
	var aviso = new avisoEmergente(titulo,texto,alto,'left');	
}

