/**
 * @author r
 */
//inicialitzem variable global d'idoma
var langAct;

$(document).ready(function(){
	var formulari = document.getElementById("search");
	 if (formulari.addEventListener) {
                            formulari.addEventListener("keydown", busca, false);
                        }
                        else 
                            if (formulari.attachEvent) {
                                formulari.attachEvent("onkeydown", busca);
                            }
})

//per a que funcioni el enter al buscador
function busca(evt){
    var elementActiu = document.activeElement.id
    var tecla = evt.which || evt.keyCode;
    if (tecla == 13) {		
       paraula = document.getElementById("search").value;
	   paraula = paraula.replace(" ", "_");
		$('#main_esq').load("phps/buscador.php?paraula="+paraula);
		document.getElementById("search").value="Buscar";
    }
}

//funcio de navegacio principal
function seccions(div, pag){
    divdesti = "#" + div;
    $(divdesti).load(pag);
}

function initWeb(){
    $('#submenu').load('pags/submenu_estruch_cat.html', function(){
        $('#submenu a#sub_estruch_1').removeClass("normal").addClass("activat");
        $('#submenu a#sub_estruch_1').click(function(){
            return false;
        })
        $('#submenu a:not(#sub_estruch_1)').removeClass("activat").addClass("normal");
    });
    $('#main_esq').load("pags/programacio.html");
}

function checkMenuSec(seccio){
    $('#menu_ppal a#btn_' + seccio + '').removeClass("normal").addClass("activat");
    /*$('#menu_ppal a#btn_'+seccio+'.activat').click(function(){
     return false;
     });*/
    $('#menu_ppal a:not(#btn_' + seccio + ')').removeClass("activat").addClass("normal");
    $('#submenu').load("pags/submenu_" + seccio + "_cat.html");
}

/*
 Unfocus History (plugin per a historial navegador)
 */
function PromptMe(){
    // some application vars
    var stateVar = "nothin'", displayDiv = document.getElementById("main_esq");
    
    // 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.historyListener = function(historyHash){
        // update the stateVar
        stateVar = historyHash;
        // update display content
        if (historyHash) {
            if (historyHash == "contacte") {
                seccions('main_esq', "pags/contacte.php");
            } else if (historyHash == "inscripcions") {
                seccions('main_esq', "pags/inscripcions.php");
            }
			 else if(historyHash.substr(0,6) == 'escena'){             
             seccions('main_esq', "pags/fitxa.php?id=" + historyHash);
             }
			 else if(historyHash.substr(0,5) == 'media'){             
             seccions('main_esq', "pags/fitxa.php?id=" + historyHash);
             }
			 else if(historyHash.substr(0,3) == 'nau'){             
             seccions('main_esq', "pags/fitxa.php?id=" + historyHash);
             }
            else {
                seccions('main_esq', "pags/" + historyHash + ".html");
            }
        }
        else {
            initWeb();
        }
    };
    // 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());
};

var LestruchNav;



