/**
 * @author r
 **/
//inicialitzem variable global d'idoma actual
var langAct;
//funcio que checkeja si ha canviat idioma actual (i canvia el menu principal i el banner si cal)
function menuBanner(idiomaWeb){
    if (idiomaWeb != langAct) {
        //carreguem el menu
        $('#main_menu').load('php/menu_' + idiomaWeb + '.php');
        //carreguem banners flash
        $('#banner_flash').load('php/banner_flash_' + idiomaWeb + '.php');
        langAct = idiomaWeb;
    }
}

//funcions.js
$(document).ready(function(){
    //carreguem els jailaits
    //$('#jailaits').load('php/jailaits.php');
    seccions('jailaits', 'php/jailaits.php');
    //construim el background del banner, del banner flash lateral i  del archive
    $(function(){
        $('#banner').add_layer("url('imatges/jais_bg.png') left repeat-y");
        $('#banner').add_layer("url('imatges/jais_top.png') top no-repeat");
        $('#banner').add_layer("url('imatges/jais_peu.png') bottom no-repeat", {
            insideCss: {
                'padding-bottom': '20px',
                'padding': '10px'
            }
        });
        $('#archive').add_layer("url('imatges/jais_bg.png') left repeat-y");
        $('#archive').add_layer("url('imatges/jais_top.png') top no-repeat");
        $('#archive').add_layer("url('imatges/jais_peu.png') bottom no-repeat", {
            insideCss: {
                'padding-bottom': '20px',
                'padding': '10px'
            }
        });
        
    });
    
    //carreguem flash al header
    $('#swf_header').flash({
        src: 'swf/header_offf2010.swf',
        width: 895,
        height: 233
    });
});

//funcions per a gestionar idioma web
function checkLang(idiomaWeb9){

    alert(idiomaWeb);
    alert(idiomaWeb9);
}

//fr=>en
function Toen(pag){


    switch (pag) {
        case "news_fr":
            nPag = "#news";
            location.href = (nPag);
            break;
        case "a_propos":
            nPag = "#about";
            location.href = (nPag);
            break;
        case "espaces":
            nPag = "#contents";
            location.href = (nPag);
            break;
        case "artistes":
            nPag = "#artists";
            location.href = (nPag);
            break;
        case "catalogue_fr":
            nPag = "#catalogue";
            location.href = (nPag);
            break;
        case "programme":
            nPag = "#schedule";
            location.href = (nPag);
            break;
        case "tickets_fr":
            nPag = "#tickets";
            location.href = (nPag);
            break;
        case "lieu":
            nPag = "#venue";
            location.href = (nPag);
            break;
        case "parrainage":
            nPag = "#sponsorship";
            location.href = (nPag);
            break;
        case "ateliers":
            nPag = "#workshops";
            location.href = (nPag);
            break;
        case "presse":
            nPag = "#press";
            location.href = (nPag);
            break;
        default:
            nPag = "#news";
            location.href = (nPag);
            break;
    }
    
}

//en=>fr
function Tofr(pag){

    switch (pag) {
        case "news":
            nPag = "#news_fr";
            location.href = (nPag);
            break;
        case "about":
            nPag = "#a_propos";
            location.href = (nPag);
            break;
        case "contents":
            nPag = "#espaces";
            location.href = (nPag);
            break;
        case "artists":
            nPag = "#artistes";
            location.href = (nPag);
            break;
        case "catalogue":
            nPag = "#catalogue_fr";
            location.href = (nPag);
            break;
        case "schedule":
            nPag = "#programme";
            location.href = (nPag);
            break;
        case "tickets":
            nPag = "#tickets_fr";
            location.href = (nPag);
            break;
        case "venue":
            nPag = "#lieu";
            location.href = (nPag);
            break;
        case "sponsorship":
            nPag = "#parrainage";
            location.href = (nPag);
            break;
        case "press":
            nPag = "#presse";
            location.href = (nPag);
            break;
        default:
            nPag = "#news_fr";
            location.href = (nPag);
            break;
        case "workshops":
            nPag = "#ateliers";
            location.href = (nPag);
            break;
    }
}

//funcio per a resetejar formularis [$('#formulari').reset();]
jQuery.fn.resetForm = function(){
    $(this).each(function(){
        this.reset();
    });
}

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

//funcio per a setejar opció menu i rollOvers
function setMenuOp(seccio){

    //pel menu principal
    $('#main_menu li a#' + seccio + ' img').css({
        'background-position': 'bottom',
        'cursor': 'default'
    });
    $('#main_menu li a:not(#' + seccio + ') img').css({
        'background-position': 'top'
    
    });
    $('#main_menu li a#' + seccio + ' img').mouseover(function(){
        $(this).css({
            'background-position': 'bottom',
            'cursor': 'default'
        });
    });
    $('#main_menu li a#' + seccio + ' img').mouseout(function(){
        $(this).css({
            'background-position': 'bottom',
            'cursor': 'default'
        });
    });
    $('#main_menu li a:not(#' + seccio + ') img').mouseover(function(){
        $(this).css({
            'background-position': 'bottom'
        
        });
    });
    $('#main_menu li a:not(#' + seccio + ') img').mouseout(function(){
        $(this).css({
            'background-position': 'top'
        
        });
    });
}

/*
 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) {
            seccions('stage', "php/" + historyHash + ".php");
        }
        else {
            seccions('stage', "php/news.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 OFFFNav;
