window.addEvent('domready', function() {
	var services = new Fx.Slide('slides-main', {mode: 'horizontal'});
	$('slides-wrap').$$restoreMe = function(){ //We call this to return to normal page!
		services.slideIn();
		//Slide all active slides out!
		$$('.slides .slide', '.slides .slide .subslide').each(function(other,i){
			other.$$slide.slideOut();
		});
		$$('.slides .slide').each(function(other,i){
			other.$$currentSlide = 0;
		});
	}
	
	// Close slide Link
	$$('.close-slide').each(function(other){
		other.addEvent("click", function(){
			$('slides-wrap').$$restoreMe();
		});
	});
	
	// Links
	$('link-1').addEvent('click', function(e){
		services.slideOut();
		$('slide-1').$$slide.slideIn();
		$('slide-1').$$currentSlide = 0;
		$('slide-1').getElements('.subslide')[$('slide-1').$$currentSlide].$$slide.show();
	});
	
	$('link-2').addEvent('click', function(e){
		services.slideOut();
		$('slide-1').$$slide.slideIn();
		$('slide-1').$$currentSlide = 1;
		$('slide-1').getElements('.subslide')[$('slide-1').$$currentSlide].$$slide.show();
	});
	
	$('link-3').addEvent('click', function(e){
		services.slideOut();
		$('slide-1').$$slide.slideIn();
		$('slide-1').$$currentSlide = 2;
		$('slide-1').getElements('.subslide')[$('slide-1').$$currentSlide].$$slide.show();
	});
	
	$('link-4').addEvent('click', function(e){
		services.slideOut();
		$('slide-1').$$slide.slideIn();
		$('slide-1').$$currentSlide = 3;
		$('slide-1').getElements('.subslide')[$('slide-1').$$currentSlide].$$slide.show();
	});
	
	// Functions (Do not edit)
	$$('.slides .slide').each(function(other,i){
		other.setStyles({
			top: 0,
			left: 0,
			"z-index": 0
		});
		other.$$slide = new Fx.Slide(other, {mode: 'horizontal'});
		other.$$slide.hide();
		other.$$nextSlide = function(){
			$(this).getElements('.subslide')[this.$$currentSlide].$$slide.slideOut();
			this.$$currentSlide++;
			$(this).getElements('.subslide')[this.$$currentSlide].$$slide.slideIn();
		}
		other.$$previousSlide = function(){
			$(this).getElements('.subslide')[this.$$currentSlide].$$slide.slideOut();
			this.$$currentSlide--;
			$(this).getElements('.subslide')[this.$$currentSlide].$$slide.slideIn();
		}
		other.$$currentSlide = 0;
		
		//Within each major slide, we have subslides, which have next/previous buttons.
		//These are intitiated here so they know which major slide to control!
		other.getElements('.previous').each(function (button){
			button.$$majorholder = other;
			$(button).addEvent("click", function(){
				this.$$majorholder.$$previousSlide();
			});
		});
		other.getElements('.next').each(function (button){
			button.$$majorholder = other;
			button.addEvent("click", function(){
				this.$$majorholder.$$nextSlide();
			});
		});
	});
	$$('.slides .slide .subslide').each(function(other,i){
		other.setStyles({
			position: "absolute",
			top: 0,
			left: 0,
			"z-index": 9999
		});
		other.$$slide = new Fx.Slide(other, {mode: 'vertical'});
		other.$$slide.hide();
	});
});
