/********************************************************************/
/* START: LogoLayer Class			                                */

var LogoLayer = Class.create();

LogoLayer.prototype = Object.extend(new AbstractLightboxLayer, {
	initialize: 
		function(node, trigger) {
			//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)";
			
			//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'});
			
			if (this.iframeLining)	this.iframeLining.show();
			this.curtain.setStyle( {'display' :'block'});
			
			if( this.logoLayerLoading == false && this.logoLayerReady == false ) {
				this.logoLayerLoading = true;
				this.getLogoLayerContent(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");
				});
			});
		},
	show:
		function() {
			$("logolayer").setStyle({ 'display' : 'block' });
			
			// #### start custom tracking implementation ####
			// check, if the s object exists
			if (s) {
				
				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										*/

if(PAGE_LANG == undefined) {
    //var url = window.location.href;
    var matches = window.location.href.match(/\/(answers|entry)\/([a-z]{2})\/([a-z]{2})\//);
    var PAGE_COUNTRY 	= (matches ? matches[2] : 'cc'); 
    var PAGE_LANG 		= (matches ? matches[3] : 'en'); 
}

var logoLayer;

var logoLayerFile = '/' + PAGE_LANG + '/logolayer.html';
var currentSite = window.location.protocol+'//'+window.location.host;
if(currentSite == 'https://stage.siemens.com')
	logoLayerFile = '/us/corp_nwa/' + PAGE_LANG + '/logolayer.html';
else if(currentSite == 'https://edit.siemens.dev.publicis.de')
	logoLayerFile = '/us/corp_nwa/root/' + PAGE_LANG + '/logolayer.html';


document.observe('dom:loaded', function() {
	logoLayer = new LogoLayer('logolayer', $('logo').down() );
});
