var SlidingTabs = new Class({
	options: {
		startingSlide: false, // sets the slide to start on, either an element or an id 
		activeButtonClass: 'current', // class to add to selected button
		activationEvent: 'click', // you can set this to ‘mouseover’ or whatever you like
		wrap: false, // calls to previous() and next() should wrap around?
		slideEffect: { // options for effect used to animate the sliding, see Fx.Base in mootools docs
		duration: 400 // half a second
		},
		animateHeight: false, // animate height of container
		rightOversized: 0 // how much of the next pane to show to the right of the current pane
	},
	current: null, // zero based current pane number, read only
	buttons: false,
	outerSlidesBox: null,
	innerSlidesBox: null,
	panes: null,
	fx: null, // this one animates the scrolling inside
	heightFx: null, // this one animates the height
	
	
	initialize: function(buttonContainer, slideContainer, options) {
		if (buttonContainer) { this.buttons = $(buttonContainer).getChildren(); }
		this.outerSlidesBox = $(slideContainer);
		this.innerSlidesBox = this.outerSlidesBox.getFirst();
		this.panes = this.innerSlidesBox.getChildren();
		
		this.setOptions(options);
		
		this.fx = new Fx.Scroll(this.outerSlidesBox, this.options.slideEffect);
		this.heightFx = this.outerSlidesBox.effect('height', this.options.slideEffect);
		
		// set up button highlight
		this.current = this.options.startingSlide ? this.panes.indexOf($(this.options.startingSlide)) : 0;
		if (this.buttons) { this.buttons[this.current].addClass(this.options.activeButtonClass); }
		
		// add needed stylings
		this.outerSlidesBox.setStyle('overflow', 'hidden');
		this.panes.each(function(pane, index) {
			pane.setStyles({
			 'float': 'left',
			 'width': this.outerSlidesBox.offsetWidth.toInt() - this.options.rightOversized + 'px',
			 'overflow': 'hidden'
		  });
		}.bind(this));
		
		// stupidness to make IE work - it boggles the mind why this has any effect
		// maybe it's something to do with giving it layout?
		this.innerSlidesBox.setStyle('float', 'left');
		
		this.innerSlidesBox.setStyle(
			'width', (this.outerSlidesBox.offsetWidth.toInt() * this.panes.length) + 'px'
		);
		
		if (this.options.startingSlide) this.fx.toElement(this.options.startingSlide);
		
		// add events to the buttons
		if (this.buttons) this.buttons.each( function(button) {
		  button.addEvent(this.options.activationEvent, this.buttonEventHandler.bindWithEvent(this, button));
		}.bind(this));
		
		if (this.options.animateHeight)
		  this.heightFx.set(this.panes[this.current].offsetHeight);
	},
	
	
	changeTo: function(element) {
		var event = { cancel: false, target: $(element) };
		this.fireEvent('change', event);
		if (event.cancel == true) { return; };
		
		if (this.buttons) { this.buttons[this.current].removeClass(this.options.activeButtonClass); };
		this.current = this.panes.indexOf($(event.target));
		if (this.buttons) { this.buttons[this.current].addClass(this.options.activeButtonClass); };
		this.fx.stop();
		this.fx.toElement(event.target);
		if (this.options.animateHeight)
		  this.heightFx.start(this.panes[this.current].offsetHeight);
	},
	
	// Handles a click
	buttonEventHandler: function(event, button) {
		if (event.target == this.buttons[this.current]) return;
		this.changeTo(this.panes[this.buttons.indexOf($(button))]);
	},
	
	next: function() {
		var next = this.current + 1;
		if (next == this.panes.length) {
			if (this.options.wrap == true) { next = 0 } else { return }
		}
		
		this.changeTo(this.panes[next]);
	},
	
	previous: function() {
		var prev = this.current - 1
		if (prev < 0) {
			if (this.options.wrap == true) { prev = this.panes.length - 1 } else { return }
		}
		
		this.changeTo(this.panes[prev]);
	}
});

SlidingTabs.implement(new Options, new Events);

