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;
			this.initNGFeature();
			this.initFeature();
			this.blurFeature(); 
		}
	},
	initNGFeature: function() 
	{
		if( document.all) { 
			var logo = document.getElementById('logo').cloneNode(true); 
			$('logo').remove();
			new Insertion.Before('footer-position-wrapper',logo);
		}
		
		if (window.console) console.log("initNGFeature");
		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 );
	},
	initFeature: function()
	{
		var rsLang = "us";
		var rsPath = encodeURIComponent("http://w1.siemens.com/entry/cc/features/science_express/all/en/readspeaker/");
		var rsCustomer = "1003388";
		var rsUrl = "http://asp.readspeaker.net/cgi-bin/siemensrsone";
		
		// vars for komdat-tracking
		var customerId = "101260";
		var komdat_download_bestell = "";  //if "" =random in flash
		var komdat_optin_bestell = "";     //if "" =random in flash
		var komdat_mailopen_bestell = "";  //if "" =random in flash
		var komdat_linkrot_bestell = "";   //if "" =random in flash
		var komdat_subscribe_bestell = "";   //if "" =random in flash
		
		var komdat_download_op1 = "26";    //if "" = 26 in flash
		var komdat_optin_op1 = "5";        //if "" = 5 in flash
		var komdat_mailopen_op1 = "13";    //if "" = 13 in flash
		var komdat_linkrot_op1 = "6";	   //if "" = 6 in flash
		var komdat_subscribe_op1 = "5";    //if "" = 5 in flash		

		var komdat_download_worth = "1";   //if "" = 0 in flash
		var komdat_optin_worth = "1";      //if "" = 0 in flash
		var komdat_mailopen_worth = "1";   //if "" = 0 in flash
		var komdat_linkrot_worth = "1";    //if "" = 0 in flash
		var komdat_subscribe_worth = "1";  //if "" = 0 in flash
		
		//  vars for contact/feedbackform
		var formmailerUrl = "../../../../../framework/pub/script/formmailer.php";
		var formmailerReceiver = "28";
		var feedbackReceiver = "28";

// ---------- change by ccaine ---------- 
		// vars for flash
		var swfLang = "et";
		var localPath = "";
		var globalPath= "../";	
		var flvPath = "../flv/" + this.flashVersion + "/";
		var imgPath = "../img/";
		
		var sectionParameter = "";
		var section = getUrlParameter("section");
		if(section != null && (section == "green_index" || section == "smartgrid" || section == "healthcareit" || section == "renewableindustry" || section == "mobility")){
			sectionParameter = "&section=" + section;
		}else{
			sectionParameter = "";
		}
		
		var sliderSwfPath = "../swf/";
		var sliderImgPath = "../img/"
		var sliderXmlPath = "xml/"
		
		var isFirefox = navigator.appName == "Netscape" ? true : false;
		var logoUrl = "http://www.siemens.com";
		var siteXML = "../xml/site.xml";
		var app = new SWFObject("../features/greencityindex/ee/et/swf/main.swf", this._featureId , "987", "100%", this.flashVersion + ",0,0,0", "#ffffff");
		app.addParam("quality", "high");
		app.addParam("wmode", "transparent");
		app.addParam("base", "../features/greencityindex/ee/et/swf/");
		app.addParam("menu", "false");
		app.addParam("swliveconnect", "true");
		app.addParam("allowScriptAccess", "always");
		app.addParam("FlashVars", "siteXML=" + siteXML + "&s_account=" + s_account + "&sticker=true&sliderSwfPath=" + sliderSwfPath + "&sliderImgPath=" + sliderImgPath +"&sliderXmlPath=" + sliderXmlPath + "&isFirefox=" + isFirefox + "&rsCustomer=" + rsCustomer + "&rsPath=" + rsPath + "&rsLang=" + rsLang + "&rsUrl=" + rsUrl + "&feedbackReceiver=" + feedbackReceiver + "&komdat_subscribe_bestell=" + komdat_subscribe_bestell + "&komdat_subscribe_op1=" + komdat_subscribe_op1 + "&komdat_subscribe_worth=" + komdat_subscribe_worth + "&komdat_linkrot_op1=" + komdat_linkrot_op1 + "&komdat_mailopen_op1=" + komdat_mailopen_op1 + "&komdat_optin_op1=" + komdat_optin_op1 + "&komdat_download_op1=" + komdat_download_op1 + "&komdat_download_bestell=" + komdat_download_bestell + "&komdat_optin_bestell=" + komdat_optin_bestell + "&komdat_mailopen_bestell=" + komdat_mailopen_bestell + "&komdat_linkrot_bestell=" + komdat_linkrot_bestell + "&komdat_download_worth=" + komdat_download_worth + "&komdat_optin_worth=" + komdat_optin_worth + "&komdat_mailopen_worth=" + komdat_mailopen_worth + "&komdat_linkrot_worth=" + komdat_linkrot_worth + "&customerId=" + customerId + "&formmailerUrl=" + formmailerUrl + "&formmailerReceiver=" + formmailerReceiver + "&version=" + this.flashVersion + "&language=" + swfLang + "&localPath=" + localPath + "&globalPath=" + globalPath + "&logoUrl=" + logoUrl + "&imgPath=" + imgPath + "&flvPath=" + flvPath + "&featureName=" + FEATURE_NAME + sectionParameter);		app.write("ng_feature"); //app.write("headervisual-zone");
		//$('headervisual-zone').hide();
	},
	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;
		
		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;
		
		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);
	}
}

var featureFlash;
var featureInterval;
document.observe("dom:loaded", function() {
    featureInterval = setInterval("createNGFeature()",100);
});

function createNGFeature() {
    if(window.HeaderAnimation.listenerQueue) {
        clearInterval(featureInterval);
        featureFlash = new Feature();
        if (Info.browser.isFirefox) Event.observe(window, 'beforeunload', featureFlash.blurFeature, false);
    }
}
