/*
 * feature.base.js
*/

var featureFlash;
var featureInterval;
var featureVars = { 'featureType' : 'liquid'};
var FEATURE_NAME = 'aroundtheworld';

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
				}
			}
		}
		this.addedFlash = false;
	},
	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;
		$('ng_feature').show();
		
		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();
		if(this.addedFlash == false) {
			this.app.write('ng_feature');
			this.addedFlash = true;
		}
		
		$('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;
				
		$('ng_feature').setStyle({ display:'none' });
		$('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 bugfix FF resizing
		if(window.location.hash == '#start' || getUrlParameter('start') ) featureFlash.focusFeature();
    }
}

document.observe("dom:loaded", function() {
	if(featureVars.featureType == 'liquid') {
		featureInterval = setInterval("createNGFeature()",100);
	}
});
