/**
 * @author r
**/

//funcio de navegacio principal
	function seccions(div, pag)
	{
		divdesti ="#"+div;
		$(divdesti).load(pag);
	}

//funcio per a carregar menu principal, depenent idioma
	function carregaMenu(lang)
	{
		$('#menu').load("pags/menu_"+lang+".html");
	}
	
//funcio per a carregar menu d'idioma, depenent idioma
	function carregaMenuIdioma(lang)
	{
		var info;
		switch (lang)
		{
			case "es":
			var info='<a href="javascript:toDe();">Deutsch </a> // <a href="javascript:toEn();"> English</a>';
			break;
			case "en":
			var info='<a href="javascript:toDe();">Deutsch </a> // <a href="javascript:toEs();"> Espa&ntilde;ol</a>';
			break;
			case "de":
			var info='<a href="javascript:toEn();">English </a> // <a href="javascript:toEs();"> Espa&ntilde;ol</a>';
			break;
		}
		$('#idioma').html(info);
	}

//funcions per a canviar d'idioma
	//a alemany
	function toDe()
	{
		//carreguem menu en alemany
		carregaMenu("de");
		//el menu d'dioma
		carregaMenuIdioma("de");
		//la secció principal
		var seccioActual= unFocus.History.getCurrent();
		switch (seccioActual)
		{
			case 'quehacemos':
			seccions('stage','pags/wasmachenwir.php');
			unFocus.History.addHistory('wasmachenwir');
			break;
			case 'whatwedo':
			seccions('stage','pags/wasmachenwir.php');
			unFocus.History.addHistory('wasmachenwir');
			break;
			case 'proyectos':
			seccions('stage','pags/projekte.php');
			unFocus.History.addHistory('projekte');
			break;
			case 'projects':
			seccions('stage','pags/projekte.php');
			unFocus.History.addHistory('projekte');
			break;
			case 'quehacemos':
			seccions('stage','pags/wasmachenwir.php');
			unFocus.History.addHistory('wasmachenwir');
			break;
			case 'contacta':
			seccions('stage','pags/kontakt.php');
			unFocus.History.addHistory('kontakt');
			break;
			case 'contact':
			seccions('stage','pags/kontakt.php');
			unFocus.History.addHistory('kontakt');
			break;
			case 'erescliente':
			seccions('stage','pags/bistdukunde.php');
			unFocus.History.addHistory('bistdukunde');
			break;
			case 'areyouclient':
			seccions('stage','pags/bistdukunde.php');
			unFocus.History.addHistory('bistdukunde');
			break;
			default:
			seccions('stage','pags/index_de.php');
			break;
		}
	}
	//a anglès
	function toEn()
	{
		//carreguem menu en anglès
		carregaMenu("en");
		//el menu d'dioma
		carregaMenuIdioma("en");
		//la secció principal
		var seccioActual= unFocus.History.getCurrent();
			switch (seccioActual)
		{
			case 'quehacemos':
			seccions('stage','pags/whatwedo.php');
			unFocus.History.addHistory('whatwedo');
			break;
			case 'wasmachenwir':
			seccions('stage','pags/whatwedo.php');
			unFocus.History.addHistory('whatwedo');
			break;
			case 'proyectos':
			seccions('stage','pags/projects.php');
			unFocus.History.addHistory('projects');
			break;
			case 'projekte':
			seccions('stage','pags/projects.php');
			unFocus.History.addHistory('projects');
			break;
			case 'contacta':
			seccions('stage','pags/contact.php');
			unFocus.History.addHistory('contact');
			break;
			case 'kontakt':
			seccions('stage','pags/contact.php');
			unFocus.History.addHistory('contact');
			break;
			case 'erescliente':
			seccions('stage','pags/areyouclient.php');
			unFocus.History.addHistory('areyouclient');
			break;
			case 'bistdukunde':
			seccions('stage','pags/areyouclient.php');
			unFocus.History.addHistory('areyouclient');
			break;
			default:
			seccions('stage','pags/index_en.php');
			break;
		}
	}
	//a castellà
	function toEs()
	{
		//carreguem menu en castellà
		carregaMenu("es");
		//el menu d'dioma
		carregaMenuIdioma("es");
		//la secció principal
		var seccioActual= unFocus.History.getCurrent();
			switch (seccioActual)
		{
			case 'whatwedo':
			seccions('stage','pags/quehacemos.php');
			unFocus.History.addHistory('quehacemos');
			break;
			case 'wasmachenwir':
			seccions('stage','pags/quehacemos.php');
			unFocus.History.addHistory('quehacemos');
			break;
			case 'projects':
			seccions('stage','pags/proyectos.php');
			unFocus.History.addHistory('proyectos');
			break;
			case 'projekte':
			seccions('stage','pags/proyectos.php');
			unFocus.History.addHistory('proyectos');
			break;
			case 'contact':
			seccions('stage','pags/contacta.php');
			unFocus.History.addHistory('contacta');
			break;
			case 'kontakt':
			seccions('stage','pags/contacta.php');
			unFocus.History.addHistory('contacta');
			break;
			case 'bistdukunde':
			seccions('stage','pags/erescliente.php');
			unFocus.History.addHistory('erescliente');
			break;
			
			case 'areyouclient':
			seccions('stage','pags/erescliente.php');
			unFocus.History.addHistory('erescliente');
			break;
			
			default:
			seccions('stage','pags/index_es.php');
			break;
		}
	}
/*
 Unfocus History (plugin per a historial navegador)
 */

function PromptMe() {
	// some application vars
	var stateVar = "nothin'", displayDiv = document.getElementById("stage");
	
	// the sole public method to manipulate this application
	this.promtForNew = function() {
		// do the stuff that changes the state
		var newVal = window.prompt("Please enter some value to store in the history and url");
		// Set the new history hash. This value must be a string, so serializtion is up to you.
		// JSON works nicely, if you need something quick: http://www.json.org
		// When a new entry is made, unFocus.History will notify the historyListener 
		// method of the change, even on the first call. For this demo app we can 
		// rely on the historyListener method to update the state, and view.
		unFocus.History.addHistory(newVal);
	};
	
	// This is the method that will recieve notifications from the History Keeper,
	// which will then update the state of the app.
	// :NOTE: This will be called when a new entry is added.
	// :NOTE: This will be called if another app on the page sets a history,
	//        so you will need to watch out for this, if you have more than
	//        one script using the history keeper, by doing some kind of 
	//        check to make sure that the new hash belongs to this app.
	//        I wouldn't expect this to be a problem all that frequently.
	this.historyListener = function(historyHash) {
		// update the stateVar
		stateVar = historyHash;
		// update display content
		if(historyHash)
		{
			if(historyHash=="de"){
				toDe();
			}
			seccions('stage',"pags/"+ historyHash+".php");
		} else {
			seccions('stage',"pags/index_es.php");			
		}
		// update document title
		//document.title = "OFFF Oeiras'09 . 7, 8, 9 May 2009 · Facely";
		
	};
	// subscribe to unFocus.History
	unFocus.History.addEventListener('historyChange', this.historyListener);
	
	// Check for an initial value (deep link).
	// In this demo app, the historyListener can handle the task.
	this.historyListener(unFocus.History.getCurrent());
};
// instantiate and inialize the app. DOM has to be ready so we can get a ref to
// the HistoryState DOM element (aka the view), so we use QuickLoader to make
// sure it's ready.
var CuantofaltaNav;