var slides = {
	slideSetup:function(){
		if ($('colorblock')) {
			$('colorblock').setStyle('display','none');
		}
		if ($('container')){
			$('container').setStyle('height','505');
		};
		if ($('bottom')){
			/*window.addEvent('keypress', function(event){
				if (event.key=='u') {
					//open up bottom slide
					$('bottom_tab').fireEvent('click');
				};
			});*/
			$('fa_bottom').setStyle('display','none');
			$('bottom_tab').setStyles({
				'visibility':'visible'
			});
			$('bottom').setStyles({
				'height':'44px',
				'position':'absolute',
				'float':'left',
				'margin-top':'0'
			});
			$('othertabinner').setStyles({
				'border-top':'0'
			});
		};
		if ($('side')) {
			/*window.addEvent('keypress', function(event){
				if (event.key=='l') {
					//open right hand slide ie move it left
					$('leftslide').fireEvent('click');
				};
			});*/
			$('fa_side').setStyle('display','none');
			$('side').setStyles({
				'float':'left',
				'position':'absolute',
				'margin-top':'0',
				'height':'503px'
			});
			$('lsc').setStyles({
				'width':'1px',
				'height':'503px',
				'margin':'0'
			});
			$('l_r_arrow').setStyle('display','inline');
			$('slide_b_cont').setStyles({
				'height':'0px'
			});
			$('leftslide').setStyles({
				'display':'inline'
			});
		};

	},
	lrSlide:function(){
		$('leftslide').setStyle('cursor', 'pointer');	
		boundSlide = this.lrSlide.bind(this);
		/*$('leftslide').addEvent('click', function(){
			if (!Browser.Engine.webkit419) {
				slides.lrSlideFunc();
			} else {
				slides.safariLRNoSlide();
			}
		});*/
		if (!Browser.Engine.webkit419) {
			$('leftslide').addEvent('click', this.lrSlideFunc.bind(this));
		} else {
			$('leftslide').addEvent('click', this.safariLRNoSlide.bind(this));
		}
	},
	lrSlideFunc:function(){
		var otherSlide = new Fx.Morph('bottom', {duration:1000, transition: 'quint:out'});
		var mySlide = new Fx.Tween('lsc', {duration:1000, transition: 'quint:out'});			
		if ($('bottom')) {
			y = $('bottom').getSize();
			if (y.y >= 50) {
				otherSlide.start({'height':44, 'top':460}).chain(function(){$('u_d_arrow').fade('in')});
			};
		};
		x = $('lsc').getSize();
		if (x.x < 30) {
			if ($('random_text')) {
				$('random_text').turnOff();
			};
			mySlide.start('width', 570).chain(function(){$('l_r_arrow').fade('out')});
		} else {	
			if ($('random_text')){
				$('random_text').turnOn();
			};
			mySlide.start('width',1).chain(function(){$('l_r_arrow').fade('in')});
		};
	},
	safariLRNoSlide:function(){
		if ($('bottom')) {
			y = $('bottom').getSize();
			if (y.y <= 25) {
				$('bottom').setStyles({'height':44, 'top':460})
			};
		};
		x = $('lsc').getSize();
		if (x.x < 30) {
			$('lsc').setStyle('width', 570)
		} else {	
			$('lsc').setStyle('width', 1)
		};

	},
	udSlide:function(){
		$('bottom_tab').setStyle('cursor','pointer');
		$('bottom_tab').addEvent('click', function(e){
			if (!Browser.Engine.webkit419) {
				slides.udSlideFunc();
			} else {
				slides.safariUDNoSlide();
			}
		});
	},
	udSlideFunc:function(){
		var mySlide = new Fx.Morph('lsc', {duration:1000, link: 'cancel', transition: Fx.Transitions.Quint.easeOut});
		var otherSlide = new Fx.Morph('bottom', {duration:1000, link: 'cancel', transition: Fx.Transitions.Quint.easeOut});
		if ($('lsc')) {
			x = $('lsc').getSize();
			if (x.x > 1) {
				mySlide.start({'width':1}).chain(function(){$('l_r_arrow').fade('in')});
			};
		};
		thisone = $('bottom').getSize();
		if ($('othertabinner').offsetHeight <= 409) {
			var newheight = 409;
			$('othertabinner').setStyle('height','100%');
		} else {
			var newheight = $('othertabinner').offsetHeight + 44;
		};
		if (thisone.y < 50) {
			if ($('random_text')) {
				$('random_text').turnOff();
			};
			otherSlide.start({'top': 45, 'height':newheight + 50}).chain(function(){$('u_d_arrow').fade('out')});
		} else {						
			if ($('random_text')) {
				$('random_text').turnOn();
			};
			otherSlide.start({'height':44,'top':460}).chain(function(){$('u_d_arrow').fade('in')});
		};
		
	},
	safariUDNoSlide:function(){
		$('bottom_tab').setStyle('cursor','pointer');
		$('bottom_tab').addEvent('click', function(){
			if ($('lsc')) {
				x = $('lsc').getSize();
				if (x.x > 1) {
					$('lsc').setStyle('width',1);
				};
			};
			thisone = $('bottom').getSize();
			//if ($('othertabinner').offsetHeight <= 409) {
			//	var newheight = 409;
			//	$('othertabinner').setStyle('height','100%');
			//} else {
				var newheight = $('othertabinner').offsetHeight + 44;
			//};
			if (thisone.y < 50) {
				$('bottom').setStyles({'top': 45, 'height':newheight + 50});
			} else {						
				$('bottom').setStyles({'height':44,'top':460});
			};
		});
		
	},
	res_focus:function(){
		if ($('respond_slide')) {
			//check if it's already open
			
			$$('#respond_slide a').addEvent('focus',function(){
				thisone = $('bottom').getSize();				
				if (thisone.y < 50) {
					$$('#othertabinner a')[0].focus();
					$('bottom_tab').fireEvent('click');
				};
			});
		};
		if ($$('#bottom_tab a')[0]){
			$$('#bottom_tab a')[0].setStyle('display','block');
		};
	},
	openmeb:function(){
		var openme = new Element('img', {
			'id': 'openmeb',
			'src': 'images/click_open_b2.png',
			'styles':{
				'position':'absolute',
				'z-index':'100',
				'opacity':'0',
				'top':'430px',
				'left':'300px'
			}
		});
		openme.inject($('p2'), 'top');
		Browser.fixPNG('openmeb');
		omi = function(){
			$('openmeb').fade('in');
			omo.delay(2000);
		};
		omo = function(){$('openmeb').fade('out');};
		omi.delay(2000);
	},
	pngfixer:function(){
		if($('#bottom_tab')){
			$$('#bottom_tab img').each(function(png){Browser.fixPNG(png)});
			$$('#bottom_tab a img').each(function(png){
				png.addClass('wide');
			});
		}
		if($$('.trm')[1]){
			$$('.trm div.tab img').each(function(png){Browser.fixPNG(png)});
		}
	},
	makepages:function(){
		var morelinkbr = new Element('br');
		var backlinkbr = new Element('br');
		var morelink = new Element('p',{
			'class': 'morelink',
			'id': 'morelink',
			'html': 'More &raquo;',
			'styles':{
				'cursor': 'pointer'
			}
		});
		morelink.inject($('slide_a'));
		morelink.addEvent('click', function(){
			slides.changepages();
		});
		var backlink = new Element('p',{
			'class': 'morelink',
			'id': 'morelink',
			'html': '&laquo; Back',
			'styles':{
				'cursor': 'pointer'
			}
		});
		backlink.inject($('slide_b'));
		backlink.addEvent('click', function(){
			slides.changepages();
		});
	},
	changepages:function(){
		var theop = $('slide_a_cont').getStyle('height');
		if (theop > '1'){
			$('slide_a_cont').setStyle('height',0);
			$('slide_b_cont').setStyle('height',490);
		} else {
			$('slide_a_cont').setStyle('height',490);
			$('slide_b_cont').setStyle('height',0);
		};
	},
	welcomeslides:function(){
		if ($('bottom_3rd')) {
			if (!Browser.Engine.webkit419) {
				var wslide1 = new Fx.Tween($$('.trm')[0], {duration:1000, transition: 'cubic:out'});
				var wslide2 = new Fx.Tween($$('.trm')[1], {duration:1000, transition: 'cubic:out'});
				var wslide3 = new Fx.Tween($$('.trm')[2], {duration:1000, transition: 'cubic:out'});
				(function(){ wslide1.start('top','140px') }).delay(250);
				(function(){ wslide2.start('top','140px') }).delay(500);
				(function(){ wslide3.start('top','140px') }).delay(750);
			
				$$('.trm').each(function(i,v){
					i.setStyle('cursor','pointer');
					i.addEvents({
						'mouseenter': function(){
							for (var x=0; x < $$('.trm div.tab').length; x++) {
								if (x != v){
									$$('.trm')[x].set('tween', {duration:'1000', transition: 'cubic:out'});
									$$('.trm')[x].tween('top','140px');
									$$('.trm div.tab')[x].getElement('img').fade('in');
								};
							};
							$$('.trm')[v].set('tween', {duration:'750', transition:'cubic:out'});
							$$('.trm')[v].tween('top','0px');
							$$('.trm div.tab')[v].getElement('img').fade('out');
						},
						'click': function(){
							document.location.href = $$('.trm div.divtext a')[v].href;
						}
					});
				});
				
				$$('.trm div.tab a').each(function(i,v){
					i.addEvent('focus', function(){
						for (var x=0; x < $$('.trm div.tab').length; x++) {
							if (x != v){
								$$('.trm')[x].set('tween', {duration:'1000', transition: 'cubic:out'});
								$$('.trm')[x].tween('top','140px');
								$$('.trm div.tab')[x].getElement('img').fade('in');
							};
						};
						$$('.trm div.tab a')[v].focus();
						$$('.trm')[v].fireEvent('mouseenter');	
					});
				});
				$$('.trm div.divtext a').each(function(i,v){
					i.addEvent('focus', function(){
						for (var x=0; x < $$('.trm div.tab').length; x++) {
							if (x != v){
								$$('.trm')[x].set('tween', {duration:'1000', transition: 'cubic:out'});
								$$('.trm')[x].tween('top','140px');
								$$('.trm div.tab')[x].getElement('img').fade('in');
							};
						};
						$$('.trm div.tab a')[v].focus();
						$$('.trm')[v].fireEvent('mouseenter');	
					});
				});
				// no need they are already open, so nothing can go wrong
			} else {
			}
		};
	},
	wslide:function(){
	},
	sifrShow:function(){
		if($('flashblock')){
			(function(){$('flashblock').fade('out');}).delay(2000);
		}
	},
	init:function(){
		this.pngfixer();
		this.slideSetup();
		this.res_focus();
		this.welcomeslides();
		this.sifrShow();
	}
}			
