var $pathModulos = 'modulos/';
var $strF = '-';
var $strR = '=';

/***************************************EVENTS****************************************/

$(document).ready(function(){
	cargarMenu();
	initLightbox();
	cargarCuerpo_izq('informacion.html');
});

function initLinks() {
	//Limpiamos los eventos Click
	$('a','#menu').unbind('click');
	$('a','#lista').unbind('click');
	$('div','#tabs').unbind('click');
	
	$('a','#galeria').unbind('click');
	
	$('a','#galeria').bind('click', onClickFoto);
	//Recargamos los eventos Click
	$('a','#menu').bind('click', onClickMenu);
	$('a','#lista').bind('click',onClickLista);
	$('div','#tabs').bind('click',onClickTabs);
}

/***************************************CLICK****************************************/

function onClickFoto(e)
{
	showLightbox(this);
	
	e.preventDefault();
}
	
	function onClickMenu(e)
	{
		if( $(this).attr('target') == '_blank') return true;
		
		cargarCuerpo_izq(this.href);
		e.preventDefault();
	}
	
	function onClickLista(e)
	{
		switch($(this).attr('rel'))
		{
			case "Cursos":
				cargarCuerpo_izq($pathModulos + 'Vista.FichaCurso.php?Id=' + this.id);
				break;
				
			default:
				cargarCuerpo_izq($pathModulos + 'Vista.Ficha.php?Id=' + this.id);	
				break;
		}
		
		e.preventDefault();
	}
	
	function onClickTabs(e)
	{
		if(this.id.length > 0) 
			cargarCuerpo_izq($pathModulos + this.id);
		e.preventDefault();
	}
	
/***************************************AJAX***************************************/

function cargarMenu()
{
	$('#menu').load($pathModulos + 'Vista.Menu.php', initLinks);
}

function cargarCabecera()
{
	$('#cabecera').fadeTo('slow', 0.33);
	$('#cabecera').load($pathModulos + 'cabecera.html', initLinks);
	$('#cabecera').fadeTo('slow', 1);
}

function cargarCuerpo_izq(src)
{
	$.ajax({
		async: true,
		type: "GET",
		dataType: "html",
		contentType: "application/x-www-form-urlencoded",
		url: src,
		beforeSend: function(){ $('#cuerpo_izq').html('<div class="loading"></div>'); },
		success: function(data){$('#cuerpo_izq').html(data);},
		complete: initLinks
	});
}

/***************************************FUNCTIONS***************************************/