/*
 * layerOption Objects
 */
var layerOptions = Array();

layerOptions['fullcontent'] = {
		position:	'default',
		idprefix:	'lightbox-layer-',
		curtain:	true,
		iframe:		true,
		forcereload:true,
		src:		null,
		cssClass:	'lightbox-layer publayer-fullcontent',
		callbacks: {
			            rechunkIframe: function (layerframe) {
			                $(layerframe.getElementsByTagName('html')[0]).addClassName('iframe-fullcontent');
			            }
			        }
}

layerOptions['external'] = {
		position:	'default',
		idprefix:	'lightbox-layer-',
		curtain:	true,
		iframe:		true,
		forcereload:true,
		src:		null,
		cssClass:	'lightbox-layer',
		callbacks: {}
}

layerOptions['videolayer458'] = {
		position:	'default',
		idprefix:	'lightbox-layer-',
		curtain:	true,
		iframe:		true,
		forcereload:true,
		src:		null,
		cssClass:	'lightbox-layer videolayer458',
		callbacks: {
			initialize: function() {
				this.debug=false;
			},
			rechunkIframe : function(layerframe) {
				$(layerframe.getElementsByTagName('html')[0]).addClassName('iframe-video-458');
				$(layerframe.getElementById('footer-position-wrapper')).setStyle({'height':'258px', 'overflow':'hidden'});
				//$(layerframe.getElementById('footer-position-placeholder')).setStyle({'height': '0px', 'display' : 'none'});
				//$(layerframe.getElementsByClassName('right-content')[0]).remove();
			},
			afterRechunk: function(layerframe, iframeroot) {			
				if(Info.browser.isIE) {
					iframeroot.height = 258;
				
					if(this.options.curtain) {
						this.correctCurtain();
					}
				}
			}	
		}
}

layerOptions['externalwide'] = {
		position:	'default',
		idprefix:	'lightbox-layer-',
		curtain:	true,
		iframe:		true,
		forcereload:true,
		src:		null,
		cssClass:	'lightbox-layer publayer-wide',
		callbacks: {
			rechunkIframe : function(layerframe) {
				$(layerframe.getElementsByTagName('html')[0]).addClassName('iframe-wide');
				/*
				if(Info.browser.isIE) {
					$A(layerframe.getElementsByTagName('div')).each(function(elm, index) {
							if( (elm.className == '' || elm.className == 'level-3')) {
								$(elm).addClassName('clearfix');
							}
						});
				}
				*/
			},
			afterRechunk: function(layerframe, iframeroot) {			
				/*
				var h, ch, fh = 0;
				if (layerframe.getElementById('content-zone')) {
					ch = layerframe.getElementById('content-zone').offsetHeight + 0;
				}
				if (layerframe.getElementById('footer-zone')) {
					fh = (layerframe.getElementById('footer-zone').offsetHeight + 0) + layerframe.getElementById('footer-position-placeholder').offsetHeight + 0;
				}
				this.iframeheight = ch + fh;
				iframeroot.height = this.iframeheight;
				
				if(this.options.curtain) {
					this.correctCurtain();
				}
				*/
			}				
		}
};

layerOptions['toolbar'] = {
		position: 		'toolbar',
		idprefix:		'toolbar-layer-',
		curtain:		false,
		iframe:			true,
		cssClass:		'toolbar-layer',
		src:			null,
		callbacks:  	{
							initialize: function() { this.debug = false; },
							rechunkIframe: function(iframedoc) {
								var contZone = $(iframedoc.getElementById('content-zone'));
								contZone.style.backgroundColor = '#e7e8eb';
								contZone.down('.right-content').style.display = 'none';
							},
							afterOpen: function() {
								//if no width is set via CSS.. set max width
								if($(this.layerIdstring).style.width == "") {
									var newWidth = $('search-zone').cumulativeOffset().left 
													+ $('search-zone').getDimensions().width 
													- $(this.layerIdstring).up().up().cumulativeOffset().left;
									$(this.layerIdstring).up().up().setStyle({'width': newWidth+"px"});
								}
							}
						}
}