var Site = {
	init: function(){
		Site.makeOptionSlider();
		Site.fontResizer();
		//Site.styleChanger();
		Site.fontChanger();
	},
	start:function(){
		Site.optionsDrop();
	},
	makeOptionSlider:function(){
		//hide the tab so it can animate later
		$('opener').setStyle('marginTop', '-70px');
		var slideOpts = new Fx.Slide('options', {duration: 500, transition:Fx.Transitions.Circ.easeOut});
		slideOpts.hide();
		var moveButton = new Fx.Style('opener','top', {duration: 500, transition:Fx.Transitions.Circ.easeOut});
		var moveTalen = new Fx.Style('languages','top', {duration: 500, transition:Fx.Transitions.Circ.easeOut});
		$('opener').addEvent('click',function(ev){
			new Event(ev).stop();
			slideOpts.toggle();	
			var hoogte = $('options').getStyle('height');
			if($('opener').getStyle('top') == $('options').getStyle('height')){
				moveButton.start(0);
				moveTalen.start(385);
				$('logo').setStyle('display','block');
			}else{
				moveButton.start($('options').getStyle('height'));
				moveTalen.start(484);
		 		$('logo').setStyle('display','none');
			}
		});
	},
	fontChanger:function(){
		//add clicks
		$('changeTrebuchet').addEvent('click', function() {
			Cookie.set("font-family", "trebuchet"); //save this for 1 year
			$('container').setStyle('font-family','"Trebuchet MS", Arial, Helvetica, sans-serif');
		});
		$('changeGeneva').addEvent('click', function() {
			Cookie.set("font-family", "geneva"); //save this for 1 year
			$('container').setStyle('font-family','Geneva, Arial, Helvetica, sans-serif');
		});
		$('changeGeorgia').addEvent('click', function() {
			Cookie.set("font-family", "georgia"); //save this for 1 year
			$('container').setStyle('font-family','Georgia, "Times New Roman", Times, serif');
		});
	
		if(Cookie.get("font-family") == "geneva"){
			$('container').setStyle('font-family','Geneva, Arial, Helvetica, sans-serif');
		}else if(Cookie.get("font-family") == "georgia"){
			$('container').setStyle('font-family','Georgia, "Times New Roman", Times, serif');
		}else{
			//do nothing, leave default
		}
	},
/*	styleChanger:function(){
		//add clicks
		var basepath = 'http://www.paxmedia.nl/hepromij/css/'
		$('cssBlauw').addEvent('click', function() {
			Cookie.set("style", "blue"); //save this for 1 year
			new Asset.css(basepath + 'blauw.css');
		});
		$('cssGroen').addEvent('click', function() {
			Cookie.set("style", "green"); //save this for 1 year
			new Asset.css(basepath +'groen.css');
		});
		$('cssGeel').addEvent('click', function() {
			Cookie.set("style", "yellow"); //save this for 1 year
			new Asset.css(basepath +'geel.css');
		});
		
		if(Cookie.get("style") == "blue"){
			new Asset.css(basepath +'blauw.css');
		}else if(Cookie.get("style") == "yellow"){
			new Asset.css(basepath +'geel.css');
		}else{
			new Asset.css(basepath +'groen.css');
		}
	},*/
	fontResizer:function(){
		//resize the font to different pixel values
		 var resize = new Fx.Style('container', 'font-size', {duration: 1000});
		$('fontLarge').addEvent('click', function() {
			resize.start(13);
			Cookie.set("font-size", "large"); //save this for 1 year
		});
		$('fontMed').addEvent('click', function() {
			resize.start(11);
			Cookie.set("font-size", "medium"); //save this for 1 year
		})
		$('fontSmall').addEvent('click', function() {
			resize.start(9);
			Cookie.set("font-size", "small"); //save this for 1 year
		})
		if(Cookie.get("font-size") == "large"){
			resize.set(13);
		}else if(Cookie.get("font-size") == "small"){
			resize.set(9);
		}else{
			//do nothing, leave default
		}
	},
	optionsDrop: function(){
		dropIn = new Fx.Style('opener', 'marginTop', {
			duration: 300,
			transition: Fx.Transitions.Circ.easeOut,
			wait: true
		});
		//workaround for z-index bug in firefox/mootools
		//and IE6 for not supporting position:fixed;
		if(!window.gecko && !window.ie6){
			$('opener').setStyle('position','fixed');
			$('options').setStyle('position','fixed');
		}
		dropIn.start.delay(1500, dropIn, 0);
	}
};
window.addEvent('domready', Site.init);
window.addEvent('load', Site.start);