
/*
 * domready.js
 *
 * Cross browser mozilla's 'onDOMContentLoaded' implementation.
 * Executes a function when the dom tree is loaded without waiting for images.
 *
 * Based on +Element.Events.domready+ from Mootools open source project,
 * this tiny javascript library adds the emulated 'DOMContentLoaded' functionality.
 *
 * Features:
 *   - No dependency on external libraries
 *   - Compatible with Prototype.js
 *
 * Tested browsers (Windows):
 *   - IE 7 (XP standalone)
 *   - IE 6 SP2
 *   - Firefox 2.0.0.4
 *   - Opera 9.21
 *
 * Tested browsers (Mac OS X):
 *   - Safari 2.0.4
 *   - Firefox 2.0.0.4
 *   - Mac Opera 9.21
 *   - Mac IE 5.2.3
 *
 * Copyright (c) 2007 Takanori Ishikawa.
 * License: MIT-style license.
 *
 * MooTools Copyright:
 * copyright (c) 2007 Valerio Proietti, <http://mad4milk.net>
 *
 *
 * See Also:
 *
 *   mootools
 *   http://mootools.net/
 *
 *   The window.onload Problem - Solved!
 *   http://dean.edwards.name/weblog/2005/09/busted/
 *
 *   [PATCH] Faster onload for Event.onload
 *   http://dev.rubyonrails.org/ticket/5414
 *   Changeset 6596: Support for "DOMContentLoaded" event handling (prototype.js event branch)
 *   http://dev.rubyonrails.org/changeset/6596
 *
 */

/**
 * @private
 */
if (typeof Event.onDOMReady != "function"){
	if (typeof Event == 'undefined') {
		Event = {};
	}
/*
 * Registers function +fn+ will be executed when the dom
 * tree is loaded without waiting for images.
 *
 * Example:
 *
 *  Event.domReady.add(function() {
 *    ...
 *  });
 *
 */

Event.domReady = {
  add: function(fn) {

    //-----------------------------------------------------------
    // Already loaded?
    //-----------------------------------------------------------
    if (Event.domReady.loaded) {
		return fn();
	}

    //-----------------------------------------------------------
    // Observers
    //-----------------------------------------------------------
    var observers = Event.domReady.observers;
    if (!observers) {
		observers = Event.domReady.observers = [];
	}
    // Array#push is not supported by Mac IE 5
    observers[observers.length] = fn;

    //-----------------------------------------------------------
    // domReady function
    //-----------------------------------------------------------
    if (Event.domReady.callback) {
		return;
	}
    Event.domReady.callback = function() {
      if (Event.domReady.loaded) {
		return;
	  }

      Event.domReady.loaded = true;
      if (Event.domReady.timer) {
        clearInterval(Event.domReady.timer);
        Event.domReady.timer = null;
      }

      var observers = Event.domReady.observers;
      for (var i = 0, length = observers.length; i < length; i++) {
        var fn = observers[i];
        observers[i] = null;
        fn(); // make 'this' as window
      }
      Event.domReady.callback = Event.domReady.observers = null;
    };

    //-----------------------------------------------------------
    // Emulates 'onDOMContentLoaded'
    //-----------------------------------------------------------
    var ie = !!(window.attachEvent && !window.opera);
    var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1;

    if (document.readyState && webkit) {

      // Apple WebKit (Safari, OmniWeb, ...)
      Event.domReady.timer = setInterval(function() {
        var state = document.readyState;
        if (state == 'loaded' || state == 'complete') {
          Event.domReady.callback();
        }
      }, 50);

    } else if (document.readyState && ie) {

      // Windows IE
      var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
      document.write(
        '<script type="text/javascript" defer="defer" src="' + src + '" ' +
        'onreadystatechange="if (this.readyState == \'complete\') Event.domReady.callback();"' +
        '><\/script>');

    } else {

      if (window.addEventListener) {
        // for Mozilla browsers, Opera 9
        document.addEventListener("DOMContentLoaded", Event.domReady.callback, false);
        // Fail safe
        window.addEventListener("load", Event.domReady.callback, false);
      } else if (window.attachEvent) {
        window.attachEvent('onload', Event.domReady.callback);
      } else {
        // Legacy browsers (e.g. Mac IE 5)
        var fn = window.onload;
        window.onload = function() {
          Event.domReady.callback();
          if (fn) {
			fn();
		  }
        };
      }

    }

  }
};

}


/**
 * @class Publicis
 * Helper class and inheritance in javascript
 * @singleton
 * @author Alexis Dorn | Sebastian Sauer
 */

