
window.addEvent('domready', function() {
		var contentPos = "show";
		var contenthight;
		var sidebarheight;
		var picturexy;
		var imagewidth;
		var myTimer;
		var homePanel1FX = $("homePanel1");
		var homePanel2FX = $("homePanel2");
		var homePanel3FX = $("homePanel3");
		var homePanel4FX = $("homePanel4");
		var homePanel5FX = $("homePanel5");
		var activePanelFX = homePanel1FX;
		var activecontroller = $("home11");
		contentheight=$("content").getStyle("height");
		sidebarheight=$("sidebar").getStyle("height");
		
		var contentfx = new Fx.Tween("content");
		var sidebarfx = new Fx.Tween("sidebar");
		var scrolled = "left";
		var speed=0;
		var scroll
		$("revive").style.opacity = 0;
		
		start();
		
		function startmoving(){
			imagewidth=$("backgroundjs").getWidth();
			divWidth=$("bigImg").getWidth();
			if(imagewidth<divWidth){
				imagewidth=divWidth
			}
			speed = imagewidth/0.05;
			
			scroll = new Fx.Scroll('bigImg', {
					wait: 1000,
					duration: speed,
					//offset: {'x': -200, 'y': -50},
					transition:Fx.Transitions.linear
			});
			
			$('botFade').style.width = imagewidth+"px";
			$('topShado').style.width = imagewidth+"px";
			if(scrolled=="left"){
				scroll.toRight().chain(function(){
						scrolled = "right";
						startmoving();
				});
			}
			else if(scrolled=="right"){
				scroll.toLeft().chain(function(){
						scrolled = "left";
						startmoving();
				});
			}
			
		}
		
		$("content-slider").addEvent("click", function(e) {
				new Event(e).stop();
				
				if(contentPos=="show"){
					
					
					contentfx.start("opacity",0).chain(function(){
							this.start("height","1px");
					});
					sidebarfx.start("opacity",0).chain(function(){
							this.start("height","1px");
					});
					$("revive").style.opacity = 1;
					contentPos="hide";
					startmoving();
				}
		});	
		
		
		$("sidebar-slider").addEvent("click", function(e) {
				new Event(e).stop();
				if(contentPos=="show"){
					contentfx.start("opacity",0).chain(function(){
							this.start("height","1px");
					});
					sidebarfx.start("opacity",0).chain(function(){
							this.start("height","1px");
					});
					$("revive").style.opacity = 1;
					contentPos="hide";
					startmoving();
				}
		});	
		
		$("revive").addEvent("click", function(e) {
				new Event(e).stop();
				contentfx.start("height",contentheight+"px").chain(function(){
						this.start("opacity",1);
				});
				sidebarfx.start("height",sidebarheight+"px").chain(function(){
						this.start("opacity",1);
				});
				$("revive").style.opacity = 0;
				contentPos="show";
				scroll.pause();
		});	
		
		function changepanel(){
			var showPanelFX;
			var showcontroller;
			
			switch(activePanelFX){
			case homePanel1FX	: showPanelFX=homePanel2FX;showcontroller=$("home22");	break;
			case homePanel2FX	: showPanelFX=homePanel3FX;showcontroller=$("home33");	break;
			case homePanel3FX	: showPanelFX=homePanel4FX;showcontroller=$("home44");	break;
			case homePanel4FX	: showPanelFX=homePanel5FX;showcontroller=$("home55");	break;
			case homePanel5FX	: showPanelFX=homePanel1FX;showcontroller=$("home11");	break;
			}
			showcontroller.className ="active";
			activecontroller.className = "";
			activecontroller=showcontroller;
			showPanelFX.style.display="block";
			activePanelFX.style.display="none";
			activePanelFX=showPanelFX;
			start();
		}
		
		function pause(){
			myTimer = $clear(myTimer); //Cancels myFunction.
		}
		
		function switcher(showPanelFX,controller){
			if(showPanelFX==activePanelFX){
			}else{
				activecontroller.className = "";
				controller.className ="active";
				activecontroller=controller;
				showPanelFX.style.display="block";
				activePanelFX.style.display="none";
				activePanelFX=showPanelFX;
			}
		}
		
		function start(){
			myTimer = changepanel.delay(5000); //Waits 5 seconds then executes myFunction.
		}
		
		$("pause").addEvent("click", function(e) {
				pause();
				new Event(e).stop();
				return false;
		});
		
		$("home1").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel1FX,$("home11"));
		});	
		
		$("home2").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel2FX,$("home22"));
		});	
		
		$("home3").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel3FX,$("home33"));
		});	
		
		$("home4").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel4FX,$("home44"));
		});	
		
		$("home5").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel5FX,$("home55"));
		});	
		
		$("home11").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel1FX,$("home11"));
		});	
		
		$("home22").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel2FX,$("home22"));
		});	
		
		$("home33").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel3FX,$("home33"));
		});	
		
		$("home44").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel4FX,$("home44"));
		});	
		
		$("home55").addEvent("click", function(e) {
				pause()
				new Event(e).stop();
				switcher(homePanel5FX,$("home55"));
		});	
});
