var Futureproofed = new Class({
	Implements: Options,
	
	options: {
		menutrigger : null,
		menuitems: null,
		tags: '#objecttags ul li'
		
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.tags = $$(this.options.tags);
		if(this.tags != null){
			this._inittags();
		}
		this._initmenu();
	},
	
	_initmenu: function(){
		this.options.menuitems= $$(this.options.menutrigger);
		if(this.options.menuitems != null){
			this.options.menuitems.each(function(el){
				if(el.get('id') != "ask_offer")
				{
					var tmp = el.getParent().getNext();
					if(tmp !=null){
						var slide = new Fx.Slide(tmp,{
							duration: 1000,
						    transition: Fx.Transitions.Quart.easeOut 
						}).show();
					}
					el.addEvent('click',function(e){
							e = new Event(e).stop();
							if(tmp != null){
								slide.toggle();
							}
					});
				}
			});
		}
	},
	
	_inittags: function(){
		var search = $('search');
		this.tags.each(function(el){
			el.addEvent('click',function(e){
				var tmpval = e.target.get('html');
				search.value = tmpval.replace(/-/g, "").clean();				
				search.getParent().submit();
			});
		});
	}
});

var FutureproofedBanner = new Class({
	Implements: Options,
	
	options:{
		images : '#banner img',
		links: '#banner li a',
		selectedimg : '#banner img.selected',
		selectedlink : '#banner ul li a.selected'
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.images = $$(this.options.images);
		this.links = $$(this.options.links);
		this.selectedimg = $$(this.options.selectedimg);
		this.selectedlink = $$(this.options.selectedlink);
		
		this._initalizeBanner();
	},
	
	_initalizeBanner: function(){
		var _self = this;
		if(this.selectedimg!= ""){
			this.selectedimgid = this.selectedimg.get('id');
		}
		else{
			this.selectedimgid = this.images[0].get('id');
		}
		this.current = 0;

		this.images.each(function(el,index){
			if(el.get('id') != _self.selectedimgid){
				el.setStyle('display','none');
			}
			else{
				_self.current = index;
			}
		});
	
		this.images[this.current].setStyle('display','block');

		if(this.selectedlink != ""){
			this.selectedlink.setStyle('display','block').fade('in');
		}else{
			this.links[0].setStyle('display','block').fade('in');
		}
		
		this.links.each(function(el,index){
			el.set('rel',index);
			el.addEvent('mouseover',function(e){
				e = new Event(e).stop();
				_self.swap(this);
			});
		});
	},
	
	swap: function(el) {
		this.images[this.current].setStyle('display','none').fade('out');
		this.images[el.get('rel')].setStyle('display','block').fade('in');
		this.current = el.get('rel');
	}
});


var FutureTabs = new Class({
	Implements: Options,
	
	options:{
		tabs : '.tabs li',
		container :'.tabcontent'
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		var _self = this;
		this.containers = $$(this.options.container);
		this.tabs = $$(this.options.tabs);
		this.current = 0;
		this.tabs.each(function(el,index){
			if(!el.hasClass('current'))
			{
				_self.containers[index].fade('hide');
			}else
			{
				_self.containers[index].fade('show');
			}
			var _index = index;
		
			el.addEvent('click',function(e){
				e = new Event(e).stop();
				_self.tabs[_self.current].removeClass('current');
				this.addClass('current');
				_self.containers[_self.current].setStyle('display','none').fade('toggle');
				_self.containers[_index].setStyle('display','block').fade(1);
				_self.current = _index; 
			});
		});
		
		
	}
});

