// properties are directly passed to `create` method
var piLayer;
var pubInterface;
var pubInterfaceClass = Class.create();
pubInterfaceClass.prototype = {
		initialize: function() {
			//
		},
		
		initLiquidFeature: function() {			
			this.id = 'liquid-feature';
			this.layerID = 'liquid-feature-layer';
			this.isFocussed = false;
			
			this.requiredFlashVersion = 9;
			this.detectedFlashVersion = 0;
			this.swfObject = null;
			this.swfObjectSrc = "../apps/vi_flash/wall.swf";
			if(PAGE_LANG == 'de')
				this.swfObjectParam = "?wallXML=../vi_flash/content/xml/wall-de.xml";
			else 
				this.swfObjectParam = "?wallXML=../vi_flash/content/xml/wall-en.xml";
			
			this.swfObject = new SWFObject(this.swfObjectSrc+this.swfObjectParam, "swfUnique1", "100%", "100%", this.requiredFlashVersion, "#ffffff");
			this.swfObject.addParam("base","../apps/vi_flash/");
			this.swfObject.addParam("menu","false");
			this.swfObject.addParam("allowScriptAccess","true");
			
			this.detectedFlashVersion = this.swfObject.installedVer.major;

			// just init the liquid feature if the required flash version is installed
			// no plugin or disabled plugin would be this.detectedFlashVersion == 0
			if (this.detectedFlashVersion > this.requiredFlashVersion) {

				var mouseOutImg = '../pool/teaserflash_' + PAGE_LANG + '_01.jpg';
				var mouseOutElmId = 'teaserMouseOut';
				var mouseOverImg = '../pool/teaserflash_' + PAGE_LANG + '_02.jpg';
				var mouseOverElmId = 'teaserMouseOver';
				
				// generate initial state (mouseout)
				$(this.id).down('img').src 	= mouseOutImg;
				$(this.id).down('img').id 	= mouseOutElmId;
				
				// load and append mouseover image in initial state, hide it
				$(this.id).down('div.image a').insert('<img src="' + mouseOverImg + '" alt="No Script Image" id="' + mouseOverElmId +'">');
				$(mouseOverElmId).hide();
				
				// show mouseover image
				$(this.id).down('a').observe('mouseover', function(e) {
					Event.stop(e);
					$(mouseOutElmId).hide();
					$(mouseOverElmId).show();
					
				});
				// show initial image on mouseout
				$(this.id).down('a').observe('mouseout', function(e) {
					Event.stop(e);				
					$(mouseOverElmId).hide();
					$(mouseOutElmId).show();
				});				
				
				$(this.id).down('a').href = 'javascript:void(0);';
				$(this.id).down('a').observe('click', function(e) { Event.stop(e); this.loadLiquidFeature(); }.bindAsEventListener(this));	
				
			}
		},
		
		
		loadLiquidFeature: function() {
			// hide elements and do the insertion, if the required flash version is installed
			if (this.detectedFlashVersion > this.requiredFlashVersion) {
				new Insertion.Before($('footer-position-wrapper'), '<div id="'+this.layerID+'" style="position: absolute;top:0;left:0;z-index:90;height:100%;width:100%;"></div>');
				
				this.swfObject.addParam("base", "../apps/vi_flash/");
				this.swfObject.addParam("wmode", "transparent");
				
				if(Layer.current) Layer.closeCurrent();
				
				this.focusLiquidFeature();
				
				Event.observe(document.onresize ? document : window, "resize", function() {
					if( pubInterface.isFocussed==true ) pubInterface.focusLiquidFeature();
				}); 
				if (Info.browser.isFirefox) Event.observe(window, 'beforeunload', pubInterface.closeLiquidFeeture, false); // line added buxfix FF resizing
				
				this.swfObject.write(this.layerID);
			}
		},
		
		focusLiquidFeature:function() {
				this.isFocussed = true;
			
				$('toolbar-zone').hide();
			  	$('content-zone').hide();
				$('footer-zone').hide();
			
				var minWidth = 1200;
				var minHeight = 675;
				var newWidth, newHeight;
				
				var resizeFeature = function() {
//					console.log("resizeFeature: " + document.viewport.getWidth() + ":" + document.viewport.getHeight());
//					newWidth = document.viewport.getWidth() < minWidth ? minWidth : document.viewport.getWidth();
//					newHeight = document.viewport.getHeight() < minHeight ? minHeight : document.viewport.getHeight();
					newWidth = document.viewport.getWidth() < minWidth ? minWidth + 'px' : '100%';
					newHeight = document.viewport.getHeight() < minHeight ? minHeight + 'px' : '100%'; //document.viewport.getHeight();
						
					if(Info.browser.isFirefox && newHeight == '100%') newHeight = '99.5%';
					
					$(this.layerID).setStyle({ width: newWidth, height: newHeight});
				}.bind(this);
				resizeFeature();
				setTimeout(resizeFeature, 50);
				setTimeout(resizeFeature, 100);
		},
		
		closeLiquidFeature: function() {
			this.isFocussed = false;
			
			$('toolbar-zone').show();
		  	$('content-zone').show();
			$('footer-zone').show();
			
			$(this.layerID).update().setStyle({ width: '0px', height: '0px'});
		},
		
		openStoryLayer : function() {
			alert("Opening Story Layer");
		},
		
		openLinkLayer: function(link, type) {
			//set class of layer
			$('lightbox-layer-'+this.id).addClassName('lightbox-layer-'+type);
			
//			piLayer.debug = true;
			piLayer.iframehref = link;
			
			piLayer.open();
		}
};

document.observe('dom:loaded', function() {
	pubInterface = new pubInterfaceClass();
	// explicitely init liquid feature
	pubInterface.initLiquidFeature();
});
