

var navigation = {
							
	inicialize: function(options){
		
		this.options = Object.extend({
			appearDuration: 500,
			repositionDuration: 800,
			repositionTransition: Fx.Transitions.Cubic.easeInOut,
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			container: document.body,
			url: ''
		}, options || {});
		
		
		if ( !window.ie6) {
		
			$A($$('.fan_button')).each(function(el) {
				el.onclick = this.click.pass(el, this);
			}, this);
			
			
			$A($$('.fan_info')).each(function(el) {
				this.setup(el,this);
			}, this);
		
		}
		else {
		
			$A($$('.fan_button')).each(function(el) {
				el.onclick = this.clickIE6.pass(el, this);
			}, this);
			
			
			$A($$('.fan_info')).each(function(el) {
				this.setupIE6(el,this);
			}, this);
			
		}
		
		$A($$('#language_nav a')).each(function(el) {
			el.addEvent('click',function() {$('flash_background').remove();});
		}, this);
		
		$A($$('#menu a')).each(function(el) {
			el.addEvent('click',function() {$('flash_background').remove();});
		}, this);
		
		$A($$('#footer a.section')).each(function(el) {
			el.addEvent('click',function() {$('flash_background').remove();});
		}, this);
		
		$A($$('#press-login-info a')).each(function(el) {
			el.addEvent('click',function() {$('flash_background').remove();});
		}, this);
		
		$('journalist_login').addEvent('submit',function() {
			$('flash_background').remove();
		});
		
		$('customer_login').addEvent('submit',function() {
			$('flash_background').remove();
		});

	},
	
	
	click: function (element) {
		
		this.button = element;
		this.info_box = element.id + '-info';
		
		
		$A($$('.fan_button_current')).each(function(el) {
			el.removeClass('fan_button_current');
		}, this);
		
		element.addClass('fan_button_current');
		
		this.close();

		return false;
		
	},
	
	
	setup: function(element) {
		
		var box_height = element.getStyle('height').toInt();
		var container = element.getParent();

		container.setStyle(
			'display', 'none'
		);

		container.removeClass('no-height');

		element.setStyle(
			'margin-top', -box_height
		);
		
	},
	
	
	open: function() {
		
		//alert('obre' + this.info_box);
		
		if ( $(this.info_box) ) {
			
			var box_height = $(this.info_box).getStyle('height').toInt();
			this.container = $(this.info_box).getParent();

			this.container.setStyle(
				'display', ''
			);

			var makingReady = new Fx.Styles(this.info_box, {
				duration:1000,
				wait:false,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			makingReady.start({
				'margin-top': 0
			});
			
		}
		
	},
	
	
	close: function() {
		
		var margin = $(this.info_box).style.marginTop;
		
		if ( margin == '0px' ) {
		
			//alert('tanca' + this.info_box);
			
			var box_height = $(this.info_box).getStyle('height').toInt();

			var closing = new Fx.Styles(this.info_box, {
				duration:1000,
				wait:false,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			closing.start({
				'margin-top': -box_height
			});
			
			this.button.removeClass('fan_button_current');
		
		}
		else {
		
			this.openClose();
		}
		
	},
	
	
	openClose: function() {
		
		var opened;
		
		$A($$('.fan_info')).each(function(el) {
			var margin = el.style.marginTop;

			if ( margin == '0px' ) {
				opened = el;
			}
		}, this);
		
		if ( opened != null ) {
		
			//alert('tanca' + opened.id);
			
			var box_height = opened.getStyle('height').toInt();

			var closing = new Fx.Styles(opened, {
				duration:1000,
				wait:false,
				transition: Fx.Transitions.Cubic.easeInOut
			});
			closing.start({
				'margin-top': -box_height
			});
			
			this.open();
		
		}
		else {
		
			this.open();
		}
		
	},
	
	
	setupIE6: function(element) {
		
		var container = element.getParent();

		element.setStyle(
			'display', 'none'
		);

		container.removeClass('no-height');
		
	},
	
	
	clickIE6: function (element) {
		
		this.button = element;
		this.info_box = element.id + '-info';
		
		
		$A($$('.fan_button_current')).each(function(el) {
			el.removeClass('fan_button_current');
		}, this);
		
		element.addClass('fan_button_current');
		
		this.closeIE6();

		return false;
		
	},
	
	
	closeIE6: function() {
		
		var displayed = $(this.info_box).style.display;
		
		if ( displayed != 'none' ) {
			
			$(this.info_box).style.display = 'none';
			
			this.button.removeClass('fan_button_current');
		
		}
		else {
		
			this.openCloseIE6();
		}
		
	},
	
	
	openCloseIE6: function() {
		
		var opened;
		
		$A($$('.fan_info')).each(function(el) {
			var displayed = el.style.display;

			if ( displayed == '' ) {
				opened = el;
			}
		}, this);
		
		if ( opened != null ) {
			
			opened.style.display = 'none';
			
			this.openIE6();
		
		}
		else {
		
			this.openIE6();
		}
		
	},
	
	
	openIE6: function() {
		
		if ( $(this.info_box) ) {
			
			$(this.info_box).style.display = '';
			
		}
		
	}
		
};

