
var PAGE = {
	
	//------------------------------------------------------------------------
	
	contentContainer:null,
	contentWrap:null,
	mainNavi:null,
	mediaNavi:null,
	logo:null,
	colorSchema:null,
	bgImage:null,
	styleSheet:null,
	footer:null,
	
	//------------------------------------------------------------------------
	
	init:function() {

		Cufon.replace('h1');

		this.init_elements();
		this.set_colorSchema();
		this.fade_logo();
		this.on_resize();
		window.onresize = function(){
			PAGE.on_resize();
		}
	},
	
	//------------------------------------------------------------------------

	init_elements:function() {
		this.contentContainer = this.object_exists('contentContainer');
		this.contentWrap = this.object_exists('contentWrap');
		this.mainNavi = this.object_exists('mainNavigation');
		this.mediaNavi = this.object_exists('mediaNavigation');
		this.footer = this.object_exists('footer');
		this.bgImage = this.object_exists(document.images.bgImage);
		this.bgImage.scaleTo = 'x';
		this.init_navi(this.mainNavi);
		this.init_navi(this.mediaNavi);
		this.logo = this.object_exists('logo');
		this.styleSheet = this.object_exists('colorSchemaCss');
	},

	//------------------------------------------------------------------------
	
	object_exists:function( id ) {
		return ($(id)) ? $(id) : null;
	},

	//------------------------------------------------------------------------
	
	init_navi:function( navi ) {
		var nodes;
		
		nodes = $(navi).getChildren('li');
		navi.activeElement = undefined;
		nodes.each(function(el) {
			if( el.hasClass('activeNode') ) {
				navi.activeElement = el;
				navi.activeElement.ul = el.getElementsByTagName('ul')[0];
			}
			el.onmouseover = function() {
				if( navi.activeElement != undefined && navi.activeElement.ul != undefined && navi.activeElement != this ) {
					navi.activeElement.ul.style.display = 'none';
				}
			}
			el.onmouseout = function() {
				if( navi.activeElement != undefined && navi.activeElement.ul != undefined && navi.activeElement != this ) {
					navi.activeElement.ul.style.display = '';
				}
			}
		});
	},
	
	//------------------------------------------------------------------------
	
	set_colorSchema:function() {
		
		if(this.styleSheet === null) {
			var head = document.getElementsByTagName('head')[0];
			this.styleSheet = document.createElement('link');
			this.styleSheet.id='colorSchemaCss';
			this.styleSheet.href='';
			this.styleSheet.rel='stylesheet';
			this.styleSheet.type='text/css';
			head.appendChild(this.styleSheet);
		}
		if( this.styleSheet.href.indexOf('/fileadmin/templates/css/white.css') > -1 ) {
			this.colorSchema = 'white';
		} else if( this.styleSheet.href.indexOf('/fileadmin/templates/css/black.css') > -1 ) {
			this.colorSchema = 'black';
		} else {
			this.colorSchema = 'home';
		}
	},

	//------------------------------------------------------------------------

	on_resize:function() {
		this.set_bgImage();
		this.set_contentContainer();
		this.set_footer();
	},
	
	//------------------------------------------------------------------------

	set_footer:function() {
		var top = this.contentContainer.offsetTop + this.contentContainer.offsetHeight;
		var top2 = window.getSize().y - top;
		if( top2 <= 66 ) {
			this.footer.style.position = 'absolute';
			this.footer.style.top = top + 38 + 'px';
			this.footer.style.bottom = 'auto';
		} else {
			this.footer.style.position = '';
			this.footer.style.top = 'auto';
			this.footer.style.bottom = '0px';
		}
		delete top;
		delete top2;
	},

	//------------------------------------------------------------------------

	get_containerTop:function( obj ) {
		obj = obj || this.contentContainer;
		var y = 0;
		var windowH = window.getSize().y / 2;
		y = obj.offsetHeight / 2;
		y = Math.round( windowH - y );
		y = ( y < 176 ) ? 176 : y;
		return y;
	},

	//------------------------------------------------------------------------
	
	set_contentContainer:function() {
		this.contentContainer.style.top = this.get_containerTop() + 'px';
	},
	
	//------------------------------------------------------------------------
	
	set_bgImage:function() {

		this.handle_browser();

		if( this.bgImage.scaleTo == 'x' ) {
			if( window.getSize().y > this.bgImage.offsetHeight ) {
				this.bgImage.scaleTo = 'y';
				this.bgImage.style.height = '100%';
				this.bgImage.style.width = 'auto';
			}
		}
		else {
			if( window.getSize().x > this.bgImage.offsetWidth ) {
				this.bgImage.scaleTo = 'x';
				this.bgImage.style.height = 'auto';
				this.bgImage.style.width = '100%';
			}
		}
		var left = (((this.bgImage.offsetWidth - window.getSize().x) / 2) * -1);
		var top = (((this.bgImage.offsetHeight - window.getSize().y) / 2) * -1);
		this.bgImage.style.marginLeft = left + 'px';
		this.bgImage.style.marginTop = top + 'px';
		delete left;
		delete top;
	},
	
	//------------------------------------------------------------------------

	handle_browser:function() {
		// Blendet beim Firefox das Hintergrundbild aus...
		var flashFiles = document.getElementsByTagName('object');
		if( Browser.firefox === true && this.colorSchema == 'black' && flashFiles.length > 0 ) {
			document.getElementsByTagName('body')[0].style.backgroundColor = '#1A1A1A';
			this.bgImage.style.display = 'none';
			$('backgroundImage_onOff').style.display = 'none';
		} else {
			document.getElementsByTagName('body')[0].style.backgroundColor = '';
			this.bgImage.style.display = 'block';
			$('backgroundImage_onOff').style.display = 'block';
		}
	},

	//------------------------------------------------------------------------

	fade_logo:function( params ) {
		
		params = params || {};
		params.colorSchema = params.colorSchema || this.colorSchema;
		params.onComplete = params.onComplete || function(){};
		
		var logoFx = new Fx.Morph(this.logo,{
			duration:500,
			transition: Fx.Transitions.Sine.easeInOut,
			onComplete:params.onComplete
		});
		if( params.colorSchema == 'black' ) {
			logoFx.start({
				backgroundPosition: '0px -95px',
				height: 27,
				top: 6
			});
		} else {
			logoFx.start({
				backgroundPosition: '0px 0px',
				height: 115,
				top: 13
			});
		}
		delete params;
	},

	//------------------------------------------------------------------------

	set_logoLink:function(lang_id) {
		var logo = document.getElementById('logo');
		logo.href = '/index.php?L='+lang_id;
		AJAXLOADER.parse_links(logo.parentNode);
	 }

	//------------------------------------------------------------------------
};

window.addEvent('domready',function(){
	PAGE.init();
});

window.addEvent('load',function(){
	PAGE.on_resize();
});
