var PAGE = {
	
	//----------------------------------------------------------------
	
	navi:null,

	//----------------------------------------------------------------
	
	init:function() {
		this.set_navigation();
		this.set_flash();
		this.set_links();
		this.set_forms();
		this.set_splash();
	},
	
	//----------------------------------------------------------------
	
	set_navigation:function() {
		this.navi = document.getElementById('navigation');
		if(this.navi != null && WORLD == 'powerup' ) {
			this.navi.nodes = this.navi.getElementsByTagName('a');
			for(var i=0; i<this.navi.nodes.length; i++) {
				var node = this.navi.nodes[i];
				node.active = ( node.parentNode.className.indexOf('active') > -1 ) ? true : false;
				node.key = node.innerHTML.toLowerCase();
				node.onmouseover = function() {
					SWF.execute('on_triggerNaviOver',this.key);
				}
				node.onmouseout = function() {
					SWF.execute('on_triggerNaviOut',this.key);
				}
			}
			delete node;
			delete i;
		} else {
			return false;
		}
	},

	//----------------------------------------------------------------
	
	set_naviNodeActive:function( key, over ) {
		for(var i=0; i<this.navi.nodes.length;i++) {
			var node = this.navi.nodes[i];
			if( node.active == false ) {
				if(node.key == key) {
					if( over === true ) {
						node.parentNode.className = node.parentNode.className + ' active';
					} else {
						node.parentNode.className = node.parentNode.className.replace(' active','');
					}
				} else {
					node.parentNode.className = node.parentNode.className.replace(' active','');
				}
			}
		}
		delete node;
		delete i;
	},

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

	trigger_naviNode:function( key ) {
		for(var i=0; i<this.navi.nodes.length;i++) {
			var node = this.navi.nodes[i];
			if(node.key == key) {
				window.location.href = node.href;
			}
		}
		delete node;
		delete i;
	},

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

	set_flash:function() {
		if( IS_IFRAME === false ) {
			var flashvars = {
				'WORLD':WORLD,
				'xmlUid': XML_UID,
				'pageUid': PAGE_UID,
				'showConsole':'true'
			};
			var params = {
				'wmode':'transparent',
				'bgcolor':'#FFFFFF',
				'allowScriptAccess':'always'
			};
			var attributes = {
				'bgcolor':'#FFFFFF',
				'id':'powerup_movie',
				'name':'powerup_movie'
			};
			var d = new Date();
			swfobject.embedSWF("fileadmin/templates/flash/index.swf?id="+d.getTime(), "flashContainer_movie", 1264, 668, "9.0.0", false, flashvars, params, attributes);
		}
	},

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

	set_links:function() {
		if( IS_IFRAME === true ) {
			var base = document.getElementsByTagName('base')[0];
			var links = document.getElementsByTagName('a');
			for( var i=0; i<links.length;i++ ) {
				var a = links[i];

				if( a.href.indexOf('iframe=') == -1 && a.href.indexOf(base.href) > -1 ) {
					if( a.target != '_top' && a.href.indexOf('mailto:') == -1 && a.href.indexOf('javascript:') == -1 ) {
						a.href = ( a.href.indexOf('?') > -1 ) ? a.href+'&iframe=1' : a.href + '?iframe=1';
					}
				}
			}
			delete i;
			delete base;
			delete links;
		}
	},

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

	set_forms:function() {
		if( IS_IFRAME === true ) {
			var base = document.getElementsByTagName('base')[0];
			var forms = document.getElementsByTagName('form');
			for( var i=0; i<forms.length;i++ ) {
				var f = forms[i];
				if( f.action.indexOf('iframe=') == -1 && f.action.indexOf(base.href) > -1 ) {
					f.action = ( f.action.indexOf('?') > -1 ) ? f.action+'&iframe=1' : f.action + '?iframe=1';
				}
			}
			delete i;
			delete base;
			delete forms;
		}
	},

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

	set_splash:function() {
		if( IS_IFRAME === false && document.getElementById('splash') != null ) {

			var cookieName = 'powerup_splash';

			var speed = 250;
			var splash = document.getElementById('splash');
			splash.isRunning = false;
			splash.fx = null;
			splash.onmouseover = function() {
				this.fx = new Fx.Morph(this,{duration:speed,onComplete:function(){
					splash.isRunning = false;
				}});
				this.fx.start({top:0,left:0});
			}
			splash.onmouseout = function() {
				this.fx = new Fx.Morph(this,{duration:speed,onComplete:function(){
					splash.isRunning = false;
				}});
				this.fx.start({top:-360,left:-322});
			}
			
			if( Cookie.read(cookieName) === null ) {
				Cookie.write(cookieName, '1');
				splash.onmouseover();
				setTimeout(function(){splash.onmouseout();},4000);
			}

		}
	}

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

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