/**
 * @author Kim
 */

//definim variable idioma
var idiomaWeb=""
//funcions de càrrega a l'inici
	$(document).ready(function(){
		
		idioma("es");
	});
	
//funció per a gestionar el canvi d'idioma
function idioma(lang)
{
	idiomaWeb=lang;
	switch (lang)
	{
	 case "es":	 
	 {
	 	seccions('stage','php/contingut/inicio.php');
		location.href="#inicio";
	 }
	 seccions('header','php/seccions/headeres.php'); 
	 seccions('down_header','php/seccions/down_header.php');
	 seccions('menu_empresa','php/seccions/menu_empresaesp.php');
	 seccions('menu_producte','php/seccions/menu_producto.php');
	 seccions('footer','php/seccions/footeres.php');
	
	 break;
	 case "cat"	:	
	{
	 	seccions('stage','php/contingut/inici.php');
		location.href="#inici";
	 } 
	 seccions('header','php/seccions/headercat.php');
	 seccions('down_header','php/seccions/down_header.php');
	 seccions('menu_empresa','php/seccions/menu_empresa.php');
	 seccions('menu_producte','php/seccions/menu_producte.php');
	 seccions('footer','php/seccions/footercat.php');
	 
	  
     	 break;
	 case "eng"	:	
	 {
	 	seccions('stage','php/contingut/home.php');
		location.href="#home";
	 } 
	 seccions('header','php/seccions/headereng.php');
	 seccions('down_header','php/seccions/down_header.php');
	 seccions('menu_empresa','php/seccions/menu_empresaeng.php');
	 seccions('menu_producte','php/seccions/menu_productoeng.php');
	 seccions('footer','php/seccions/footereng.php');
	 
	 break;
	 default:
	
	 break;
	}
}


	
		
//funcio per a resetejar formularis [$('#formulari').reset();]
	jQuery.fn.reset = function(){
		$(this).each(function(){
			this.reset();
		});
	}

	
	//funcio de navegacio principal
	function seccions(div, pag)
	{
		divdesti ="#"+div;
		$(divdesti).load(pag);
	}
 
 /*
 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){
			//alert(historyHash);
			aux = historyHash.split("?");			
			//alert(aux[1]);
			seccions('stage',"php/contingut/"+ aux[0] +".php?"+ aux[1]);
		} else {
			seccions('stage',"php/contingut/inicio.php");			
		}
	};
	// 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 MaivisaNav;