Publicis = function (){
	return {
		/**
		 * Enables classic inheritance in Javascript. It won't call the constructor of the parent class!
		 * Be sure that in oProps are only methods,
		 * as properties with complex datatypes will be passed by reference (!!!).
		 * Extends superClass wifth subClass. Public methods and properties can be overwritten.
		 * @param {Class} subClass Subclass, which will extend superClass
		 * @param {Class} superClass Class, which will be extended
		 * @param {Object} oProps Properties an methods of the subClass
		 */
		extend: function (subClass, superClass, oProps){

			var F = function(){};
			F.prototype = superClass.prototype;

			subClass.prototype = new F();
			subClass.prototype.constructor = subClass;

			subClass.superclass = superClass.prototype;

			if (superClass.prototype.constructor == Object.prototype.constructor){
				superClass.prototype.constructor = superClass;
			}

			if (oProps){
				for (var i in oProps){
					subClass.prototype[i] = oProps[i];
				}
			}

		},
		/**
		 * Adds a function to the dom ready event
		 * @param {Object} fn
		 */
		onDomReady: function (fn){
			if (typeof Event.onDOMReady == "function"){
				Event.onDOMReady(fn);
			}else{
				Event.domReady.add(fn);
			}
		},
		/**
		 * Returns a unique id string, which is not in use as an dom id
		 * @return String
		 */
		uniqueId: function (){
			var idNum = parseInt(Math.random () * Date.parse(new Date()), 10);
			var id = "publicis-" + idNum;
			if (document.getElementById(id)){
				id = this.uniqueId();
			}
			return id;
		},
		/**
		 * Helper for destroying IE nodes
		 * @private
		 * @param {Object} element
		 */
		discardElement : function (element) {
			if (!document.all && $(element).parentNode){
				nd = $(element).remove();
				nd = null;
				delete nd;
				return;
			}
			//see http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/c76967f0-dcf8-47d0-8984-8fe1282a94f5
		     var garbageBin = document.getElementById('IELeakGarbageBin');
		     if (!garbageBin) {
		             garbageBin = document.createElement('DIV');
		             garbageBin.id = 'IELeakGarbageBin';
		             garbageBin.style.display = 'none';
		             document.body.appendChild(garbageBin);
		     }
		     // move the element to the garbage bin
		     garbageBin.appendChild(element);
		     garbageBin.innerHTML = '';
		},
		/**
		 * Helper to detect if obj is a native js array
		 * @param {Object} obj
		 * @return bool
		 */
		isArray: Array.isArray || function (obj) {
			return !!(obj && obj.concat && obj.unshift && !obj.callee);
		},
		/**
		 * depends on Prototypejs' Event Object
		 * @param {Object} ev
		 * @return null || element name
		 */
		is : function ( ev ) {
			if( !ev || !ev.target ) {
				return null;
			}
			try {
				return Event.element( ev ).tagName.toLowerCase();
			} catch( e ) { return null; }
		},
		/**
		* @param {Object} DOMNode
		* return {String}
		*/
		innerText : function ( node ) {
			if( ! node ) { return ""; }
			var content = node.innerHTML.strip(),
				R_INNERTEXT = />.*(?=<.*)/;

			if( ( /[^a-zA-Z0-9]/ ).test( content )
				&& R_INNERTEXT.test( content )
			) {
				try {
					content = R_INNERTEXT.exec( content )[ 0 ].substr( 1 );
				} catch( e ) {
					content = tab.innerHTML;
				}
			}
			return content;
		},
		getViewport : function () {
			var elem = (document.compatMode === "CSS1Compat") ?
				document.documentElement :
				document.body;
			return {
				height : elem.clientHeight || 0,
				width : elem.clientWidth || 0
			};
		},
		/**
		 * @see jQuery getWindow
		 */
		getWindow : function ( elem ) {
			if( !elem ) {
				var elem = window;
			}
			return elem && typeof elem === "object" && "setInterval" in elem
				? elem
				: elem.nodeType === 9
					? elem.defaultView || elem.parentWindow
					: false;
		},
		/**
		 * @see jQuery bodyOffset
		 * @param {Object} body [optional]
		 * @return {Object} { top : int, left : int } ||
		 */
		bodyOffset: function( body ) {
			if( !body ) {
				var body = document.body;
			}
			if( body == null ) { return null; }
			var $body = $( body ),
				top = body.offsetTop,
				left = body.offsetLeft;

			if ( body.offsetTop !== parseFloat( $body.getStyle( "marginTop" ) ) ) {
				top  += parseFloat( $body.getStyle( "marginTop" ) ) || 0;
				left += parseFloat( $body.getStyle( "marginLeft" ) ) || 0;
			}

			return { top: top, left: left };
		},
		/**
		 * @see jQuery getPosition
		 * @return {Object} { top : int, left : int } || null
		 */
		getPosition : function ( elem ) {
			var box;
			if ( !elem || !elem.ownerDocument ) {
				return null;
			}

			if ( elem === elem.ownerDocument.body ) {
				return Publicis.bodyOffset( elem );
			}

			try {
				box = elem.getBoundingClientRect();
			} catch(e) {
				// old plain iterate the whole dom loop
				if ( !elem.viewportOffset ) {
					elem = $( elem );
				}
				var pos = elem.viewportOffset();
				return { top: pos[ 0 ] || 0, left: pos[ 1 ] || 0 };
			}

			if ( !box ) {
				return { top: 0, left: 0 };
			}

			var doc = elem.ownerDocument,
				docElem = doc.documentElement,
				body = doc.body,
				oldBoxModel = Info.browser.isIEpre7,
				win = this.getWindow( doc ),
				clientTop  = docElem.clientTop  || body.clientTop  || 0,
				clientLeft = docElem.clientLeft || body.clientLeft || 0,
				scrollTop  = win.pageYOffset || oldBoxModel && docElem.scrollTop  || body.scrollTop,
				scrollLeft = win.pageXOffset || oldBoxModel && docElem.scrollLeft || body.scrollLeft,
				top  = box.top  + scrollTop  - clientTop,
				left = box.left + scrollLeft - clientLeft;

			return { top: top, left: left };
		},
		getWindowScrollTop : function () {
			var oldBoxModel = Info.browser.isIEpre7,
				win = this.getWindow();

			return ("pageYOffset" in win )
				? win.pageYOffset
				: oldBoxModel && win.document.documentElement.scrollTop
					|| win.document.body.scrollTop;
		},
		trim : ( String.prototype.trim )
			? function( text ) {
				return text == null
					? ""
				: String.prototype.trim.call( text );
			}
			: function( text ) {
				var trimLeft = /^\s+/,
					trimRight = /\s+$/;
				return text == null
					? ""
					: text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
			},

		hasFlash : function () {
			if( typeof this._clientHasFlash === "undefined" ) {
				this._clientHasFlash = ( !! swfobject )
					? this._clientHasFlash = swfobject.getFlashPlayerVersion().major > 0
					: false;
			}
			return this._clientHasFlash;
		},
		/**
		 * @param {String} relative webpath
		 * @return {Boolean} false | {String}
		 */
		getAbsolutePath : function (path) {

			if( ( /http:\/\/|website\.php/i ).test( path )
				|| ! ( /\.\./ ).test( path )
			) {
				return false;
			}

			var queryPath = window.location.pathname,
				queryParts = queryPath.split(/\//),
				parts = path.split(/\//),
				filename = "",
				reverseCounter = 0,
				_slice = Array.prototype.slice,
				tmp = [];


			filename = parts.pop();

			queryParts.each( function ( val, key ) {
				if( !! val ) {
					tmp.push( val );
				}
			} );

			if( (/\./).test( queryParts[ queryParts.length - 1] ) ) {
				reverseCounter += 1;
			}
			queryParts = _slice.call( tmp, 0 );
			tmp = [];

			parts.each( function ( val, key ) {
				if( ! val ) {
					return;
				}
				if( val != ".." ) {
					tmp.push( val );
				} else {
					reverseCounter += 1;
				}
			} );
			parts = _slice.call( tmp, 0 )

			for( i = 0; i < reverseCounter; i++ ) {
				queryParts.pop();
			}

			filename = queryParts.join( '/' ) + '/'+ parts.join( '/' ) + '/' +  filename;
			if( "/" != filename.substr( 0, 1) ) {
				filename = "/" + filename;
			}
			return filename;
		},
		/**
		 * @param mixed data : array or object
		 * @param {Function} fn
		 * @param {Object} scope
		 */
		each : function( data, fn, scope ) {
			scope = scope || null;
			if( typeof data === "undefined" ) {
				return;
			}
			if( data.prototype && data.prototype.forEach ) {
				data.forEach( fn, scope );
			} else {
				for( var i in data ) {
					fn.call( scope, data[ i ], i );
				}
			}
		},
		/**
		 * @returns {Boolean}
		 */
		isObject : function ( o ) {
			o = o || null;
			return ({}).toString.call( o ) == '[object Object]';
		},
		size : function( o ) {
			if( this.isArray( o ) ) { return o.length; }
			if( ! this.isObject ) {
				return 0;
			}
			var size = 0,
				key;

			for( key in o ) {
				if( o.hasOwnProperty( key ) ) {
					size += 1;
				}
			}
			return size;
		},
		/**
		 * @param {Mixed} elem
		 * @param {Array} array
		 */
		indexOf : function( elem, array ) {

			if( ! array.length ) {
				return -1;
			}

			if ( Array.prototype.indexOf ) {
				return Array.prototype.indexOf.call( array, elem );
			}

			for ( var i = 0, length = array.length; i < length; i++ ) {
				if ( array[ i ] === elem ) {
					return i;
				}
			}

			return -1;
		}
	};
}();

/**
 * @class Publicis.Format
 * Helper class for formatting
 * @singleton
 * @author Alexis Dorn
 */
Publicis.Format = {
		/**
		 * Converts a Byte Integer into formatted string (Unities: b, KB, MB, GB, TB)
		 * @param {Integer} val
		 * @return String
		 */
		convertBytes: function (val){
			var bytes = parseInt(val, 10);
			var precision = 1;
			if (!isNaN(bytes)){
				var units = ['B', 'KB', 'MB', 'GB', 'TB'];
				bytes = Math.max(bytes, 0);
				var pow = Math.floor((bytes ? Math.log(bytes) : 0) / Math.log(1024));
				pow = Math.min(pow, units.length - 1);
				bytes = bytes / Math.pow(1024, pow);
				var coefficient = Math.pow(10, precision);
				val =  (Math.round(bytes * coefficient) / coefficient)  + ' ' + units[pow];
			}
			return val;
		},
		/**
		 * Converts a Unix Timestamp into a Dateobject
		 * @param {Integer} tmStmp
		 * @return Date
		 */
		timeStamp2Date: function (tmStmp){
			 return  new Date(tmStmp * 1000);
		},
		/**
		 * Uses the SCAL prototyping of Date (http://scal.fieldguidetoprogrammers.com)
		 * @param {Date} date
		 * @param {String} format (yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)
		 * @return String
		 */
		formatDate: function (date, format){
			return date.format(format);
		}

};

/**
 * @class Publicis.Layer
 * @namespace Publicis
 * @extends Layer
 * <b>Extends Layer</b> of virtual identity AG script (see \root\framework\_resources\js\compiled\script.js)
 * @constructor
 * Creates a new layer<br><br>
 * see \root\framework\_resources\js\compiled\script.js for documentation
 * @param {Object} config
 * @author Alexis Dorn
 */

Publicis.Layer = function (config){
	this.config = Object.clone(config);
	/**
	 * @cfg {Element} node <b>Obligatory:</b> Container Element of Layer
	 */
	var node = config.node;
	/**
	 * @cfg {Element} trigger: the click event of this DOM Node will open the Layer
	 */
	var trigger = config.trigger;
	/**
	 * the clicked element that opened
	 * @var {Element}
	 */
	this.opener = null;

	Publicis.Layer.superclass.constructor.call(this, node, trigger);
	this.pubObserver = new Publicis.Observable({});
	this.pubObserver.registerEvent([
		/**
		 * @event beforeopen
		 * Fires before component is open. Return false to stop open.
		 * @param {Publicis.Layer} this
		 */
		"beforeopen",
		/**
		 * @event open
		 * Fires when component is open
		 * @param {Publicis.Layer} this
		 */
		"open",
		/**
		 * @event beforeclose
		 * Fires before component is close. Return false to stop closing.
		 * @param {Publicis.Layer} this
		 */
		"beforeclose",
		/**
		 * @event close
		 * Fires when component is closed
		 * @param {Publicis.Layer} this
		 */
		"close"
	]);
};


(function () {

if( typeof Layer === "undefined" ) {
	return;
}

Publicis.extend(Publicis.Layer, Layer, {
	initialize: function(node, trigger) {
		this.initSuper(node, trigger);
	},
	/**
	 * @private
	 */
	afterOpen: function(){
		this.pubObserver.fireEvent("open", this);
		return Publicis.Layer.superclass.afterOpen.call(this);
	},
	/**
	 * @private
	 */
	afterClose: function(newLayer) {
		this.pubObserver.fireEvent("close", this);
		return Publicis.Layer.superclass.afterClose.call(this, newLayer);
	},
	/**
	 * @private
	 */
	beforeClose: function() {
		if (this.pubObserver.fireEvent("beforeclose", this) === false){
			return;
		}
		return Publicis.Layer.superclass.beforeClose.call(this);
	},
	/**
	 * @private
	 */
	beforeOpen: function() {
		if (this.pubObserver.fireEvent("beforeopen", this) === false){
			return;
		}
		return Publicis.Layer.superclass.beforeOpen.call(this);
	},
	/**
	 * hides thelayer
	 */
	hide: function() {
		this.node.hide();
	},
	/**
	 * show layer
	 */
	show: function() {
		this.node.show();
	},
	/**
	 * Adds a callback to a event
	 * @param {String} eventname
	 * @param {Function} callback The function that will be called as callback
	 * @param {Object} scope The this scope in callback function
	 */
	addListener: function (eventname, callback, scope){
		this.pubObserver.addListener(eventname, callback, scope);
	},
	/**
	 * Disables firing of all Events, until you will call enableEvents again
	 */
	disableEvents: function (){
		this.pubObserver.disableEvents();
	},
	/**
	 * Enables firing of all Events, after you disableEvents has been called
	 */
	enableEvents: function (){
		this.pubObserver.enableEvents();
	},
	/**
	 * overwrite parent to make an array or trigger elements available
	 * bind Events to any given trigger
	 * @param {Element} node
	 * @param {Array} trigger
	 */
	initSuper: function(node, trigger) {
		if(!Publicis.isArray (trigger)) {
			this.opener = trigger;
			return Publicis.Layer.superclass.initSuper.call(this, node, trigger);
		}
		this.node   = node;
		this.isOpen = false;
		this.trigger = trigger || null;
		if(this.trigger.length == 0) {
			return;
		}
		for (var i in this.trigger) {
			if(typeof(this.trigger[i]) !== "object" || !this.trigger[i].nodeType) {
				continue;
			}
			this.trigger[i].observe("click", function(e) {
				this.toggle(e);
				Event.stop(e);
			}.bindAsEventListener(this));
		}
		if (Info.browser.isIEpre7) {
			this.iframeLining = new IframeLining(this.node);
			this.correctIframe();
		}
	},
	/**
	 * overwrite parent method to detect lightbox opener
	 */
	toggle: function(e) {
		if (!this.isOpen && typeof(e) !== "undefined") {
			this.opener = $(Event.element(e));
		}
		Publicis.Layer.superclass.toggle.call(this);
	}
});

/**
 * @class Publicis.Lightbox
 * @namespace Publicis
 * @extends Layer
 * <b>Extends Layer and ContentLayer</b> of virtual identity AG script (see \root\framework\_resources\js\compiled\script.js)
 * @constructor
 * Creates a new lightbox layer<br><br>
 * see \root\framework\_resources\js\compiled\script.js for documentation
 * @param {Object} config
 * @author Alexis Dorn
 * @author Sebastian Sauer
 */
Publicis.Lightbox = function (config){
	this.body = $(document.getElementsByTagName("body")[0]);
	/**
	 * be sure to extend the whitelist if you wanna register a new content box type
	 */

	var existingTypes = [ "content", "feature", "video", "gallery", "socialbookmarks", "form" ],
		layerType = "",
		defaultSettings = {},
		i;

	if(typeof config.layerType !== "undefined" && typeof config.layerType === "string") {
		for ( i in existingTypes ) {
			if(existingTypes[i] == config.layerType) {
				layerType = existingTypes[i];
				break;
			}
		}
	}

	/**
	 * @cfg {String} layerType Style of layer, can be in array existingTypes or "feature" (default)
	 */
	this.layerType = (layerType == "") ? "feature" : layerType;
	switch (this.layerType) {
		case "socialbookmarks" :
			defaultSettings = {
				classPrefix : "socialbookmarks",
				idContainerPrefix : "socialbookmarks_content_container_",
				idButtonPrefix : "socialbookmarks_content_closebutton_",
				width : 278,
				height : 347,
				top : 235,
				left: 683
			}
			break;
		case "video" :
			defaultSettings = {
				classPrefix : "contentlayer_2",
				idContainerPrefix : "videolayer__content_container_",
				idButtonPrefix : "videolayer_content_closebutton_",
				width : 800,
				height : 600,
				top : 116,
				left: 44
			}
			break;
		case "gallery" :
			defaultSettings = {
				classPrefix : "gallerylayer contentlayer_2",
				idContainerPrefix : "gallerylayer__content_container_",
				idButtonPrefix : "gallerylayer_content_closebutton_",
				width : 640,
				height : 600,
				top : 116,
				left: 44
			}
			break;
		case "content" :
			defaultSettings = {
				classPrefix : "contentlayer_2",
				idContainerPrefix : "contentlayer_2_content_container_",
				idButtonPrefix : "contentlayer_2_content_closebutton_",
				width : 640,
				height : 480,
				top : 116,
				left: 44
			}
			break;
		case "form" :
			defaultSettings = {
				classPrefix : "contentlayer_2",
				idContainerPrefix : "contentlayer_2_content_container_",
				idButtonPrefix : "contentlayer_2_content_closebutton_",
				width : 500,
				height : 480,
				top : 116,
				left: 44
			}
			break;
		case "feature" :
		default :
			defaultSettings = {
				classPrefix : "webfeature_b2",
				idContainerPrefix : "webfeature_container_b2_swf_container_",
				idSwfPrefix : "webfeature_container_b2_swf_container_",
				idButtonPrefix : "webfeature_container_b2_closebutton_",
				width : 960,
				height : 393,
				top : 116,
				left: 14
			}
	}
	/**
	 * @cfg {String} id Identifier of component
	 */
	this.id = (typeof config.id == "undefined") ? Publicis.uniqueId () : config.id;
	/**
	 * @cfg {String} idContainer DOM ID of outer container
	 */
	this.idContainer = (typeof config.idContainer == "undefined") ? defaultSettings.idContainerPrefix + this.id : config.idContainer;
	/**
	 * @cfg {String} idSwf: DOM ID of SWF container
	 */
	if(typeof defaultSettings.idSwfPrefix === "undefined") {
		this.idSwf = null;
	} else {
		this.idSwf = (typeof config.idSwf === "undefined") ? defaultSettings.idSwfPrefix + this.id : config.idSwf;
	}
	/**
	 * @cfg {DOMNode} node This configuration will be set automatically
	 */
	/**
	 * @cfg {String} idButton DOM ID of button
	 */
	this.idButton = (typeof config.idButton === "undefined") ? defaultSettings.idButtonPrefix + this.id : config.idButton;

	/**
	 * @cfg {Number} height Height of the outer box
	 */
	this.height = (typeof config.height === "number") ? config.height : defaultSettings.height;
	/**
	 * @cfg {Number} width Width of the outer box
	 */
	this.width = (typeof config.width === "number") ? config.width : defaultSettings.width;
	/**
	 * @cfg {Number} top Top Position (default: 116)
	 * shouldn't be overwritten, otherwise comment out (see siemens style guide)
	 */
	this.top = defaultSettings.top;
	//this.top = (typeof config.top !== "number") ? defaultSettings.top : config.top;
	/**
	 * @cfg {Number} left Left Position (layerType = default: 14, layerType = content: 44)
	 * shouldn't be overwritten, otherwise comment out (see siemens style guide)
	 */
	this.left = defaultSettings.left;
	//this.left = (typeof config.left !== "number") ? defaultSettings.left : config.left;

	/**
	 * @cfg {String} classPrefix Css Class Prefix/Container CSS Class (layerType = feature: webfeature_b2, layerType = content: webfeature_xyz)
	 */
	this.classPrefix = defaultSettings.classPrefix;

	/**
	 * @cfg {boolean} scrollTop Scroll Browser to Top Position on Open. default: true
	 */
	this.scrollTop = (typeof config.scrollTop === "boolean") ? config.scrollTop : true;

	//Only renders html
	this.render();

	//obligatory configuration of superclass
	config.node = $(this.idContainer);
	// set style by cfg
	config.node.setStyle({
		width: this.width.toString() + 'px',
		height: this.height.toString() + 'px',
		top: this.top.toString() + 'px',
		left: this.left.toString() + 'px'
	});

	Publicis.Lightbox.superclass.constructor.call(this, config);

	this.formerLogoZIndex = false;
	this.logoContainer = document.getElementById("logo");
	if (this.logoContainer === null){
		this.logoContainer = false;
	}
	this.addListener("open", function (){
		if (this.scrollTop) {
			scrollTo(0,0);
		}
		this.adaptModalLayerToWindow();
		this.modalLayer.show();
		this.modalLayer.setOpacity(0.9);
		if (this.logoContainer){
			var el = $(this.logoContainer);
			//bug in ie, change of z-index will be displayed only on absolute positioned elements
			if (Prototype.Browser.IE) {
				var logo = new Element('p', { 'class' : 'logo_ie_fix' });
				this.modalLayer.update(logo);
			} else {
				this.formerLogoZIndex = el.getStyle("z-index");
				el.setStyle({
					zIndex: "10001"
				});
			}
		}
	}, this);
	this.addListener("close", function (){
		this.modalLayer.hide();
		if (this.logoContainer && !Prototype.Browser.IE){
			this.logoContainer.style.zIndex = this.formerLogoZIndex;
		}
	}, this);

	//Event close button
	$(this.idButton).observe("click", this.close.bindAsEventListener(this));
	//adapting modallayer onresize
	Event.observe(window, "resize", this.adaptModalLayerToWindow.bindAsEventListener(this))

	this.modalLayer = false;

	this.renderModalLayer();
};
Publicis.extend (Publicis.Lightbox, Publicis.Layer, {
	/**
	 * @private
	 */
	render: function (){
		this.body.insert({
			bottom: this.getTemplate().evaluate({
				id: this.id,
				idContainer: this.getIdLightboxContainer(),
				idSwf: this.getIdSwfContainer(),
				idButton: this.getIdButton(),
				classPrefix : this.classPrefix
			})
		});
	},
	/**
	 * @private
	 */
	renderModalLayer: function (){
		this.modalLayer = new Element ("div", {
			style: "display:none;",
			className: "webfeature_b2_overlay"
		});
		this.body.insert({bottom: this.modalLayer});
	},
	/**
	 * @private
	 */
	adaptModalLayerToWindow: function(){
		if (!this.isOpen){
			return;
		}
		var pageSize = this.getPageSize();
		var scrollLeft = 0;
		if (document.documentElement.scrollLeft){
			scrollLeft = document.documentElement.scrollLeft;
		}
		if (window.pageXOffset){
			scrollLeft = window.pageXOffset;
		}
		if (window.scrollMaxX){
			scrollLeft = window.scrollMaxX;
		}

		this.modalLayer.offsetHeight.position = "relative";
		this.modalLayer.style.height = pageSize.vHeight+ "px";
		this.modalLayer.style.width = "100%";
		if (scrollLeft > 0){
			this.modalLayer.style.width = (this.modalLayer.getWidth() + scrollLeft) + "px";
		}
	},
	/**
	 * @private
	 * todo: getting real width
	 */
	getPageSize: function() {
		// document dimensions
		this.pageSize = {};
		var vWidth, vHeight;
		if (window.innerHeight && window.scrollMaxY) {
			vWidth = document.body.scrollWidth;
			vWidth = window.innerWidth;
			vHeight = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			vWidth = document.body.scrollWidth;
			vHeight = document.body.scrollHeight;
		} else {
			vWidth = document.body.offsetWidth;
			vHeight = document.body.offsetHeight;
		};
		return this.pageSize = {
			vWidth: vWidth,
			vHeight: vHeight
		};
	},
	getIdLightboxContainer: function () {
		return this.idContainer;
	},
	getIdSwfContainer: function (){
		return this.idSwf;
	},
	getIdButton: function (){
		return this.idButton;
	},
	/**
	 * Gets the prototype search template for thesearch area
	 * @return Template See Prototype documentation
	 * @private
	 */
	getTemplate: function (){
		if (this.template instanceof Template){
			return this.template;
		}
		switch (this.layerType) {
			case "socialbookmarks" :
				this.template = new Template([
					'<div id="#{idContainer}" class="#{classPrefix}_layer" style="display:none;">',
						'<div id="share_#{idContainer}" class="#{classPrefix}_container"></div>',
						'<div class="socialbookmarks_close_layer">',
							'<a href="javascript:void(null);" class="socialbookmarks_close" id="#{idButton}"></a>',
						'</div>',
					'</div>'
				].join(""));
				break;
			case "content" :
				this.template = new Template([
  	      			'<div id="#{idContainer}" class="#{classPrefix}" style="display:none;">',
  	      				'<div id="contentlayer2_#{idContainer}_frame" class="#{classPrefix}_swf"></div>',
  	      				'<div class="#{classPrefix}_close_layer">',
  	      					'<a href="javascript:void(null);" class="#{classPrefix}_close" id="#{idButton}"></a>',
  	      				'</div>',
  	      			'</div>'
  	      		].join(""));
				break;
			case "video" :
				this.template = new Template([
	      			'<div id="#{idContainer}" class="#{classPrefix}" style="display:none;">',
	      				'<div id="videolayer_#{idContainer}" class="#{classPrefix}_video"></div>',
	      				'<div class="#{classPrefix}_close_layer">',
	      					'<a href="javascript:void(null);" class="#{classPrefix}_close" id="#{idButton}"></a>',
	      				'</div>',
	      			'</div>'
		      	].join(""));
	      		break;
			case "gallery" :
				this.template = new Template([
	      			'<div id="#{idContainer}" class="#{classPrefix}" style="display:none;">',
					'<div class="#{classPrefix}_navi clearfix"><a href="javascript:void(null);"><span>&laquo;</span> Previous</a><a href="javascript:void(null);">Next <span>&raquo;</span></a></div>',
	      				'<div id="gallerylayer_#{idContainer}" class="#{classPrefix}_content"></div>',
	      				'<div class="#{classPrefix}_close_layer">',
	      					'<a href="javascript:void(null);" class="#{classPrefix}_close" id="#{idButton}"></a>',
	      				'</div>',
	      			'</div>'
		      		].join(""));
	      			break;
			case "form" :
				this.template = new Template([
	      			'<div id="#{idContainer}" class="#{classPrefix}" style="display:none;">',
	      				'<div class="iframecontainer"></div>',
						'<div class="#{classPrefix}_close_layer">',
	      					'<a href="javascript:void(null);" class="#{classPrefix}_close" id="#{idButton}"></a>',
	      				'</div>',
	      			'</div>'
		      	].join(""));
	      		break;
			case "feature" :
			default :
				this.template = new Template([
	      			'<div id="#{idContainer}" class="#{classPrefix}" style="display:none;">',
	      				'<div id="#{idSwf}" class="#{classPrefix}_swf"></div>',
	      				'<div class="#{classPrefix}_close_layer">',
	      					'<a href="javascript:void(null);" class="#{classPrefix}_close" id="#{idButton}"></a>',
	      				'</div>',
	      			'</div>'
	      		].join(""));
		}
		return this.template;
	}
});

})();

Publicis.Components = {};
Publicis.ThirdParty = {Spry: {}};

/**
 * @author Sebastian Sauer
 * @namespace GuiSelectProductLayer
 * @extends GuiSelectProductLayer
 *
 */
(function () {

if( typeof( GuiSelectProductLayer ) === "undefined" ) {
	return;
}

Object.extend( GuiSelectProductLayer.prototype, {
	calculateDirection : function () {
		var position = Publicis.getPosition( this.parentContainer ),
			viewPort = Publicis.getViewport(),
			availableSpace = ( viewPort.height + Publicis.getWindowScrollTop() - position.top  ),
			listHeight = ( 10 + this.list.getHeight() );

		if( typeof( this._turnDirection ) === "undefined" ) {
			this.direction = "down";
			this.sortOrder = "down";
		}

		this.direction = ( availableSpace < listHeight ) ? "up" : "down";

		this._turnDirection = false;
		if( this.direction !== this.sortOrder ) {
			this._turnDirection = true;
		}

		this._sortReverse();
	},
	_sortReverse : function () {

		if( !this._turnDirection ) {
			return;
		}

		var nodes = this.list.childElements()
			fragment = document.createDocumentFragment();;
		if( nodes.length < 1) {
			return;
		}
		nodes = nodes.reverse();

		this.list.empty();
		$A( nodes ).each( function ( listEntry ) {
			this.list.insert( listEntry );
		}.bind( this ) );

		this.sortOrder = this.direction;

	}
});

Object.extend( GuiSelectProductLayer.prototype, (function ( orig ) {
    return {
        beforeOpen: function () {
            if( !this.origTopPosition ) {
				this.origTopPosition = this.node.up().getHeight().toString() + "px";
			}
			this.calculateDirection();
            return orig.apply( this, arguments );
        }
    };
})( GuiSelectProductLayer.prototype.beforeOpen ) );

Object.extend( GuiSelectProductLayer.prototype, (function ( orig ) {
    return {
        afterOpen: function () {
            orig.apply( this, arguments );
			if( this.direction && this.direction === "up" ) {
				this.node.style.top = ( -1 * this.node.getHeight() ).toString() + "px";
				this.node.addClassName( "content-upper" );
				if( ! this.scrollbar ) {
					return;
				}

				this.scrollbar.pageEnd();
				return;
			}

			this.node.removeClassName( "content-upper" );
			this.node.style.top = this.origTopPosition;
        }
    };
})( GuiSelectProductLayer.prototype.afterOpen ) );

})();

