
(function(){
	
	
	
	
	var TabBox = this.TabBox = new Class({
		
		
		Implements: [Events],
		
		
		current: undefined,
		
		
		initialize: function( element ){
			
			this.element = element;
			
			this.arrangeElements();
			
			this.attachEvents();
			
		},
		
		
		arrangeElements: function(){
			
			
			this.element.addClass('tabbed');
			this.element.removeClass('tabs-fallback');
			
			var items = this.element.getChildren('li');
			
			this.current = items[0];
			
			var offset = this.current.getFirst('.tab').getSize().x;
			
			
			for( var i = 1 , length = items.length ; i < length ; i++ ){
				
				var tab = items[i].getFirst('.tab');
				
				tab.setStyle( 'left' , offset );
				
				offset += tab.getSize().x;  
				
			}
			
			this.element.setStyle('opacity', 1);
		},
		
		attachEvents: function(){
			
			var that = this;
		
			this.element.addEvents({
				
				
				'click:relay(.tab)' : function(e){
					
					
					that.current.removeClass( 'active' );
					that.current = this.getParent();
					that.current.addClass('active');

				}
				
			});
			
		}
		
		
	});
	
	var menu = $('menu');
	
	if ( menu ){
		
		menu.addEvents({
			
			
			'mouseenter:relay(li.multilevel)': function(e){
				
				this.addClass('clicked');
				
			},
			'mouseleave:relay(li.multilevel)': function(e){
				
				this.removeClass('clicked');
				
			}
			
			
		});
		
	}
	
	
	var tabs = $('tabbox');
	
	if ( tabs){
				
		var service_tabs = new TabBox( tabs ); 
		
	}

	
	
	var bubble = $('bounce');
	var widget = $('widget');
	
	if ( bubble ){
		
		
		
		var bubble_parent = bubble.getParent(); 


		bubble_parent.active = bubble;
		
		var bounce = function(){
						
			if ( this.hold ){ return }
			
			var effect = new Fx.Tween( this , {property: 'top' ,  duration: 'short', transition: 'linear'});
			effect.start(10,0).chain(
			    function(){ this.start(0,10); }
			);


		}
		
		
		widget.addEvents({
			
			'mouseenter:relay(li)': function(e){
				this.removeClass('inactive');
				bubble_parent.active.addClass('inactive');
				bubble_parent.active = this;
			},
				
			'mouseenter': function(e){
				bubble.hold = true;
			},
			'mouseleave': function(e){
				bubble_parent.active.addClass('inactive');
				bubble_parent.active = bubble;
				bubble.removeClass('inactive');
				bubble.hold = false;
			}
			
		});
		
		
		bounce.periodical( 1000 , bubble );
		
	}else{
		
		if ( widget ){
		
			var lib = {
				
				
				
				toggle: (function(){
					
					var active = null;
					
					return function( item ){
					
						if ( active !== null ){
							
							active.toggleClass('inactive');
						}
						
						if ( item !== null ){
							item.toggleClass('inactive');
						}
	
						active = item;
					
					};
					
				})()
				
			} 
			
			widget.addEvents({
				
				'mouseenter:relay(li)': function(e){
					lib.toggle( this );
				},
				
				'mouseleave': function(){
					lib.toggle( null );
				}
					
				
			});
			
		}
		
	}
	
	
	document.addEvents({
		
		
		'click:relay(a.external)': function(e){
			
			e.stop();
			
			window.open(this.get('href'));
		}
		
	});
	
	
})();


