/**
 * @author r
**/
	//funcions.js
	$(document).ready(function(){
	//carreguem els jailaits
	$('#jailaits').load('php/jailaits.php');	
	$('.menu ul li a').mouseover()
	});
	
	//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,function(success){$.scrollTo({top:0})});
	}
		
	function setMenuOp(seccio)
	{
		//pel menu superior
		$('#theme ul li a#'+seccio).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		$('#theme ul li a:not(#'+seccio+')').css({'color':'#000', 'background-color':'#fff', 'text-decoration':'line-through', 'cursor':'default'});
		$('#theme ul li a#'+seccio).mouseover(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		});
		$('#theme ul li a#'+seccio).mouseout(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		});
		$('#theme ul li a:not(#'+seccio+')').mouseover(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none','cursor':'pointer'});
		});
		$('#theme ul li a:not(#'+seccio+')').mouseout(function(){
			$(this).css({'color':'#000', 'background-color':'#fff', 'text-decoration':'line-through','cursor':'pointer'});
		});
		
		//pel menu inferior
		$('#theme2 ul li a#'+seccio).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		$('#theme2 ul li a:not(#'+seccio+')').css({'color':'#000', 'background-color':'#fff', 'text-decoration':'line-through', 'cursor':'default'});
		$('#theme2 ul li a#'+seccio).mouseover(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		});
		$('#theme2 ul li a#'+seccio).mouseout(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none', 'cursor':'default'});
		});
		$('#theme2 ul li a:not(#'+seccio+')').mouseover(function(){
			$(this).css({'color':'#fff', 'background-color':'#000', 'text-decoration':'none','cursor':'pointer'});
		});
		$('#theme2 ul li a:not(#'+seccio+')').mouseout(function(){
			$(this).css({'color':'#000', 'background-color':'#fff', 'text-decoration':'line-through','cursor':'pointer'});
		});
	}

//funcio per a navegació accordion schedule
function initMenu() {
  $('#parrilla ul').hide();
//  $('#parrilla ul:first').show();
  $('#parrilla li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
	  	checkElement.slideUp('normal', function(success){$.scrollTo({top:0})});
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#parrilla ul:visible').slideUp('normal');
        checkElement.slideDown('normal', function(success){$.scrollTo({top:0})});
        return false;
        }
      }
    );
  }
  
 //funcio per a navegació accordion workshops (sense scroll)
function initMenu2() {
  $('#parrilla2 ul').hide();
  $('#parrilla2 li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
	  	checkElement.slideUp('normal');
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#parrilla2 ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
	
/*
 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;