/*–––––––––––––––––––– FUNCTIONS ––––––––––––––––––––*/

var URL;
var lastLocation;
var reDir;

function loadData()
{	
	if(window.location.hash)
	{
		var URLdata = window.location.hash.split('.');
		URLdata[0] = URLdata[0].substr(1);
		if(URLdata[0] != lastLocation)
		{
			var Nav = URLdata[0] + '/nav.php'
			$('#MENUBAR').animate({opacity: 0},250,function()
			{
				$('#MENUBAR').load(Nav, function()
				{
					$('#MENUBAR').animate({opacity: 1},250,function()
					{
						$(this).css('filter','');
					});
				});
			});
		};
		
		if(URLdata[1])
		{
			if(URLdata[2])
			{
				URL = URLdata[0] + '/' + URLdata[1] + '.php?id=' + URLdata[2];
			}
			else
			{
				URL = URLdata[0] + '/' + URLdata[1] + '.php';
			}
		}
		else
		{
			URL = URLdata + '/inicio.php';
		};
		
		$('#CONTENIDO').animate({opacity: 0},250,function()
		{
			$('#CONTENIDO').load(URL, function()
			{								
				
				if(reDir){clearTimeout(reDir);};
				
				$('#CONTENIDO').animate({opacity: 1},250,function()
				{
					$(this).css('filter','');
				});				
			});
		});
		lastLocation = URLdata[0];
	}
	else
	{
		if(lastLocation)
		{
			$('#MENUBAR').animate({opacity: 0},250,function()
			{
				$('#MENUBAR').empty();
			});
			
			$('#CONTENIDO').animate({opacity: 0},250,function()
			{
				$('#CONTENIDO').load('bepensa/inicio.php', function()
				{
					if(reDir){clearTimeout(reDir);};
					
					$('#CONTENIDO').animate({opacity: 1},250,function()
					{
						$(this).css('filter','');
					});
				});
			});
			lastLocation = '';
		}
		else
		{
			//$('#CONTENIDO').load('bepensa/inicio.php');
		}
	};
};

function initSliders()
{
	$('#SLIDERS .panel').hide();
	$('#SLIDERS .title').click(function()
	{
		var checkElement = $(this).next();
		if((checkElement.is('.panel')) && (checkElement.is(':visible')))
		{
			checkElement.slideUp('normal');
			$('.hideable').slideDown('normal');
			$('.revealer').css({cursor:'text'});
			return false;
		};
		
		if((checkElement.is('.panel')) && (!checkElement.is(':visible')))
		{
			$('#SLIDERS .panel:visible').slideUp('normal');
			checkElement.slideDown('normal');
			$('.hideable').slideUp('normal');
			$('.revealer').css({cursor:'pointer'});
			return false;
		};
	});
	
	$('.revealer').click(function()
	{
		$('.hideable').slideDown('normal');
		$('.panel').slideUp('normal');
		$('.revealer').css({cursor:'text'});
	});
};

/*––––––––––––––––––––  DOCUMENT READY ––––––––––––––––––––*/

$(document).ready(function()
{	
	loadData();
});

/*––––––––––––––––––––  URL CHANGE ––––––––––––––––––––*/

$(window).bind('hashchange', function()
{
	loadData();
});
