/**
 * @author Alexander Farkas [trixta] // http://pfirsichmelba.de
 * Enthält addClass, hasClass, removeClass und $ Funktion von prototype,
 * getStyle von quirksmode -> http://www.quirksmode.org/dom/getstyles.html
 * und die Autor-/User-Mode-Detetction
 * 
 */
/*  Prototype JavaScript framework, version 1.4.0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/
/* Entspricht einer weiter gekürzten! Variante von 
 * prototype.lite.js für/von moo.fx (http://moofx.mad4milk.net/)
 */
var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		};
	}
};
Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
};
function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;
	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	};
};
if (!window.Element) var Element = new Object();
Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},
	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	}
});
Array.prototype.iterate = function(func){
	for(var i=0;i<this.length;i++) func(this[i], i);
};
if (!Array.prototype.each) Array.prototype.each = Array.prototype.iterate;
function $c(array){
	var nArray = [];
	for (var i=0;i<array.length;i++) nArray.push(array[i]);
	return nArray;
};
/*
	http://www.quirksmode.org/dom/getstyles.html
*/
function getStyle(el,styleProp)
{
	var x = $(el), y;
	if (x.currentStyle)
		y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
};
function authorUserMode(_settings)
{
	var _settings = _settings || this;
	this.except_safari = _settings.except_safari || false;
	this.pictureurl = _settings.pictureurl || false;
	this.picturewidth = _settings.picturewidth || 1;
	contrastmodeobj = this;
	
	this.picturedisabeld = function(){
		Element.removeClassName(bodyel, 'pictureenabeld');
		Element.addClassName(bodyel, 'picturedisabeld');
	};
	this.pictureenabeld = function(){
		window.clearTimeout(contrastmodeobj._contrastTimeID);
		Element.addClassName(bodyel, 'pictureenabeld');
		Element.removeClassName(bodyel, 'picturedisabeld');
	};
	if(_settings.pictureurl){
		var tmp = new Date();
		_settings.pictureurl = _settings.pictureurl+'?'+tmp.getTime();
		var testpic = new Image();
		testpic.src = _settings.pictureurl;
		testpic.onload = contrastmodeobj.pictureenabeld;
		contrastmodeobj._contrastTimeID = window.setTimeout(contrastmodeobj.picturedisabeld,999);
	}
	
	
	
	var testbg = document.createElement("div"),contrastmode = false;
	testbg.setAttribute('id','userbgtest');
	testbg.style.backgroundColor = '#ff0000';
	testbg.style.width = '10px';
	testbg.style.visibility = 'hidden';
	var bodyel = document.getElementsByTagName('body')[0];
	bodyel.appendChild(testbg);
	var bgcolor = getStyle(testbg,'backgroundColor');
	if(navigator.userAgent.indexOf("Safari") == '-1' || (navigator.userAgent.indexOf("Safari") != '-1' && !_settings.except_safari)){
		if(bgcolor == 'transparent' || (bgcolor != 'rgb(255, 0, 0)' && bgcolor != '#ff0000' && bgcolor != 'red')){
			contrastmode = true;
		}else {
			testbg.style.backgroundColor = '#0000ff';
			bgcolor = getStyle(testbg,'backgroundColor');
			if(bgcolor != 'rgb(0, 0, 255)' && bgcolor != '#0000ff' && bgcolor != 'blue')
				contrastmode = true;			
		}
	}
	if(contrastmode){
		Element.addClassName(bodyel, 'userbg');
		Element.removeClassName(bodyel, 'authorbg');
	}else{
		Element.addClassName(bodyel, 'authorbg');
		Element.removeClassName(bodyel, 'userbg');
	}
	if(getStyle(testbg,'width') == '10px'){
		Element.addClassName(bodyel, 'cssenabeld');
		Element.removeClassName(bodyel, 'cssdisabeld');
	}else{
		Element.addClassName(bodyel, 'cssdisabeld');
		Element.removeClassName(bodyel, 'cssenabeld');
	}
	bodyel.removeChild(testbg);
};