Object.extend(Position, {
	windowGetWidth:function(){
		if(!Prototype.BrowserFeatures.XPath && Prototype.Browser.WebKit ){
			return this.innerWidth;
		}
		if(Prototype.Browser.Opera){
			return document.body.clientWidth;
		}
		//return document.documentElement.clientWidth;
		return document.documentElement.offsetWidth;
	},
	windowGetHeight:function(){
		if(!Prototype.BrowserFeatures.XPath && Prototype.Browser.WebKit){
			return this.innerHeight;
		}
		if(Prototype.Browser.Opera){
			return document.body.clientHeight;
		}
		//return document.documentElement.clientHeight;
		//return document.documentElement.offsetHeight;
		if (Prototype.Browser.IE && !window.XMLHttpRequest) {	// IE 6<=
			return document.documentElement.offsetHeight;
		}
		return document.body.parentNode.clientHeight
	},
	windowGetScrollTop:function() {
		return this.pageYOffset||document.documentElement.scrollTop;
	}
});

var FullScreenBG = Class.create();
FullScreenBG.prototype = {
	bg_element: null,
	ratio: 0,
	img_src: null,
	initialize: function(src) {
		this.img_src = src;
		Event.observe(window, "load", this.createBackground.bindAsEventListener(this));
	},
	createBackground: function() {
		if(this.bg_element===null) {
			this.bg_element = Element.extend(document.createElement("img"));
			this.bg_element.id="FullScreenBGImg";
			this.bg_element.setStyle({ position:"fixed", overflow:"hidden", zIndex:-2, top: "0", left: "0", visibility:"hidden" });
			this.bg_element.src = this.img_src;
			Event.observe( this.bg_element, "load", this.imgInit.bindAsEventListener(this));
			document.body.appendChild(this.bg_element);
			if(Prototype.Browser.IE && !window.XMLHttpRequest) { // IE 6
				this.bg_element.setStyle({position:"absolute", top:Position.windowGetScrollTop()+"px"} );
				Event.observe(window, "scroll", function() {
					this.bg_element.setStyle({top: Position.windowGetScrollTop()+"px"});
				}.bind(this));
			}
		}
	},
	imgInit: function(){
		var w=parseInt(this.bg_element.getStyle("width"),10);
		var h=parseInt(this.bg_element.getStyle("height"),10);
		this.ratio=w/h;
		this.scale();
		this.bg_element.setStyle({visibility:"visible"});
		Event.observe(window, "resize", this.scale.bindAsEventListener(this));
	},
	scale: function() {
		
		var width, height, n_width, n_height, ratio;
		width = Position.windowGetWidth();
		height = Position.windowGetHeight();
		ratio = this.ratio;
		
		if (width/height>ratio){
			n_width=width;
			n_height=Math.round(width/ratio);
		}
		else {
			n_width=Math.round(height*ratio);
			n_height=height;
		}
		//debug("width: "+width+" height: "+height+" ratio: "+ratio);
		//debug("n_width: "+n_width+" n_height: "+n_height);
		this.bg_element.width=n_width;
		this.bg_element.height=n_height;
		var pos= {
			left: Math.round(width/2-n_width/2)+"px",
			top: Math.round(height/2-n_height/2)+"px"
		};
		this.bg_element.setStyle(pos);
	}
}

var FullScreenBG2 = Class.create();
FullScreenBG2.prototype = {
	bg_element: null,
	ratio: 0,
	scaleFactor: 0.6,
	img_src: null,
	initialize: function(src) {
		this.img_src = src;
		Event.observe(window, "load", this.createBackground.bindAsEventListener(this));
	},
	createBackground: function() {
		if(this.bg_element===null) {
			if (Prototype.Browser.IE ) {
				this.bg_element = Element.extend(document.createElement("div"));
				this.bg_element.id="FullScreenBGImg";
				this.bg_element.setStyle({ position:"absolute", overflow:"hidden", zIndex:-1, top: Position.windowGetScrollTop()+"px", left: "0px", visibility:"hidden",
					width: "438px", height: "400px",
					"filter": 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+this.img_src+'",sizingMethod="scale")'
				});
				
				document.body.appendChild(this.bg_element);
				Event.observe(window, "scroll", function() {
					this.bg_element.setStyle({top: Position.windowGetScrollTop()+"px"});
				}.bind(this));
				this.imgInit();
			}
			else {
				this.bg_element = Element.extend(document.createElement("img"));
				this.bg_element.id="FullScreenBGImg";
				this.bg_element.setStyle({ position:"fixed", overflow:"hidden", zIndex:-1, top: "0px", left: "0px", visibility:"hidden" });
				this.bg_element.src = this.img_src;
				Event.observe( this.bg_element, "load", this.imgInit.bindAsEventListener(this));
				document.body.appendChild(this.bg_element);
			}
		
			
		}
	},
	imgInit: function(){
		var w=parseInt(this.bg_element.getStyle("width"),10);
		var h=parseInt(this.bg_element.getStyle("height"),10);
		this.ratio=w/h;
		this.scale();
		this.bg_element.setStyle({visibility:"visible"});
		Event.observe(window, "resize", this.scale.bindAsEventListener(this));
	},
	scale: function() {
		
		var width, height, n_width, n_height, ratio;
		var w_width = Position.windowGetWidth();
		var w_height = Position.windowGetHeight();
		width=w_width*this.scaleFactor;
		height = w_height*this.scaleFactor;
		ratio = this.ratio;
		
		if (width/height<ratio){
			n_width=width;
			n_height=Math.round(width/ratio);
		}
		else {
			n_width=Math.round(height*ratio);
			n_height=height;
		}
		//debug("width: "+width+" height: "+height+" ratio: "+ratio);
		//debug("n_width: "+n_width+" n_height: "+n_height);
		if (Prototype.Browser.IE ) {
			this.bg_element.setStyle({width: n_width+"px", height: n_height+"px"});
		}
		else {
			this.bg_element.width=n_width;
			this.bg_element.height=n_height;
		}
		// 150: w_width/2 - (696/2) + 198  >>> mitte minus .a_inner.width / 2 + .a_sp_links.width
		// n_width*0.08: soll bündig mit Text im Bild sein, der ist um ~8% versetzt
		var pos = {
			top: Math.round((w_height/2)-(n_height/1.8)+67)+"px",
			left: Math.round(w_width/2 -150 -(n_width*0.08))+"px"
		};
		
		this.bg_element.setStyle(pos);
	
	}
}

