/**
 * @author fdqepd
 */
var infoPanels = new Array();
infoPanels[0] = "home";
infoPanels[1] = "home";
infoPanels[2] = "firma";
infoPanels[3] = "miembros";
infoPanels[4] = "oficina";
infoPanels[5] = "contacto";

var menuItems = new Array();

var myQuotes = new Array();
myQuotes[0] = "q0";
myQuotes[1] = "q1";
myQuotes[2] = "q2";
myQuotes[3] = "q3";
myQuotes[4] = "q4";
myQuotes[5] = "q5";

var rndm = 0;
var currentPanel;



// Define colours
var normal='none';
var highlight='#13224A';
function init(){
	$('currentLocation').innerHTML = '';
	for(var i = 0; i < infoPanels.length; ++i){
		if(i>0) {
			$(infoPanels[i]).hide();
		} else {
			Effect.Appear($(infoPanels[i]), { duration: 1, queue:'front'});
			Effect.Appear($(myQuotes[i]), { duration: 0.5, queue:'front'});
			
		}		
	}
	for(var i = 0; i < menuItems.length; ++i){
			$(menuItems[i]).style.background=normal;
			$(menuItems[i]).active = false;
			currentPanel = '';
	}
	// grab all second level headlines and loop over them
	var nav = $('nav')
	var h2s = nav.getElementsByTagName('li');
	for (i=0;i<h2s.length;i++){
		// add the hover function onmouseover and onmouseout
			h2s[i].id = i;
			h2s[i].active = false;
			h2s[i].onmouseover=function(){hover(this);}
			h2s[i].onmouseout=function(){hoverOut(this);}
			h2s[i].onclick=function(){toggleInfo(this.id);}
			menuItems[i] = h2s[i];
		
		
	}
	
	for (i=0;i<myQuotes.length;i++){
		// hide all quotes but 1st
		if(i>0) {
			$(myQuotes[i]).hide();
		}
	}
}


// collapse function, shows and hides the element and sets the highlight
// colour of the headline
function hover(o){
	o.style.background=highlight;
	o.style.cursor='hand';
	o.style.cursor='pointer';
}
function hoverOut(o){
	if(o.id != currentPanel){
		o.style.background=normal;
	}	
}
function toggleInfo(id, o){
	if (!$(menuItems[id]).active){
		$(menuItems[id]).active=true;
		for(var i = 0; i < infoPanels.length; ++i){
			if(i!=id){
				$(menuItems[i]).active=false;
				$(infoPanels[i]).hide();
				$(myQuotes[i]).hide();
				$(menuItems[i]).style.background=normal;
			}		
		}
		
		$('currentLocation').innerHTML = ' .' + infoPanels[id];
		Effect.Appear(infoPanels[id], { duration: 1, queue:'front'});
		Effect.Appear(myQuotes[id], { duration: 0.5, queue:'front'});
		
		currentPanel = id;
		
	}
	
}

function sendData () {
	if ($('frm').name.value=="" || $('frm').dir.value=="" || $('frm').emp.value==""|| $('frm').sub.value==""|| $('frm').tel.value=="" || $('frm').email.value=="" || $('frm').msg.value=="") {
		$('status').innerHTML = "Por favor, complete todos los campos.";
	} else {
		var url = 'process.php';
		var pars = Form.serialize('frm');
		var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
		$('frm').name.value="";
		$('frm').dir.value="";
		$('frm').tel.value="";
		$('frm').sub.value="";
		$('frm').emp.value="";
		$('frm').email.value="";
		$('frm').msg.value="";		
	}
}

function showLoad () {
	$('status').innerHTML = 'Enviando...';
}
function showResponse (originalRequest) {
	var newData = originalRequest.responseText;
	//$('load').style.display = 'none';
	$('status').innerHTML = newData;
}