window.addEvent('domready',function(){
	new FontSwitch('fontSwitch',75,10,55,115);
/*
	$$('a.popup').each(function(el) {
		el.addEvent(
			'click',
			function(e) {
				var event = new Event(e);
				var link = el;

				var dimensions = [800,600,1,1,1,1,1];
				if (link.target) {
					dimensions = link.target.substr(3).split('x');
				}
				if (null != openPopup(link.href,link.target,dimensions[0],dimensions[1],dimensions[2],dimensions[3],dimensions[4],dimensions[5],dimensions[6])) {
					event.preventDefault();
					return false;
				}
			}
		);
	});
*/


	window.alt = false;
	window.ak = new Array();

        $$('a').filterByAttribute('accesskey').each(
                function(el) {
                       window.ak[el.getAttribute('accesskey')] = el;
                }
        );

        document.addEvent(
                'keydown',
                function (e) {
                        e = new Event(e);
                        if (window.alt && window.ak[e.key])
                                document.location.replace(window.ak[e.key]);
                        window.alt = e.alt;                        
                }
        );
});



function FontSwitch(el,initialSize,increment,min,max) {
	this.init = function(el,initialSize,increment) {
		this.increment = increment ? increment : 10;
		this.initialSize = initialSize ? initialSize : 100;
		this.min = min ? min : 50;
		this.max = max ? max : 150;
		this.el = $(el);
		
		this.bodyElement = document.getElementsByTagName('body')[0];				
		this.setSize(this.getSize());
		this.setActiveStyleSheet(this.getActiveStyleSheet());
		
		this.el.getElement('a.smaller').addEvent('click',this.smaller.bind(this));		
		this.el.getElement('a.default').addEvent('click',this.defaultSize.bind(this));
		this.el.getElement('a.bigger').addEvent('click',this.bigger.bind(this));
		this.el.getElement('a.normal').addEvent('click',this.normal.bind(this));
		this.el.getElement('a.invert').addEvent('click',this.invert.bind(this));		
	}

			
	this.bigger = function(e) {
		(new Event(e)).preventDefault();
		this.setSize(this.size + this.increment);		
	}
	
	this.smaller = function(e) {
		(new Event(e)).preventDefault();
		this.setSize(this.size - this.increment);
	}

	this.defaultSize = function(e) {
		(new Event(e)).preventDefault();
		this.setSize(this.initialSize);
	}

	this.normal = function(e) {
		(new Event(e)).preventDefault();
		this.setActiveStyleSheet();
	}

	this.invert = function(e) {
		(new Event(e)).preventDefault();
		this.setActiveStyleSheet('Invertierte Farben (weiss auf schwarz)');
	}

	this.setActiveStyleSheet = function(title) {
		$$('link').each(
			function (a) {
				if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
					a.disabled = (a.getAttribute("title") == title) ? false : true;
				}
			}
		);
		Cookie.set('style',title);
	}

	this.getActiveStyleSheet = function() {
		var style = Cookie.get('style');
		return style ? style : '';
	}

	
	this.getSize = function() {
		var size = Cookie.get('fontSize');
		return size ? size : (this.size ? this.size : this.initialSize);
	}

	this.setSize = function(size) {
		size = Math.min(Math.max(size,this.min),this.max);
		this.size = parseInt(size);
		this.bodyElement.style.fontSize = this.size + '%';
		Cookie.set('fontSize',this.size);		
	}
	
	this.init(el,initialSize,increment);	
}




function openPopup(href,target,w,h,status,scrollbars,menubar,location,toolbar) {
	var features = "width="+w+",height="+h+",scrollbars="+(scrollbars?"yes":"no")+",status="+(status?"yes":"no")+",menubar="+(menubar?"yes":"no")+",location="+(location?"yes":"no")+",toolbar="+(toolbar?"yes":"no")+",resizable=yes";
	var theWindow = window.open(href,target,features);
	theWindow.focus();
	return theWindow;
}