var FutureMMBox = new Class({

	Implements: Options,
	
	options:{
		images : '.box04 #objectmedia img',
		controlers :'.table2 ul li',
		imagebox : 'objectmedia',
		left: 'but_left',
		right: 'but_right'
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.images = $$(this.options.images);
		this.controls = $$(this.options.controlers);
		this.leftbtn = $(this.options.left);
		this.rightbtn = $(this.options.right);
		this.current = 0;
		
		this._setUpImages();
		this._setUpControls();
		this.intializeSlideShow();
		
		Milkbox = new Milkbox();
		$('but_fullscreen').addEvent('click',function(e){
			e.stop();
			Milkbox.autoPlay();
		}.bind(this));
	},
	
	_setUpImages: function(){
		this.data = "{";
		this.images.each(function(el,index){
			if(index > 0)
			{
				el.setStyle('display','none');
			}
			if(index >= 1) this.data += ",";
			this.data += "'"+el.src+"'";
			this.data +=":{'caption' : ";
			this.data += "'"+el.alt+"'";
			this.data +="}";
		},this);
		this.data += "}";
		this.data = JSON.decode(this.data);
	},
	
	intializeSlideShow: function(){
		var _self = this;
		this.myShow = new Slideshow(this.options.imagebox, this.data, { 
			captions: false, 
			controller: false, 
			height: 330, 
			width: 480 
			});
		this.myShow.addEvent('moved',function(el){
			_self.controls[_self.current].removeClass('current');
			_self.controls[el].addClass('current');
			_self.current = el;
		});
	},

	_setUpControls: function(){
		var _self= this;
		this.leftbtn.addEvent('click',function(e){
			e = new Event(e).stop();
			_self.myShow.prev();
		});
		this.rightbtn.addEvent('click',function(e){
			e = new Event(e).stop();
			_self.myShow.next();
		});
		this.controls.each(function(el,index){
			var _index = index;
			el.addEvent('click',function(e){
				e = new Event(e).stop();
				_self.myShow.go(_index);
			});
		});
	}
});

var FutureproofedProject = new Class({
	Implements: Options,
	
	options:{
		links : '.actionbox_options li',
		wrapper: 'objectwrapper'
		
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.links = $$(this.options.links);
		this.wrapper = $(this.options.wrapper);
		this.filter = [];
		this.links.each(function(el){
			el.addEvent('click',function(e){
				e.preventDefault();
				if(!this.filter.contains(e.target.get('rel').toUpperCase())){
					this.filter.include(e.target.get('rel').toUpperCase());
					el.removeClass('off').addClass('on');
				}else{
					this.filter.erase(e.target.get('rel').toUpperCase());
					el.removeClass('on').addClass('off');
				}
				this.rebuildGrid(e.target.get('rel').toUpperCase());
			}.bind(this));
		}.bind(this));
	},
	
	rebuildGrid : function(href){
		var upperhref = href.toUpperCase();
		this.wrapper.getElements('.object').each(function(el){
			var tmprel = el.get('rel').toUpperCase();
			var show = false;
			if(tmprel != null && this.filter.length > 0){
				this.filter.each(function(el){
					if(tmprel.contains(el,',')){
						show = true;
						return;
					}
				});
			}else{
				show = true;
			}
			if(show){
				el.fade('in').setStyle('display','block');
			}else
			{
				el.fade('out').retrieve('tween').chain(function(){
					el.setStyle('display','none');
				});
			}
			
		}.bind(this));
	}
});

window.addEvent('domready',function(){
		var sizeopen = 230;
		var sizeclosed = 58;
		var boxes = $$('.site_choice');
		var start = boxes[0];
		var intial = start;
		boxes.each(function(el,i){
			el.set('morph');
			el.getElement('img').set('morph');
			el.addEvent('mouseover',function(e){
				e.stop();
				start.morph({width: sizeclosed});
				start.getElement('img').morph({width: sizeclosed});
				start.setStyle('background-position','bottom left');
				
				el.morph({width: sizeopen});
				el.getElement('img').morph({width: sizeopen});
				el.setStyle('background-position','top left');
				start = el;
			});
		});
		
		$('content').addEvent('mouseover',function(e){	
			if(start != intial)
			{
				start.morph({width: sizeclosed});
				start.setStyle('background-position','bottom left');
				start.getElement('img').morph({width: sizeclosed});
				intial.morph({width: sizeopen});
				intial.setStyle('background-position','top left');
				intial.getElement('img').morph({width: sizeopen});
			}
		});
		$('navbox').addEvent('mouseover',function(e){	
			if(start != intial)
			{
				start.morph({width: sizeclosed});
				start.setStyle('background-position','bottom left');
				start.getElement('img').morph({width: sizeclosed});
				intial.morph({width: sizeopen});
				intial.setStyle('background-position','top left');
				intial.getElement('img').morph({width: sizeopen});
			}
		});
		
});