var selectedId='inicio';
var first=true;

$(document).ready(function(){
	$("#menu").delegate('a', 'click', openContentOnClick);
	$("#logo").delegate('a', 'click', openContentOnClick);
	$('#menu #equipamientos').unbind('click');
	
	openContent(selectedId);
})

function openContentOnClick() {
	$(this).blur();
	var idContent;
	var info = $(this).attr('href').split('#')[1];
	var arrayParam = new Object();
	if(info.indexOf('|')>0){
		arrayParam.filter = info.split('|')[1];
		info = info.split('|')[0]; 
	}
	idContent = info;

	if(idContent!=''){
		openContent(idContent, arrayParam);
	}
	return false;
}

function openContent(idContent,params, mensajeStr) {

	var realName = idContent; 
	if ( params === undefined ) {
		realName = idContent;
	} else {
		if ( params.filter != undefined ) {
			realName = idContent + '.' + params.filter;
		}
	}

	if ((selectedId!=realName) || (first==true) ) {
		
		selectedId = realName;
		first=false;
		
		//Cambia contenido
		$("#content").fadeOut(100, function(){
			
		   if ( params === undefined ) {
			   queryString = '';
		   } else {
			   queryString = '?';
				for(var colname in params) {
					queryString=queryString+colname+'='+params[colname]+'&';
				}
				queryString=queryString.substring(0, queryString.length-1);
		   }
		   $('html, body').animate({scrollTop:0}, 'fast');
		   $("#content").load("content/"+idContent+".php"+queryString,{mensaje: mensajeStr}, function() {
			   $("#content").fadeIn(100);
		   });
		});
	}
	
	return false; //to prevent browser from loading the single HTML fragment
}

function consultar(mensaje) {
	val= new Array();
	openContent('Contacto',val,mensaje);
}

