var Background = Class.create({
	initialize: function() {
		if(window.flbg != undefined){
			this.createBackground();
			this.mouseEvent();
		}
	},
	
getBrowserHeight: function(){
   if (window.innerHeight){
       return window.innerHeight;} 
   else if (document.documentElement &&
document.documentElement.clientHeight != 0){
       return document.documentElement.clientHeight;    }
   else if (document.body){return document.body.clientHeight;}     
       return 0;
},
	
	createBackground: function() {
		var isIE = (window.ActiveXObject) ? true : false;
		if($('top') == null)
			$$('body')[0].writeAttribute("id","top");
		
		var ie = parseFloat(navigator.appVersion.split('MSIE')[1]);
		var dimensions = $(window.flbg.pageWrap).getDimensions();
		var fullHeight = dimensions.height;
		
		if (Number(ie)){
			var browserHeight = document.body.clientHeight;
		}else{
			var browserHeight = window.innerHeight;
		}
	
		if (browserHeight > fullHeight) {
			fullHeight = "100%";
			$('top').style.height = "100%";
		}else {
			if (Number(ie)) {
				fullHeight = fullHeight + 15;
			}else{
				fullHeight = fullHeight;
			}
		}

		fullHeight = fullHeight + 20;
		/*if(isIE)
			fullHeight = fullHeight + 35;
		else
			fullHeight = fullHeight + 20 ;*/

		if(window.flbg.toLargePage == "1"){fullHeight = 1024};
			
		var flashvars = {};
			flashvars.cpWhere = window.flbg.cpWhere;
			flashvars.cpMade = window.flbg.cpMade;
			flashvars.cpXMLPath = window.flbg.cpXMLPath;
			//flashvars.cpComponents = Object.toJSON(window.flbg.cpComponents);

		var params = {};
			params.base = "typo3conf/ext/flbg/res/";
			params.allowfullscreen = "true";
			params.quality = "best";
			params.wmode = "transparent";
			params.scale = "noScale";
			params.menu = "true";		
			
		var attributes = {};
			attributes.id = window.flbg.id;
			attributes.name = window.flbg.id;		

		swfobject.embedSWF("typo3conf/ext/flbg/res/flbg.swf", window.flbg.id, "100%", fullHeight.toString(), "8", "", flashvars, params, attributes);
		
		$(window.flbg.id).wrap("div", { "class": window.flbg.id, "id": window.flbg.id+"ID", "style": "height:"+fullHeight.toString()+"px;"});	
/*		$(window.flbg.id).style.height = fullHeight+'px';
		alert(this.getBrowserHeight())
		$('flbgID').setStyle({ 'height': this.getBrowserHeight() });
		$('flbg').setStyle({ 'height': this.getBrowserHeight() });		*/

		$(window.flbg.pageWrap).wrap("div", {"id": "cpPageT3"});
	},
	
	mouseEvent: function(){
		this.mouseX = 0;
		this.mouseY = 0;
		
		document.observe('mousemove', this.updateMousePosition);
	},
	
	updateMousePosition: function(event){
		if(typeof(event.pageX) == 'number' ){
			var xcoord = event.pageX;
			var ycoord = event.pageY;
		}else if(typeof(event.clientX)=='number'){
			var xcoord = event.clientX;
			var ycoord = event.clientY;
			var badOldBrowser = (window.navigator.userAgent.indexOf('Opera') + 1) || (window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) || (navigator.vendor == 'KDE');
			
			if(!badOldBrowser){
				if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
					xcoord += document.body.scrollLeft;
					ycoord += document.body.scrollTop;
				}else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
					xcoord += document.documentElement.scrollLeft;
					ycoord += document.documentElement.scrollTop;
				}
			}
		}else{}

		window.cpBackgroundMouseEvents = {}
		window.cpBackgroundMouseEvents._xmouse = xcoord;
		window.cpBackgroundMouseEvents._ymouse = ycoord;
	}
});

UClass.background = Background;


function sendMouseEventToFlash(){
	return window.cpBackgroundMouseEvents._xmouse+"::"+window.cpBackgroundMouseEvents._ymouse;
}