/* Special case, since in /cc/corp_contact/ has content NOT in content-zone */
layerOptions['toolbar-contact'] = {
		position: 		'toolbar',
		idprefix:		'toolbar-layer-',
		curtain:		false,
		iframe:			true, 
		cssClass:		'toolbar-layer',
		src:			null,
		callbacks:  	{
							initialize: function() {
								/* the following 4 functions are needed to show/hide an iframe onunload of the page */
								this.showIFrame =  function () {
							        this.removePreloader();
							    }.bind(this);
							    this.hideIFrame = function () {
							        this.addPreloader()
							    }.bind(this);
							    
							    this.addPreloader = function () {
							        if (!$("lightbox-preloader")) {
							            new Insertion.Before($(this.iframeidstring), "<div id='lightbox-preloader'>&nbsp;</div>")
							        }
							        $(this.iframeidstring).style.visibility = "hidden";
							    }.bind(this);
							    this.removePreloader = function () {
							        if ($("lightbox-preloader")) {
							            $("lightbox-preloader").remove()
							        }
							        $(this.iframeidstring).style.visibility = "visible";
							    }
							},
							afterRechunk: function(layerframe, iframeroot) {			
								var h, ch = 0;
								if (layerframe.getElementById('toolbar-layer-contact')) {
									ch = layerframe.getElementById('toolbar-layer-contact').offsetHeight + 0;
								}
								this.iframeheight = ch;
								iframeroot.height = this.iframeheight;
								
								if(this.options.curtain) {
									this.correctCurtain();
								}
							},
							afterOpen: function() {
								//if no width is set via CSS.. set max width
								if($(this.layerIdstring).style.width == "") {
									var newWidth = $('search-zone').cumulativeOffset().left 
													+ $('search-zone').getDimensions().width 
													- $(this.layerIdstring).up().up().cumulativeOffset().left;
									$(this.layerIdstring).up().up().setStyle({'width': newWidth+"px"});
								}
							}
						}
}

/* Special case, since siteIDlayer has content NOT in content-zone */
layerOptions['toolbar-siteid'] = {
		position: 		'toolbar',
		idprefix:		'toolbar-layer-',
		curtain:		false,
		iframe:			true, 
		cssClass:		'toolbar-layer',
		src:			null,
		callbacks:  	{
							rechunkIframe: function (layerframe) {
								$(layerframe.getElementsByTagName('html')[0]).addClassName('iframe-siteid');
								$(layerframe.getElementsByTagName('html')[0]).removeClassName('iframe');
							},
							afterRechunk: function(layerframe, iframeroot) {
								var h, ch = 0;
								if (layerframe.getElementById('site-id-layer')) {
									ch = layerframe.getElementById('site-id-layer').offsetHeight + 0;
								}
								this.iframeheight = ch;
								iframeroot.height = this.iframeheight;
								
								if(this.options.curtain) {
									this.correctCurtain();
								}
							},
							afterOpen: function() {
								//if no width is set via CSS.. set max width
								if($(this.layerIdstring).style.width == "") {
									var newWidth = $('search-zone').cumulativeOffset().left 
													+ $('search-zone').getDimensions().width 
													- $(this.layerIdstring).up().up().cumulativeOffset().left;
									$(this.layerIdstring).up().up().setStyle({'width': newWidth+"px"});
								}
							}
						}
}

