var AXIS = new Class({
	Implements: [Options, Events],
	options: {
		periodicalTime: 8000,
		slideTime: 300,
		slideFx: Fx.Transitions.linear,
		
		submenuTime: 200,
		submenuFx: Fx.Transitions.linear,
		
		mainId: 'slideshow',
		menuId: '#slideshow ul li a',
		containerImg: '#slideshow-container div',
		submenuId: 'smenu',
		
		startTop: -250,
		startEnd: 0,
		
		fotoGalleryId: '.e2g'
	},
	initialize: function(options){
		this.slider = '';
		var IE6 = false;
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){var ieversion=new Number(RegExp.$1);if (ieversion>=6) { IE6 = true; } }
		if(IE6==true) {
			var i = new Element('div',{'id':'ie6_banner'}).set('html','<div id="ie6_wrap"><div id="ie6_links"><a href="http://www.mozilla.com/nl" target="_blank"><img src="http://www.wijstoppenook.nl/site/gfx/firefox_small.png" alt="" />Firefox</a><a href="http://www.google.com/chrome" target="_blank"><img src="http://www.wijstoppenook.nl/site/gfx/chrome_small.png" alt="" />Chrome</a><a href="http://www.apple.com/safari" target="_blank"><img src="http://www.wijstoppenook.nl/site/gfx/safari_small.png" alt="" />Safari</a><a href="http://www.opera.com" target="_blank"><img src="http://www.wijstoppenook.nl/site/gfx/opera_small.png" alt="" />Opera</a> </div><h1>U gebruikt een oude versie van Internet Explorer</h1><p>Helaas wordt Internet Explorer 6 niet meer volledig ondersteund op deze website. Wij raden u aan over te schakelen naar een modernere internetbrowser. U kunt natuurlijk kiezen voor <a href="http://www.microsoft.com/ie">Internet Explorer 8</a>. Beter nog kiest u een browser uit het overzicht hiernaast.<br /> Deze browsers zijn veelal sneller en veiliger en voldoen beter aan de webstandaarden.</p></div>');
			i.inject($('header'),'before');
		}
		if($defined($(this.options.mainId)) && $type($(this.options.mainId)) != "object") {
			this.openHeader();
			this.loadHeader();
			this.cycleHeader();
		}
		if($defined($(this.options.submenuId))) {
			this.loadSubmenu();
		}
		if($defined($$(this.options.fotoGalleryId)[0])) {
			this.loadGallery();
		}
		$each($$('#nav li a'), function(a,b) {
			if(a.get('href') == document.location.href) {
				a.addClass('active');
			}
		});
		var o1 = 'odd';
		$each($$('.dir'),function(a,b) {
			a.addClass(o1);
			o1 = (o1 == 'odd')?'even':'odd';
		});
	},
	loadGallery: function() {
		var eld = this;
		eld.caFx = new Array();
		$each($$(eld.options.fotoGalleryId+' div.thumb a div.absoluteOnTop'), function(a,b) {
			var nexElm = a.getNext().getNext();
			eld.caFx[b] = new Fx.Morph(nexElm, {duration:eld.options.submenuTime,transition:eld.options.submenuFx,link:'cancel'});
			a.addEvents({
				'mouseenter':function() {
					eld.caFx[b].start({'height':20});
				},
				'mouseout':function() {
					eld.caFx[b].start({'height':0});
				}
			});
		});
	},
	loadSubmenu: function() {
	/*
		$each($$('#'+this.options.submenuId+' ul#subnav li'),function(a,b) { 
			if(a.getChildren('ul').length > 0) {
				if(a.getChildren('a')[0].get('class') != "active") {
					var ul = a.getChildren('ul');
					ul.setStyle('height',0);
				}
				a.addClass('uitgeklapt');
			}
		});
		var eld = this;
		eld.baFx = new Array();
		eld.baFo = new Array();
		$each($$('#'+this.options.submenuId+' ul#subnav ul li'),function(a,b) { eld.eachSubmenu(a,b,eld,false); });
		$each($$('#'+this.options.submenuId+' ul#subnav li'),function(a,b) { 
			if(a.getParents()[0].get('id') == "subnav") {
				eld.eachSubmenu(a,b,eld,true); 
			}
		});
	*/
	},
	eachSubmenu: function(a,b,eld,c) {
		if(a.getChildren('ul').length > 0) {
			if(a.getChildren('a')[0].get('class') != "active") {
				if(c == true) {
					var ul = a.getChildren('ul');
				} else {
					var ul = a.getChildren('ul');
					var ul2 = ul[0].getParents('ul')[0];
					var ulHeight2 = ul2.getScrollSize();
				}
				var ulHeight = ul.getScrollSize()[0];
				ul.setStyle('height',0);
				
				eld.baFx[b] = new Fx.Morph(ul[0], {duration:eld.options.submenuTime,transition:eld.options.submenuFx});
				if(c == false) {
					var o = b + 1000;
					eld.baFx[o] = new Fx.Morph(ul2, {duration:eld.options.submenuTime,transition:eld.options.submenuFx});
					eld.baFo[o] = ul2.getStyle('height');
				}
				a.addClass('uitklapbaar').addEvents({
					'mouseover': function(e) {
						eld.baFx[b].cancel();
						eld.baFx[b].start({'height':ulHeight.y});
						if(c == false) {
							eld.baFx[o].start({'height':ulHeight2.y});
						}
					},
					'mouseout': function(e) {
						eld.baFx[b].cancel();
						eld.baFx[b].start({'height':0});
						if(c == false) {
							eld.baFx[o].start({'height':eld.baFo[o]});
						}
					}
				});
			} else {
				a.addClass('uitgeklapt');
			}
		}
	},
	openHeader: function() {
		var c = 0;
		var eld = this;
		$each($$(eld.options.containerImg), function(a,b) {
			if(c!=0) {
				a.setStyle('top',eld.options.startTop);
			} else {
				a.addClass('active');
			}
			c++;
		});
	},
	loadHeader: function() {
		var eld = this;
		eld.mouseover = false;
		eld.resetperiod = false;
		$$(eld.options.menuId).addEvents({
			'mouseover': function(e) {
				e.stop();
				eld.gotoSlide(this);
				eld.pauseHeader(true);
			},
			'mouseout':function(e) {
				e.stop();
				eld.pauseHeader(false);
			}
		});
		$(eld.options.mainId).addEvents({
			'mouseover': function() {
				eld.pauseHeader(true);
			},
			'mouseout':function() {
				eld.pauseHeader(false);
			}
		});
		
	},
	pauseHeader: function(e) {
		if(e == true) {
			$clear(this.slider);
		} else {
			this.slider = this.runSlide.periodical(this.options.periodicalTime,null,this);
		}
	},
	cycleHeader: function() {
		this.slider = this.runSlide.periodical(this.options.periodicalTime,null,this);
	},
	runSlide: function(eld) {
		var curElm = $$(eld.options.containerImg+'.active')[0].get('class');
		curElm = curElm.replace("image","").replace(" active","");
		var curElm2 = curElm.toInt();
		curElm2 = curElm2 + 1;
		if(curElm2 == 6) {
			curElm2 = 1;
		}
		eld.gotoSlide($$('.slide'+curElm2)[0]);
	},
	gotoSlide: function(a) {
		var eld = this;
		var curElm = $$(eld.options.containerImg+'.active')[0];
		var aniElm = $$('.'+a.get('class').replace('slide','image'))[0];
		
		if(a.get('class') != aniElm && $defined(aniElm) === true) {
			var gotoSlide = a.get('class').replace("slide","").toInt();
			curElm.setStyle('z-index',90);
			
			if($defined(eld.aFx)) {
				eld.aFx.cancel();
			}

			eld.nFx = new Fx.Morph(curElm, {duration:eld.options.slideTime,transition:eld.options.slideFx});
			eld.nFx.start({'top':eld.options.startTop});
			curElm.removeClass('active');

			eld.aFx = new Fx.Morph($$('.image'+gotoSlide)[0], {duration:eld.options.slideTime,transition:eld.options.slideFx});
			eld.aFx.start({'top':eld.options.startEnd});
			
			$$('.image'+gotoSlide)[0].addClass('active').setStyle('z-index',91);
			$$(eld.options.menuId).removeClass('active');
			a.addClass('active');
			a.mouseout = false;
		}
	}
	
});

