// JavaScript Document
/* = EFECTO LOGO
--------------------------------------------------------------- 
*/
logoEffect = function(){
	var myEffect = new Fx.Morph('effectLogo', {duration: 1500, transition: Fx.Transitions.Sine.easeOut,link: 'cancel'});	
	myEffect.set({'opacity':'0'});
	
		 $('logo').getElement('a').addEvents({
			mouseenter: function(){
				myEffect.start({'opacity': [0,1]})
				
			},
			mouseleave: function(){
				myEffect.start({'opacity': [0]})
			}
		});
}
/* END EFECTO LOGO
--------------------------------------------------------------- */
/* = LAVALAMP
--------------------------------------------------------------- 
*/
activeLavalamp = function(){
	if(location.href.match(/contact/))	{							 
		$('navItem0').removeClass('current')									 
		$('navItem5').addClass('current')
	}
	new Lavalamp($('nav').getElement('ul'), {transition: Fx.Transitions.backOut, duration: 700});
}
/* END LAVALAMP
--------------------------------------------------------------- */

onPageLoad_EntryMap = function(){
		var myEffects = new Fx.Morph('mapa', {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
		myEffects.start({'right': [-1000, 0]});

}

init = function(){
	
	$('wrapper_logo').setStyle('top','-1000px');
	$('footer').setStyle('opacity','0');
	setTimeout("onLoadPageEntryLogo()", 1200 )

}

/*--------------------------------------------------------------------------------------------------------------
*/


onPageLoad_MoveCredits = function(){
	
	var creditMove = new Fx.Morph('footer', {duration: 7000, transition: Fx.Transitions.Sine.easeOut});
	creditMove.start({'opacity': [0, 1]});	
		
}
/*--------------------------------------------------------------------------------------------------------------
*/
/*window.addEvent('domready', function() {
	var accordion = new Accordion($$('.toggler'),$$('.element'), {
		opacity: 0,
		onActive: function(toggler) { toggler.setStyle('color', '#ff3300'); },
		onBackground: function(toggler) { toggler.setStyle('color', '#000000'); }
	});
});*/
	
/* = ACORDEON SECONDARYNAV
--------------------------------------------------------------- 
*/
var acordeonSecondaryNav    = {}
acordeonSecondaryNav.active = false;
acordeonSecondaryNav.show   = 30000;

acordeonSecondaryNav.init = function(_show){
	var link_toggles = $$('.toggler');
	link_toggles.addEvent('click', function(e){ e.stop(); })
	new Accordion(link_toggles, $$('.contenido'),{
		show: _show,								
		display: 1
	});
}
/* END ACORDEON SECONDARYNAV
--------------------------------------------------------------- */
onMouseOver_MoveRepresentates = function(){
	$('linkToRepresentantes').getElements('a').each(function(el, index){
		 el.set('morph', {link : 'cancel'}); 
		 el.addEvents({ 
			 'mouseenter': function() { 
				 el.morph({ 
					 'padding-left' : '15px'
				 }); 
			 }, 
			 'mouseleave' : function() { 
				 el.morph({ 
					 'paddingLeft' : '0px'
				 });  
			 }     
		});	
	});
}// end onMouseOver_MoveRepresentates


/* = FANCY_MENU BY AARON
--------------------------------------------------------------- 
*/
//Imprescindible poner en el span la propiedad visibility:visible !important;
onMouseOverFancyMenu = function(){
	$each($$('.fade'), function(span) {

		var myEffect = new Fx.Morph(span, {duration: 800, transition: Fx.Transitions.Sine.easeOut, link:'cancel'});	
		myEffect.set({'opacity':'0'});
		//var effectHeader = new Fx.Morph('headerBG', {duration: 800, transition: Fx.Transitions.Sine.easeOut,link: 'cancel'});	
		//effectHeader.set({'opacity':'0'});
		
		
		 span.addEvents({
			mouseenter: function(){
				myEffect.start({'opacity': [0,1]})
				//effectHeader.start({'opacity': [0,1]})
				
			},
			mouseleave: function(){
				myEffect.start({'opacity': [0]})
				//effectHeader.start({'opacity': [0]})
			}
		});
	});	
}// end MouseOverFancyMenu
/* END FANCY_MENU BY AARON
--------------------------------------------------------------- 
*/

/* = ACORDEON SITEMAP
--------------------------------------------------------------- 
*/
var AcordeonSiteMap = function(_show){
	var link_toggles = $$('.siteMap').getElements('li.sitemap_level_0');
	var links = link_toggles[0].getElement('a')
	links.addEvent('click', function(e){e.stop()})
	
	//var s=''; for(a in links[0]){s+=a+' -'};alert(s);
		link_toggles.each(function(item2, i){
		item2.getElement('ul').each(function(item, index){
			if(!item){
			var ul = Element('ul').appendText(' ')
			ul.injectInside(link_toggles[0][index])
			}
		});					   

	var content = $$('.siteMap').getElements('ul');
	
		new Accordion(links, content,{
			show: 0,								
			display: 1
		});
	});
}
/* END ACORDEON SITEMAP
--------------------------------------------------------------- */	

onLoadPageEntryLogo = function(){
	//for(a in $('logo').setStyle){s+=a+' - '}alert($('logo').setStyle)
	var logoDown = new Fx.Morph('wrapper_logo', {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
	logoDown.start({'top': [-500, 0]}).addEvent('onComplete', onPageLoad_MoveCredits);	
}
/* = CARGA LA PAGINA 
--------------------------------------------------------------- */
window.addEvent('domready', function(){
	if(location.href.match(/sitemap/) || location.href.match(/legal/)){
		$('navItem0').addClass('current')
	}
									 
	if(location.href.match(/sitemap/)){
		AcordeonSiteMap()
	}									 
	
	
	if(location.href.match(/index/))
	init();

	logoEffect();
	if($('mapa')) onPageLoad_EntryMap();


	
	onMouseOver_MoveRepresentates();
	onMouseOverFancyMenu();
	//activeLavalamp();
		
	//init acordeon secondaryNav
	//if(acordeonSecondaryNav.active) acordeonSecondaryNav.init(parseInt(acordeonSecondaryNav.show));	
});
