/*
	CUSTOM feature.base.js for pages containing the /answers-feature
 * feature.base.js
*/

var featureFlash;
var featureInterval;

var Feature = Class.create();
Feature.prototype = {
	initialize: function()
	{
		this._featureId = "FlashApplication";
		var version;
		var fVersion = deconcept.SWFObjectUtil.getPlayerVersion()["major"];
		if(fVersion >= 9){			//special resources for flash 9 available
			version = 9;
		}else{
			version = 0;			//not supported flash version -> show non-flash/non-javascript version
		}

		if(version != 0){
			this.flashVersion = version;
			if(featureVars.featureType == 'liquid') this.initNGFeature();
			this.initFeature();
			if(featureVars.featureType == 'liquid')
			{
				if(Layer.current == null) // if no layer is already open then do blurFeature
				{
					this.blurFeature(); // line added buxfix FF resizing
				}
			}
		}
	},
	initNGFeature: function() 
	{
		new Insertion.Before('footer-position-wrapper','<div id="ng_feature"></div>');
		this.isFocussed = false;
		Event.observe(document.onresize ? document : window, "resize", function() {
			if( featureFlash.isFocussed==true ) featureFlash.focusFeature();
		}); 
		var featureListener = { augmentDone: function() { if( featureFlash.isFocussed ) featureFlash.focusFeature();} };
		HeaderAnimation.listenerQueue.add( featureListener );
	},
	stopVideo: function() { 
		var _flashObj = $(this._featureId); 
	    if(_flashObj) _flashObj.SetVariable('stopVideo','true');
	},
	looseFocus: function() {
		$(this._featureId).blur();
	},
	getFeatureId: function() {
		return this._featureId;
	},			
	focusFeature: function() {
		Layer.closeCurrent();
		this.isFocussed = true;
		
		$('logo').style.zIndex = -1; // prevent logo from beeing visible during video-playback
		//$('logo').setStyle({zIndex: '-1', border: '1px solid red' });
		
		if ($('header-zone').getHeight() == 393 || $('header-zone').getHeight() == 0) { //otherwise wait till HeaderAnimation is finished
			var maxWidth = 1000;
			var maxHeight = 600;
			var newWidth, newHeight;
			
			var resizeFeature = function() {
				newWidth = document.viewport.getWidth() < maxWidth ? maxWidth : document.viewport.getWidth();
				newHeight = document.viewport.getHeight() < maxHeight ? maxHeight : document.viewport.getHeight();
	
				$('ng_feature').setStyle({ width: newWidth+'px', height: newHeight+'px'});
			}
			
			resizeFeature();
			
			$('toolbar-zone').hide();
		  	$('content-zone').hide();
			$('footer-zone').hide();
			
			document.getElementById('FlashApplication').width = '100%';
			document.getElementById('FlashApplication').height = '100%';
			
			setTimeout(resizeFeature, 50);
			
			var app = (navigator.appName.indexOf("Microsoft") != -1) ? document.getElementById("FlashApplication") : document["FlashApplication"];
			app.SetVariable('browserSize', newWidth + ',' + newHeight);
		}
	},
	blurFeature: function() {
		Layer.closeCurrent();
		this.isFocussed = false;
		
		$('logo').style.zIndex = 10002; // set logo back to top-level
		
		document.getElementById('FlashApplication').width = '987';
		document.getElementById('FlashApplication').height = '393';
		
		$('ng_feature').setStyle({ width:'987px', height: '393px'});
		$('toolbar-zone').show();
		$('content-zone').show();
		$('footer-zone').show();
		
		var app = (navigator.appName.indexOf("Microsoft") != -1) ? document.getElementById("FlashApplication") : document["FlashApplication"];
		if(typeof newWidth != "undefined") app.SetVariable('browserSize', newWidth + ',' + newHeight); // line changed buxfix FF resizing
	}
}

function createNGFeature() {
    if(window.HeaderAnimation.listenerQueue) {
        clearInterval(featureInterval);
        featureFlash = new Feature();
		if (Info.browser.isFirefox) Event.observe(window, 'beforeunload', featureFlash.blurFeature, false); // line added buxfix FF resizing
    }
}

document.observe("dom:loaded", function() {
	if(featureVars.featureType == 'liquid') {
		featureInterval = setInterval("createNGFeature()",100);
	}
});
