/********************************************************************/
/* START: LogoLayer Class			                                */

if (typeof EnergyApps == "undefined") { 
	EnergyApps = { 
		Apps : {}
	};
} else {
	EnergyApps.Apps = {};
}

var LogoLayer = Class.create();

LogoLayer.prototype = Object.extend(new AbstractLightboxLayer, {
	initialize: 
		function(node, trigger) {
		
			var lang = ( !! GLOBAL_PAGE_LANG ) ? GLOBAL_PAGE_LANG : "en",
				mandatory = ( !! GLOBAL_PAGE_LANG ) ? GLOBAL_MANDATOR_SHORTCUT : "hq";
			
			this.logoLayerFile = '/includes/root/framework/logolayer/' + mandatory + '_' + lang + '_logolayer.html';
		
			//add Layer to DOM
			new Insertion.Before("footer-position-placeholder",
						'<div id="logolayer">'
							+'<div class="close"><a href="javascript:void(0);"><span class="access">Close Logo Layer</span></a></div>'
							+'<div class="blankline">&nbsp;</div>'
							+'<div id="logolayer-content"></div></div>');
			
			this.initSuper($('logolayer'), trigger);
			trigger.href = "javascript:void(0)";
			trigger.title = "";
			
			//CloseButton
			var closeButton = Helper.getCloseButton(this.node);
			closeButton.observe("click", function(){this.close();}.bindAsEventListener(this));
			
			//Curtain
			this.curtainidstring = "lightbox-curtain-logo";
			new Insertion.After($('content-zone'), "<div id='"+ this.curtainidstring+ "' class='lightbox-curtain'>&nbsp;</div>");
			this.curtain = $(this.curtainidstring);
			
			//IframeLining
			if (Info.browser.isIEpre7) {
				this.iframeLining = new IframeLining(this.curtain);
			}
			
			this.listener = {
				'augmentDone' :this.handleOpen.bind(this)
			};
			Event.observe(window, "resize", function() { this.resizeCurtain();	}.bindAsEventListener(this));
			
			this.logoLayerCont 		= '';
			this.logoLayerReady 	= false;
			this.logoLayerLoading 	= false;
		},
	beforeOpen:
		function() {
			//calculate/set curtain size 
			this.resizeCurtain();

			//position the curtain
			this.curtain.setStyle( {
				'top':	'0px',
				'height' : '5300px'
			});
			
			if (this.iframeLining)	this.iframeLining.show();
			this.curtain.setStyle( {'display' :'block'});
			
			if( this.logoLayerLoading == false && this.logoLayerReady == false ) {
				this.logoLayerLoading = true;
				this.getLogoLayerContent( this.logoLayerFile );
			}
			/* Stop Flash Animations */
			if(typeof(featureFlash) != 'undefined' && typeof(featureFlash.stopVideo) == 'function') 
				featureFlash.stopVideo();

			return true;
		},
	getLogoLayerContent: 
		function (url) {
			if( this.logoLayerReady == false ) {
				new Ajax.Request(url,  { method:'get', onComplete: this.onresult.bind(this), onFailure: function(oXHR) { alert("Error: " + oXHR.status); }	});
			}
		},		
	hide: 
		function() {
			$("logolayer").setStyle({ 'display' : 'none' });
		},
	onresult: 
		function (xhr) {
			$('logolayer-content').update(xhr.responseText);
			
			this.logoLayerReady = true;
			this.logoLayerLoading = false;
			
			$$("#logolayer-content a").filter(function(link) {
				return !$(link).hasClassName('c');
			}).each(function(link) {
				link.observe("mouseover", function() {
					$(link).up("li").addClassName("hover");
				});
				link.observe("mouseout", function() {
					$(link).up("li").removeClassName("hover");
				});
			});
			
			//Hightlight Active Language
			$$("#logolayer li.active a").filter(function(link) {
				return !$(link).hasClassName('c');
			}).each(function(link) {
				if (link.hasClassName(PAGE_LANG)) link.addClassName("active");
			});
		},
	show:
		function() {
			$("logolayer").setStyle({ 'display' : 'block' });
			
			// #### start custom tracking implementation ####
			// check, if the s object exists
			if ( typeof s !== 'undefined' && s.tl ) {
				
				var tracking_string = 'logolink|' + location.pathname;  
				// send custom link
				s.tl(true, 'o', tracking_string);
			}
			// #### end custom tracking implementation ####			
		}
});

/* END: LogoLayer Class 	                                        */
/********************************************************************/
/* Initialize LogoLayer Class										*/

document.observe('dom:loaded', function() {
	EnergyApps.App.LogoLayer = new LogoLayer('logolayer', $('logo').down() );
});
