// JavaScript Document

/*
Variables globales que contienen un array con las url de las imagenes para el slideshow y con el caption de cada una si tiene
*/
var aThumbfilenames = [];
var aDescriptions = [];



var Languages = function(){  
    
    //setting
    var state = 'closed';
    	
    $('changeLanguage').addEvents({
        click: function(){
        	
    	    //change the state
	        state = (state == 'closed') ? 'opened' : 'closed';
            $('ctl00_languages').set('morph', {duration: 300, transition: 'bounce:out'});  
	        $('ctl00_languages').morph('.' + state);
        }
    });
}


//ANTIGUO EFECTO DE NAVEGACION
//var Nav = function(){  
//
//     $$('div#nav ul li').addEvents({
//		mouseenter: function(){
//			this.set('morph', {duration: 700, transition: 'bounce:out'});
//			this.morph({
//				'margin-top': '-10px'
//			});
//		},
//		mouseleave: function(){
//			this.morph({
//				'margin-top': '0px'
//			});
//		}
//	});
//    
//}


var mySlideshow = function(){
	var data = {}	
		
	for(var i=1; i<aThumbfilenames.length; i++){
		data[aThumbfilenames[i]] = {}
		if(aDescriptions[i] != '') data[aThumbfilenames[i]].caption = aDescriptions[i].replace('"','\'')
	}
	
	new Slideshow('slideshow', data, {controller: false, height: 418, hu: 'files/', thumbnails: false, width: 960, delay: 4000});
}
 
 
 
var SlideList = new Class({
initialize: function(menu, options) {
			this.setOptions(this.getOptions(), options);
	
			
			this.menu = menu
			this.current = this.menu.getElement('li.current');
 
			this.menu.getElements('li').each(function(item){
				item.addEvent('mouseenter', function(){ this.moveBg(item); this.deleteAttrTitle(item);}.bind(this));
				item.addEvent('mouseleave', function(){ this.moveBg(this.current); }.bind(this));
				//item.addEvent('click', function(event){ this.clickItem(event, item); }.bind(this));
			}.bind(this));
			
			this.back = new Element('li').addClass('background').adopt(new Element('div').addClass('left')).injectInside(this.menu);
			this.back.fx = new Fx(this.options);
			
			if(this.current) this.setCurrent(this.current);
},
 
 
 
setCurrent: function(el, effect){
			this.back.setStyles({left: (el.offsetLeft)+'px', width: (el.offsetWidth)+'px'});
			(effect) ? this.back.effect('opacity').set(0).start(1) : this.back.setOpacity(1);
			this.current = el;
},
 
 
 
getOptions: function(){
			return {
			transition: Fx.Transitions.sineInOut,
			duration: 500, wait: false,
			onClick: Class.empty
			};
},
 
 
 
clickItem: function(event, item) {
			if(!this.current) this.setCurrent(item, true);
			this.current = item;
			this.options.onClick(new Event(event), item);
},
 
 
 
moveBg: function(element) {
	this.back.set('morph', {duration: 700, transition: Fx.Transitions.Back.easeOut});
	this.back.morph({'left':element.offsetLeft,
				  	'width':element.offsetWidth})
	this.back.fx.start('left', element.offsetLeft)
},



deleteAttrTitle: function(item){
	
	item.getElement('a').removeAttribute('title')
}
});
 
SlideList.implement(new Options);
 
window.addEvent('domready', function(){

	Languages();
	if ($('slideshow')) mySlideshow();
	//Nav();
	//new SlideList($('nav').getElement('ul'), {transition: Fx.Transitions.backOut, duration: 700});




});
