/* DomReady Event fires when all Elements are ready, but not images. */ 
window.addEvent('domready', function() { 
		
	var show_menu = new Fx.Styles('',{duration:500,wait:false});
	
	$$('.show_menu').addEvent('click',function(ev){
		if(ev) ev = new Event(ev).stop();
		$$('.trail_menu').setStyles({'opacity':0,'height':0});
		el = this.getProperty('rel') + '_menu';
		show_menu.element = $(el);
		show_menu.start({'opacity':1,'height':(show_menu.element.getSize().scrollSize.y-46)});
	});
	
	$$('.close_menu').addEvent('click',function(ev){
		if(ev) ev = new Event(ev).stop();
		$$('.trail_menu').setStyles({'opacity':0,'height':0});
	});
		
	$$('.makes_link').each(function(element){
		var element = element;
		element.addEvents({
			'mouseenter':function(ev){ ev = new Event(ev).stop(); element.removeClass('makes_notselected').addClass('makes_isselected'); },
			'mouseleave':function(ev){ ev = new Event(ev).stop(); element.removeClass('makes_isselected').addClass('makes_notselected'); }
		});
	});
	
	
	var scroll_details = new Fx.Scroll('',{duration:500,wait:false,transition: Fx.Transitions.Cubic.easeInOut});
	
	$$('.specs').addEvent('click',function(ev){
		
		if (ev) ev = new Event(ev).stopPropagation();
				
		if($(ev.target).hasClass('specs_link')) {
			el = ev.target.getProperty('id').split('_');
			
			scroll_details.element = $('specs'+el[1]);
			
			scroll_details.toElement(el[0] + '_' + el[1] + '_detail');
		} else {
			return;
		}
		
	});
	
	
	
	
	/*  NAVIGATION OVERLAY & ANIMATION */

	if($('builder_main')) {

			$('builder_main').setStyles({
											'overflow':'hidden',
											'height':250
										});
			
			if(window.ie6)
				overlayurl = '/lib_css/images/elements/type_menu_active.gif';
			else
				overlayurl = '/lib_css/images/elements/type_menu_active.png';
			
			var overlay = new Asset.image(overlayurl,{
					'id':'overlay',
					'class':'overlay',
					onload : function(){
						overlay.setStyles({
							'top':-14,
							'left':-10,
							'height':125,
							'width':100
					 	}).injectTop('type-menu');
					}
				});
						
			var moveOverlay = new Class({
					initialize: function(element){
						this.el = element;
						this.animation = new Fx.Styles(this.el, {wait:false, duration: 500, transition: Fx.Transitions.Cubic.easeInOut});
						//return this;
					},
					go: function(left,top){
						
						this.animation.start({
							'left':left,
							'top':top
						});
					}				
				});		
				
				
			var fadeIt = new Fx.Styles('builder_main',{wait:false,duration:400,transition: Fx.Transitions.Expo.easeOut});
				
			var moveDisplay = new Fx.Scroll('builder_main', {
				wait:false, 
				duration: 1000, 
				transition: Fx.Transitions.Cubic.easeInOut,
				onStart: function() {
					//fadeIt.start({'opacity':.4});
				},
				onComplete: function() {
					//fadeIt.start({'opacity':1});
				}
			});
			
					
								
			$ES('a','type-menu').each(function(e){
				
				moveIt = new moveOverlay(overlay);
				
				e.addEvent('click',function(ev){
					
					ev = new Event(ev).stop();
					
					$clear(timer);
					
					topCorner = e.getTop() - $('type-menu').getTop() - 14;
					leftCorner = e.getLeft() - $('type-menu').getLeft() - 10;
								
					moveIt.go(leftCorner,topCorner);
									
					moveDisplay.toElement( 'display' + e.getProperty('rel') );
							
				}.bind(this));
				
			});
			
			
			
			var myChain = new Chain();
	
			$ES('a','type-menu').each(function(e) { 
				myChain.chain( function(){
					
					topCorner = e.getTop() - $('type-menu').getTop() - 14;
					leftCorner = e.getLeft() - $('type-menu').getLeft() - 10;
								
					moveIt.go(leftCorner,topCorner);
					
					moveDisplay.toElement( 'display' + e.getProperty('rel') );
				}.bind(this));
			});
			
			var runChain = function() { 
				myChain.callChain();
				if (myChain.chains.length == 0) { 
					runChain = $clear(timer); 
				} 
			}
			
			myChain.callChain();
			
			var timer = runChain.periodical(4000);
		}
		
		
		$$('.inventory_link').addEvent('click',function(ev){
			if(ev) ev = new Event(ev).stop();
			this.submit();
		});
	
 });