layerOptions['logo'] = {
		position: 		'default',
		idprefix:		'layer-',
		curtain:		true,
		iframe:			false,
		cssClass:		'logolayer',
		src:			'../logolayer.html',
		callbacks:  	{
			initialize: function() {
				new Insertion.Before($('layer-content-logolayer').up(),'<div class="blankline">&nbsp;</div>');
				
				// example for setting src dynamically - relative to the page location 
				// this.options.src = pageVars.root + PAGE_LANG + somevar + ".html";
			},
			afterOpen: function() {
				$$("#layer-content-logolayer 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
				$$("#layer-logolayer li.active a").filter(function(link) {
					return !$(link).hasClassName('c');
				}).each(function(link) {
					link.addClassName("active");
				});
			}
		}
}

layerOptions['share'] = {
		position:		'default',
		idprefix: 		'tools-layer-',
		curtain:		false,
		iframe:			true,
		forcereload:	false,
		cssClass:		'lightbox-layer',
		//src:			'../../apps/share/tools-share.php',
		callbacks: {
				initialize: function() { 
					this.debug = false;
					$('tools-layer-share').setStyle({ width:'276px' }); 
					this.isFooter = false;
					
					if(this.trigger != $('footer-tools-share') ) {
						$('footer-tools-share').href = 'javascript:void(0);';
						$('footer-tools-share').observe("click", function(e) {this.toggle(e);  Event.stop(e); }.bindAsEventListener(this) );
					}
					pubLayer.prototype.correctIframeHeight = function() {
						//fix layerheight if opened in layer
						if(self != top)
						{
							var iframeid = top.Layer.current.iframeidstring;
							var cH = $('content-zone').getHeight();
							var lO = $('tools-layer-share').cumulativeOffset();
							var lH = $('tools-layer-share').getHeight() + lO.top;
							top.document.getElementById(iframeid).height =  $('content-zone').getHeight() < lH ? lH : $('content-zone').getHeight();
						}
					}
				},
				show: function(e) {
					var _parent = {};
					if(e) {
						_parent 	= Event.element(e).up('div'); //Event.findElement(e,'div');
					} else if (this.listener.event) {
						_parent 	= Event.element(this.listener.event).up('div');
					}
			    	if( _parent.id == 'pagetools-zone') {
			    		if(this.debug) this.debugOut("top sharelayer");
			    		var pos 		= $('pagetools-zone').cumulativeOffset();
			    		this.isFooter	= false;
			    		$('tools-layer-share').setStyle({ top: (pos.top + $('pagetools-zone').getHeight() + 5) +'px', left: (pos.left -1)+'px' });
						if(self != top) {
							$('tools-layer-share').setStyle({ left: (pos.left -2)+'px' });
						}
			    	} else {
			    		if(this.debug) this.debugOut("bottom sharelayer");
			    		var footerpos 	= $('footer-pagetools-zone').cumulativeOffset();
			    		var iconpos		= $('footer-tools-share').cumulativeOffset();
			    		this.isFooter	= true;
			    		$('tools-layer-share').setStyle({ top: (footerpos.top + 10 ) +'px', left: (iconpos.left - $('tools-layer-share').getWidth() - 6 )+'px' });
			    	}
					
			        //$("tools-layer-share").addClassName("active-layer");
			        this.trigger.addClassName("clicked"); // avoids hover effect (only for the first time)
			        this.trigger.observe("mouseout",
			            function(e) {
			                this.trigger.removeClassName("clicked");
			                this.trigger.stopObserving("mouseout");
			            }.bindAsEventListener(this)
			        );
			        
			        this.node.setStyle({'display':'block'});
			        
			        if(this.isFooter) {
			        	var footerpos 	= $('footer-pagetools-zone').cumulativeOffset();
			        	var iconpos		= $('footer-tools-share').cumulativeOffset();
			        	$('tools-layer-share').setStyle({ 	top:  ( footerpos.top - $('tools-layer-share').getHeight() + 11 ) +'px',
			        										left: ( iconpos.left - $('tools-layer-share').getWidth() - 4 )+'px' });
						if(Info.browser.isIEpre7) { this.iframeLining.refresh(); }
			        }
			    },
				afterOpen: function() {
					this.correctIframeHeight();
				},
				afterClose: function() {
					this.correctIframeHeight();
				},
			    afterRechunk: function() {
			    	if(this.isFooter) {
			        	var footerpos 	= $('footer-pagetools-zone').cumulativeOffset();
			        	var iconpos		= $('footer-tools-share').cumulativeOffset();
			        	$('tools-layer-share').setStyle({ 	top:  ( footerpos.top - $('tools-layer-share').getHeight() + 11 ) +'px',
			        										left: ( iconpos.left - $('tools-layer-share').getWidth() - 4 )+'px' });
			        	if(Info.browser.isIEpre7) { this.iframeLining.refresh(); }
			        }
					this.correctIframeHeight();
			    }
		}		
}

/********************************************************************/
/* START: Fix for Footer-PageTools Fontsize                         
 * Important: To take effect this .js has to be inlcuded
 *            AFTER VI's script.js and/or module.fontsize.js
*/

function init_fontsize() {
	if ($('pagetools-fontsize') || $('footer-tools-fontsize-decrease') ) {
		var font = new FontSize;
		var title = new Cookie('text-size').read(font.getDefaultStyleSheet());
		font.setActiveStyleSheet(title);
	}
}

FontSize.prototype.setActiveStyleSheetDefault = FontSize.prototype.setActiveStyleSheet;
FontSize.prototype.initializeDefault = FontSize.prototype.initialize;

FontSize.prototype.initialize = function() {
	//this.initializeDefault();
	if ($('pagetools-zone')) {
		$("tools-fontsize-decrease").observe("click", function() {
			this.fontSizeDown();
			this.correctIframe();
		}.bindAsEventListener(this));
		$("tools-fontsize-enlarge").observe("click", function() {
			this.fontSizeUp();
			this.correctIframe();
		}.bindAsEventListener(this));
	}
	
	if($("footer-pagetools-zone")) {
		$("footer-tools-fontsize-decrease").observe("click", function() {this.fontSizeDown(); this.correctIframe();}.bindAsEventListener(this));
		$("footer-tools-fontsize-enlarge").observe("click", function() {this.fontSizeUp(); this.correctIframe();}.bindAsEventListener(this));
	}
};

FontSize.prototype.correctIframe = function() {
	if(self != top)
	{
		var iframeid = top.Layer.current.iframeidstring;
		top.document.getElementById(iframeid).height =  $('content-zone').getHeight();
	}
}

FontSize.prototype.setActiveStyleSheet = function(title) {
	//this.setActiveStyleSheetDefault(title);
	
	var i, a;
	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (/\bstylesheet\b/.test(a.rel) && a.title) {
			a.disabled = true; // always set true first for IE7 
			if (a.title == title) {
				a.disabled = false;
			}
		}
	}

	if($("pagetools-zone")) {
		switch(title) {
			case 'A+':
				$('tools-fontsize-enlarge').removeClassName('deactivated');
				$('tools-fontsize-decrease').removeClassName('deactivated');
				break;
			case 'A++':
				$('tools-fontsize-enlarge').addClassName('deactivated');
				break;
			default:
				$('tools-fontsize-decrease').addClassName('deactivated');
				break;
		}
	}
	
	if($("footer-pagetools-zone")) {
		switch(title) {
			case 'A+':
				$('footer-tools-fontsize-enlarge').removeClassName('deactivated');
				$('footer-tools-fontsize-decrease').removeClassName('deactivated');
				break;
			case 'A++':
				$('footer-tools-fontsize-enlarge').addClassName('deactivated');
				break;
			default:
				$('footer-tools-fontsize-decrease').addClassName('deactivated');
				break;
		}
	}
	
	new Cookie('text-size').write(title, 365 * 24 * 3600);
};
/* END: Fix for Footer-PageTools Fontsize                           */
/********************************************************************/
/* START: Fix for Contact 											*/
function showContactIFrame() {
    var a = GLOBAL_LAYER_CONTROLLER['contact'];
    a.showIFrame();
}
function hideContactIFrame() {
    var a = GLOBAL_LAYER_CONTROLLER['contact'];
    a.hideIFrame();
};
/* END: Fix for Contact                           					*/
/********************************************************************/
/* START: custom tracking implementation for IJS module                              */
/* overwrite submitForm() from script.js to implement custom tracking for IJS module */
function submitForm(id) {
	// custom behaviour for international jobssearch module
	if (id == 'ijs') {
		// #### custom tracking implementation - START ####
		if(!isiPad){
			
			var ijsForm 		= $(id);
			var regionConst 	= 'region';
			var familyConst 	= 'jobfamily';
			var experienceConst = 'experience';
		
			var currentTarget = ijsForm.action;
			var currentInputRegion = ijsForm.select('input[type=hidden][name=' + regionConst + ']').first().readAttribute('value');
			var currentInputFamily = ijsForm.select('input[type=hidden][name=' + familyConst + ']').first().readAttribute('value');
			var currentInputExperience = ijsForm.select('input[type=hidden][name=' + experienceConst + ']').first().readAttribute('value');
			// build custom string as pev2
			var sep = '|';
			var trackingString = 	'ijs_mod' 		+ sep +
								regionConst 	+ '=' + currentInputRegion 	+ sep + 
								familyConst 	+ '=' + currentInputFamily 	+ sep + 
								experienceConst + '=' + currentInputExperience;	
								// send custom link
			if (typeof(s) != 'undefined') {
				s.tl(true, 'e', trackingString);
			}
			// #### custom tracking implementation - END ####
		}
	}
	// default behaviour
	$(id).submit();
}

