/* START: content layer */
var NewsletterLayer = Class.create();

NewsletterLayer.prototype = Object.extend(new Layer, {

    initialize: function(node, trigger) {
        this.node = node;
        this.initSuper(node, trigger);
        var closeButton = Helper.getCloseButton(this.node);
        closeButton.observe("click", function(){this.close();}.bindAsEventListener(this));
        trigger.href="javascript:void(0);";
        if (Info.browser.isIEpre7) {
            this.iframeLining = new IframeLining(this.node);
        }
        this.listener = {'augmentDone' : this.handleOpen.bind(this) };
    },

    open: function() {
        if(HeaderAnimation.diminishable && !HeaderAnimation.augmented) {
            HeaderAnimation.listenerQueue.add(this.listener);
            HeaderAnimation.augment();
        } else {
            Layer.prototype.open.call(this);
        }
    },

    show: function() {
        this.node.setStyle({'display': 'block'});
    },

    hide: function() {
        this.node.setStyle({'display': 'none'});
    },

    beforeOpen: function() {
        if(this.iframeLining)
            this.iframeLining.show();
        return true;
    },

    beforeClose: function() {
        if(this.iframeLining)
            this.iframeLining.hide();
        return true;
    },

    handleOpen: function() {
        HeaderAnimation.listenerQueue.remove(this.listener);
        Layer.prototype.open.call(this);
    }
});
/* END: content layer */
/* START: content layer */
var ContentLayer = Class.create();

ContentLayer.prototype = Object.extend(new Layer, {

    initialize: function(node, trigger) {
        this.node = node;
        this.initSuper(node, trigger);
        
        this.selectedItem = this.trigger.hash;
        
        this.preSelectSector();
        
        var closeButton = Helper.getCloseButton(this.node);

        closeButton.observe("click", function(){this.close();}.bindAsEventListener(this));

        trigger.href="javascript:void(0);";

        if (Info.browser.isIEpre7) {
            this.iframeLining = new IframeLining(this.node);
        }

        //store the listener so it can be accessed by functions add and remove
        this.listener = {'augmentDone' : this.handleOpen.bind(this) };
    },
    preSelectSector: function() {
        if(this.selectedItem) {
            var selArray = this.selectedItem.split("-");
            var selId = "ul"+selArray[0]+" a";
            var selPos = parseInt(selArray[1]);
            var count = 1;

            this.node.select(selId).each(function(item) {
                    if(selPos == count) {
                        item.addClassName('oswp-selected');
                    }
                    count++;
                }.bind(this)
            );
        } else {
            if($('ospw-header')) {
                $$('div#ospw-header a').each(function(item) {item.addClassName('oswp-selected');});
            }
        }
    },

    open: function() {
        if(HeaderAnimation.diminishable && !HeaderAnimation.augmented) {
            HeaderAnimation.listenerQueue.add(this.listener);
            HeaderAnimation.augment();
        } else {
            Layer.prototype.open.call(this);
        }
    },

    show: function() {
        this.node.setStyle({'display': 'block'});
    },

    hide: function() {
        this.node.setStyle({'display': 'none'});
    },

    beforeOpen: function() {
        //calculate top value of layer
        if(!this.headerHeight) this.headerHeight = $('header-zone').getDimensions().height + $('toolbar-zone').getDimensions().height;

        //set the top value with header height
        this.node.setStyle({'display': 'block'});
        if(!this.nodeTop) this.nodeTop = this.headerHeight + parseInt(this.node.getStyle('top'));
        if(!this.nodeLeft) this.nodeLeft = parseInt(this.node.getStyle('top'));
        if(!this.nodeHeight) this.nodeHeight = this.node.getDimensions().height;
        this.node.setStyle({'display': 'none'});

        this.node.setStyle({'top': this.nodeTop+'px'});
        if(this.iframeLining)
            this.iframeLining.show();
        return true;
    },
    
    afterOpen : function() {
        // press filter layer functionality (checkboxes, tracking) 
        if(this.node.hasClassName("filter-layer"))
        {
            if (typeof(FilterLayerHelper) != 'undefined') 
            {
                var filterLayerHelper = new FilterLayerHelper(this);
            }
        }
    },  

    beforeClose: function() {
        if(this.iframeLining)
            this.iframeLining.hide();
        return true;
    },

    handleOpen: function() {
        HeaderAnimation.listenerQueue.remove(this.listener);
        Layer.prototype.open.call(this);
    }
});
/* END: content layer */
/* START: abstract lightbox layer */
var AbstractLightboxLayer = Class.create();
AbstractLightboxLayer.prototype = Object.extend(new Layer, {
    initialize : function(node, trigger, idstring) {
    },
    open : function() {
        if (HeaderAnimation.diminishable && !HeaderAnimation.augmented) {
            HeaderAnimation.listenerQueue.add(this.listener);
            HeaderAnimation.augment();
        } else {
            Layer.prototype.open.call(this);
        }
    },
    show : function() {
        this.node.setStyle( {
            'display' :'block'
        });
    },
    hide : function() {
        this.node.setStyle( {
            'display' :'none'
        });
    },
    beforeOpen : function() {
        //  calculate/set curtain size 
        this.resizeCurtain();

        //position the curtain
        this.curtain.setStyle( {
            'top':  '0px'
        });
        //set the dimensions of layer
        this.node.setStyle( {
            'display' :'block'
        });
        if (!this.nodeTop)
            this.nodeTop = parseInt(this.node.getStyle('top'));
        if (!this.nodeLeft)
            this.nodeLeft = parseInt(this.node.getStyle('left'));
        if (!this.nodeHeight)
            this.nodeHeight = this.node.getDimensions().height;
        this.node.setStyle( {
            'display' :'none'
        });
        
        //check whether layer is higher than current page
        var wrapper = $('footer-position-wrapper');
        this.diff = parseInt(wrapper.getDimensions().height) - this.nodeTop
                - this.nodeHeight;
        if (this.diff < 0) {
            //resize the content zone
            var layerOccupation = this.nodeHeight + this.nodeTop;
            
            //difference between layer height and content height
            var diff2 = $('content-zone').getDimensions().height
                    - layerOccupation;
            $('content-zone').setStyle(
                    {
                        'height' :$('content-zone').getDimensions().height
                                - diff2 + 'px'
                    });
            //  after content-zone resizing, check again curtain size
            this.resizeCurtain();
        }
        ;
        this.node.setStyle( {
            'top' :this.nodeTop + 'px'
        });
        if (this.iframeLining)
            this.iframeLining.show();
        this.curtain.setStyle( {
            'display' :'block'
        });
        return true;
    },
    beforeClose : function() {
        this.curtain.setStyle( {
            'display' :'none'
        });
        if (this.iframeLining)
            this.iframeLining.hide();
        if (this.diff < 0) {
            if (Info.browser.isIE) {
                $('content-zone').setStyle( {
                    'height' :'1%'
                });
            } else {
                $('content-zone').setStyle( {
                    'height' :'auto'
                });
            }
        }
        return true;
    },
    handleOpen : function() {
        HeaderAnimation.listenerQueue.remove(this.listener);
        Layer.prototype.open.call(this);
    },
    resizeCurtain : function() {
        
        if(this.curtain) {
            var wrapper = $('footer-position-wrapper').getDimensions();
            var curtainHeight = parseInt(wrapper.height);
            var header = $('header-zone').getDimensions();
            var toolbar = $('toolbar-zone');

            this.contentHeight = parseInt(wrapper.height) - parseInt(header.height) - parseInt(toolbar.getDimensions().height);
            this.contentWidth = wrapper.width;
            //982px is toolbar min-width (926px) plus its margins (34px left + 22px right)
            if(this.contentWidth < 982) {
                this.contentWidth = 982;
            }
            

            // add footer pagetools height to curtain height - if there are footer page tools 
            /*
            if ($('footer-pagetools-zone')) {
                var footer_pagetools_height = parseInt($('footer-pagetools-zone').getDimensions().height);
                // add 1px due to positioning of the footer pagetools
                curtainHeight += footer_pagetools_height + 1;
            }
            */
            this.curtain.setStyle({'height': curtainHeight +'px','width': this.contentWidth+'px'});
            if(this.iframeLining) {
                this.iframeLining.refresh();
            }
        }

        
    }
});
var InlineLightboxLayer = Class.create();
InlineLightboxLayer.prototype = Object.extend(new AbstractLightboxLayer, {
    initialize : function(node, trigger, idstring) {
        if (pageType == "1" || pageType == "2")
            return;
        this.idstring = idstring;
        this.layerIdstring = "layer-content-" + idstring;
        this.node = node;
        this.curtainidstring = "lightbox-curtain" + idstring;
        this.replacer = "replacer-" + idstring;
        this.videoContent = false;
        this.initSuper(node, trigger);
        var closeButton = Helper.getCloseButton(this.node);
        closeButton.observe("click", function() {
            this.close();
        }.bindAsEventListener(this));
        trigger.href = "javascript:void(0);";
        new Insertion.After($('content-zone'), "<div id='"
                + this.curtainidstring
                + "' class='lightbox-curtain'>&nbsp;</div>");
        this.curtain = $(this.curtainidstring);
        //this.resizeCurtain();
        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));
        new Insertion.After($(this.idstring), "<div id='" + this.replacer
                + "'>&nbsp;</div>");
        var content = $(this.idstring);
        $(this.idstring).remove();
        $(this.layerIdstring).appendChild(content);
    },
    afterOpen : function() {
        if (typeof fireSifrHandler == 'function') {
            fireSifrHandler();
        }
        
        /*  rewrite video content (must be saved in global array) into layer    */
        if(this.videoContent)layerContent[this.idstring].write(this.idstring);
    },
    afterClose : function() {
        /*  check if layer consists of flash/video content  */
        /*  delete layer content for stopping flash/video in IE */
        this.contentVideoCheck();
        if(this.videoContent) $(this.layerIdstring).down().innerHTML = "";
    },
    contentVideoCheck: function() {
        if ( $$("#"+this.idstring + ' embed[class=sIFR-flash]').length || $$("#"+this.idstring + ' object[class=sIFR-flash]').length)
        {
            /*  sifr Object */
            this.videoContent = false;
        } else
        {
            /*  flash/video object  */
            this.videoContent = true;
        }
            
    }
});
var ExternalLightboxLayer = Class.create();
ExternalLightboxLayer.prototype = Object
        .extend(
                new AbstractLightboxLayer,
                {
                    initialize : function(node, trigger, idstring) {
                        if (pageType == "1" || pageType == "2")
                            return;
                        this.idstring = idstring;
                        this.layerIdstring = "layer-content-" + idstring;
                        this.node = node;
                        this.iframehref = trigger.href;
                        this.iframeidstring = "iframe-" + idstring;
                        this.iframeisloaded = false;
                        this.iframeheight = 50;
                        this.curtainidstring = "lightbox-curtain" + idstring;
                        var iframe = document.createElement('iframe');
                        iframe.setAttribute('id', this.iframeidstring);
                        iframe.setAttribute('name', this.iframeidstring);
                        iframe.setAttribute('src', "about:blank");
                        iframe.setAttribute('height', this.iframeheight + 'px');
                        iframe.setAttribute('width', '100%');
                        iframe.setAttribute('frameBorder', '0');
                        iframe.setAttribute('border', '0');
                        iframe.setAttribute('marginwidth', '0');
                        iframe.setAttribute('marginheight', '0');
                        iframe.setAttribute('scrolling', 'no');
                        this.initSuper(node, trigger);
                        var closeButton = Helper.getCloseButton(this.node);
                        closeButton.observe("click", function() {
                            this.close();
                        }.bindAsEventListener(this));
                        trigger.href = "javascript:void(0);";
                        new Insertion.After($('content-zone'), "<div id='"
                                + this.curtainidstring
                                + "' class='lightbox-curtain'>&nbsp;</div>");
                        this.curtain = $(this.curtainidstring);
                        //this.resizeCurtain();
                        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.layerIdstring).appendChild(iframe);
                    },
                    afterOpen : function() {
                        if (!this.iframeisloaded) {
                            this.setIFrameLocation();
                            this.iframeisloaded = true;
                        }
                        else if(this.iframehref != this.iframecurrenthref) {
                            this.setIFrameLocation();
                        }
                        else {
                            this.correctCurtain();
                        }
                    },
                    afterClose : function() {
                        $(this.iframeidstring).src = 'about:blank';
                        this.iframeheight = 50;
                        this.iframeisloaded = false;
                    },
                    setIFrameLocation : function() {
                        new Insertion.Before($(this.iframeidstring),
                                "<div id='lightbox-preloader'>&nbsp;</div>");
                        Event.observe($(this.iframeidstring), 'load', function(
                                e) {
                            this.rechunkIFrame(e);
                        }.bindAsEventListener(this));
                        $(this.iframeidstring).style.visibility = 'hidden';
                        $(this.iframeidstring).src = this.iframehref;
                    },
                    correctCurtain : function() {
                        if (this.curtain) {
                            
                            var wrapper = $('footer-position-wrapper').getDimensions();
                            var header = $('header-zone').getDimensions();
                            var toolbar = $('toolbar-zone');
                            var footer = $('footer-zone');
                            
                            //  complete height of layer (close Button + iframe content)
                            var iframeLayerHeight = $(Layer.current.layerIdstring).up().up().getDimensions().height;
                            // total height for curtain/shadow 
                            var wrapperHeight = parseInt(wrapper.height);                       
                            //  layer top position + layer height
                            var iframeHeightTotal = parseInt(iframeLayerHeight) + parseInt(this.nodeTop);
                            
                            // occupied space for the iframe in the content zone
                            //var iframeHeightInContentZone = iframeHeightTotal - (parseInt(header.height) + parseInt(toolbar.getDimensions().height));

                            //  if layer distance (page top to the lower edge of the layer) is greater than current curtain, then correct curtain
                            //  easy: if iframe greater than page

                            //  < + footer.getDimensions().height
                            if (wrapperHeight < iframeHeightTotal) {
                                
                                var contentHeightNew = iframeHeightTotal - header.height - toolbar.getDimensions().height; 
                                this.diff = -1;
                                //  resize content-zone height to total iframe/layer height + position top
                                $('content-zone').setStyle( {
                                    'height' :contentHeightNew + 'px'
                                });
                                
                                this.contentHeight = contentHeightNew;
                                this.contentWidth = parseInt(wrapper.width);
                                this.curtain.setStyle( {
                                    'height' :parseInt($('footer-position-wrapper').getDimensions().height) + 'px',
                                    'width' : this.contentWidth + 'px'
                                });                                 
                                if (this.iframeLining) {
                                    this.iframeLining.refresh();
                                }
                            }
                            else {
                                // no correction, but scroll to content (if lightbox is opened in footer etc)
                                $('footer-position-wrapper').scrollTo();
                            }
                        }
                    },
                    rechunkIFrame : function(loadevt) {
                        //  afterClose: sets iframe src=about:blank (IE video hack)
                        //  ==> fires this function
                        //  ==> layer/iframe already closed -> skip this function
                        if(!Layer.current) return;
                        var crossevt = (window.event) ? event : loadevt
                        var iframeroot = (crossevt.currentTarget) ? crossevt.currentTarget
                                : crossevt.srcElement
                        if (iframeroot) {
                            if (iframeroot.contentWindow) {
                                
                                // set background image to none instead of empty URL (fixes Safari 3.2 bug)                             
                                //iframeroot.contentWindow.document.body.style.backgroundImage = "url('')";
                                iframeroot.contentWindow.document.body.style.backgroundImage = "none";
                                iframeroot.contentWindow.document.body.style.backgroundColor = '#fff';
                                if (iframeroot.contentWindow.document
                                        .getElementById('logo')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('logo').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('header-zone')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('header-zone').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('toolbar-zone')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('toolbar-zone').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('breadcrumb-zone')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('breadcrumb-zone').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('footer-zone')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('footer-zone').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('content-zone')) {
                                    var contZone = $(iframeroot.contentWindow.document.getElementById('content-zone'));
                                    contZone.style.marginLeft = '0px';
                                    //if(Info.browser.isIEpre7)contZone.style.marginLeft = '-14px';

                                    contZone.down('.left-content').setStyle({'padding': '0px','margin': '0px'});
                                    //contZone.down('.left-content').setStyle({'margin': '0px'});
                                    contZone.down('.right-content').setStyle({'margin': '66px 0px 0px 58px'});
                                }   
                                if (iframeroot.contentWindow.document.getElementById('footer-pagetools-zone')) {
                                    var foPageZone = $(iframeroot.contentWindow.document.getElementById('footer-pagetools-zone'));
                                    foPageZone.setStyle({'top': '0px','width': '699px', 'marginLeft': '0px'});
                                    if(Info.browser.isIEpre7)foPageZone.setStyle({'top': '-1px'});
                                }
                                if (iframeroot.contentWindow.document.getElementById('footer-position-placeholder')) {
                                    iframeroot.contentWindow.document.getElementById('footer-position-placeholder').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document.getElementById('footer-position-wrapper')) {
                                    iframeroot.contentWindow.document.getElementById('footer-position-wrapper').style.marginBottom = '0px';
                                }
                                // remove left column in press rss/newsletter layer + TV registration layer
                                if (iframeroot.contentWindow.document
                                        .getElementById('ospw-lhc')) {
                                    iframeroot.contentWindow.document
                                            .getElementById('ospw-lhc').style.display = 'none';
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('photonews-wide-column')) {
                                    $(iframeroot.contentWindow.document.getElementById('photonews-wide-column')).setStyle({'margin': '0px', 'width':'698px'});
                                }
                                if (iframeroot.contentWindow.document
                                        .getElementById('ospw-rhc')) {
                                    var tvOspwRhc = $(iframeroot.contentWindow.document.getElementById('ospw-rhc'));
                                    if(tvOspwRhc.down('.ospw-wide-column')) tvOspwRhc.down('.ospw-wide-column').style.margin = "0px";
                                }
                                
                                /*
                                // press release: remove margins to fit styleguide 1.4
                                if (iframeroot.contentWindow.document.getElementById('llhc')) {
                                    var llhc = $(iframeroot.contentWindow.document.getElementById('llhc')); 
                                    llhc.down().setStyle({'marginTop': '-4px', 'marginLeft': '0px'});
                                }
                                *                                   
                                // press picture: footer pagetool positioning
                                /*
                                if (iframeroot.contentWindow.document.getElementById('lrhc')) {
                                    var lrhc = $(iframeroot.contentWindow.document.getElementById('lrhc'));
                                    if(lrhc.getStyle('marginLeft') == '50px'){
                                        lrhc.setStyle({'marginLeft': '58px'});
                                    }
                                }
                                */
                                if (iframeroot.contentWindow.document
                                        .getElementById('content-zone')) {
                                    var h = iframeroot.contentWindow.document
                                            .getElementById('content-zone').offsetHeight + 0;
                                    iframeroot.height = h;
                                    this.iframeheight = h;
                                }
                            }
                            else if (iframeroot.contentDocument) {
                                
                                iframeroot.contentDocument.document.body.style.backgroundImage = "url('')";
                                iframeroot.contentDocument.document.body.style.backgroundColor = '#fff';
                                if (iframeroot.contentDocument.document
                                        .getElementById('logo')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('logo').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('header-zone')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('header-zone').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('toolbar-zone')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('toolbar-zone').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('breadcrumb-zone')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('breadcrumb-zone').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('footer-zone')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('footer-zone').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('content-zone')) {
                                    var contZone = $(iframeroot.contentDocument.document.getElementById('content-zone'));
                                    contZone.style.marginLeft = '0px';
                                   // if(Info.browser.isIEpre7)contZone.style.marginLeft = '-14px';
                                    if(Info.browser.isIEpre7)contZone.down('.left-content').setStyle({'padding': '0px'});
                                    contZone.down('.left-content').setStyle({'margin': '0px'});
                                    contZone.down('.right-content').setStyle({'margin': '66px 0px 0px 58px'});
                                }   
                                if (iframeroot.contentDocument.document.getElementById('footer-pagetools-zone')) {
                                    var foPageZone = $(iframeroot.contentDocument.document.getElementById('footer-pagetools-zone'));
                                    foPageZone.setStyle({'top': '0px','width': '699px', 'marginLeft': '0px'});
                                    if(Info.browser.isIEpre7)foPageZone.setStyle({'top': '0px','width': '713px', 'marginLeft': '0px'});
                                }
                                if (iframeroot.contentDocument.document.getElementById('footer-position-placeholder')) {
                                    iframeroot.contentDocument.document.getElementById('footer-position-placeholder').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document.getElementById('footer-position-wrapper')) {
                                    iframeroot.contentDocument.document.getElementById('footer-position-wrapper').style.marginBottom = '0px';
                                }
                                // remove left column in press rss/newsletter layer + TV registration layer
                                if (iframeroot.contentDocument.document
                                        .getElementById('ospw-lhc')) {
                                    iframeroot.contentDocument.document
                                            .getElementById('ospw-lhc').style.display = 'none';
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('photonews-wide-column')) {
                                    $(iframeroot.contentDocument.document.getElementById('photonews-wide-column')).setStyle({'margin': '0px', 'width':'698px'});
                                }
                                if (iframeroot.contentDocument.document
                                        .getElementById('ospw-rhc')) {
                                    var tvOspwRhc = $(iframeroot.contentDocument.document.getElementById('ospw-rhc'));
                                    if(tvOspwRhc.down('.ospw-wide-column')) tvOspwRhc.down('.ospw-wide-column').style.margin = '0px';
                                }
                                
                                /*
                                // press release: remove margins to fit styleguide 1.4
                                if (iframeroot.contentDocument.document.getElementById('llhc')) {
                                    var llhc = $(iframeroot.contentDocument.document.getElementById('llhc')); 
                                    llhc.down().setStyle({'marginTop': '-4px', 'marginLeft': '0px'});
                                }
                                *                                   
                                // press picture: footer pagetool positioning
                                /*
                                if (iframeroot.contentDocument.document.getElementById('lrhc')) {
                                    var lrhc = $(iframeroot.contentDocument.document.getElementById('lrhc'));
                                    if(lrhc.getStyle('marginLeft') == '50px'){
                                        lrhc.setStyle({'marginLeft': '58px'});
                                    }
                                }
                                */
                                if (iframeroot.contentDocument.document
                                        .getElementById('content-zone')) {
                                    var h = iframeroot.contentDocument.document
                                            .getElementById('content-zone').offsetHeight + 0;
                                    iframeroot.height = h;
                                    this.iframeheight = h;
                                }                  
                            } else {
                                return;
                            }
                            
                            
                            
                            this.iframeisloaded = true;
                            if ($('lightbox-preloader')) {
                                $('lightbox-preloader').remove();
                            }
                            this.correctCurtain();
                            $(this.iframeidstring).style.visibility = 'visible';
                            
                            if(iframeroot && iframeroot.contentWindow)
                                iframeroot.contentWindow.initLayout_sifr();
                            if(iframeroot && iframeroot.contentDocument)
                                iframeroot.contentDocument.initLayout_sifr();
                            
                        }
                    }
                });

/* END: external lightbox layer */
var NEWSLETTER_REL_REGEX = /^newsletter-(.+)$/;
var CONTENT_REL_REGEX = /^content-(.+)$/;
var INLIGHTBOX_REL_REGEX = /^in-lightbox-(.+)$/;
var EXTLIGHTBOX_REL_REGEX = /^ext-lightbox-(.+)$/;
var ADDITIONAL_TRIGGER_LINKS_REL_REGEX=/^trigger-(.+)$/;
function init_ext_lightboxLayers( scope ) {
    scope = scope || $$('#content-zone a','#footer-zone a');
    if ($("content-zone")) {
        $A( scope )
                .each(
            function(trigger) {
                trigger = $(trigger);
                if (INLIGHTBOX_REL_REGEX.test(trigger.rel)) { // layer link
                    
                    var id = trigger.rel.replace(INLIGHTBOX_REL_REGEX, "$1");

                    var elm = "<div id='lightbox-layer-"+id+"' class='lightbox-layer'><div class='close'><a href='javascript:void(0);'>";
                    elm += "<span class='access'>Close Layer</span></a></div>";
                    elm += "<div class='layer-content'><div id='layer-content-"+id+"'></div></div></div>";

                    new Insertion.Before($('footer-position-placeholder'), elm);

                    var node = $("lightbox-layer-" + id);
                    var key="lightbox-layer-"+id;
                    GLOBAL_LAYER_CONTROLLER[key]=new InlineLightboxLayer(node,trigger,id);
                    
                } else if (EXTLIGHTBOX_REL_REGEX.test(trigger.rel)) { // layer link
                    
                    var id = trigger.rel.replace(EXTLIGHTBOX_REL_REGEX, "$1");
                    
                    var elm = "<div id='lightbox-layer-"+id+"' class='lightbox-layer'><div class='close'><a href='javascript:void(0);'>";
                    elm += "<span class='access'>Close Layer</span></a></div>";
                    elm += "<div class='layer-content'><div id='layer-content-"+id+"'></div></div></div>";

                    new Insertion.Before($('footer-position-placeholder'), elm);
                    
                    var node = $("lightbox-layer-" + id);
                    var key="lightbox-layer-"+id;
                    GLOBAL_LAYER_CONTROLLER[key]=new ExternalLightboxLayer(node,trigger,id);
                    
                } else if(CONTENT_REL_REGEX.test(trigger.rel)) {
                    
                    var id = trigger.rel.replace(CONTENT_REL_REGEX, "$1");
                    var node = $("content-layer-" + id);
                    var key="content-layer-"+id;
                    GLOBAL_LAYER_CONTROLLER[key]=new ContentLayer(node,trigger);

                } else if(NEWSLETTER_REL_REGEX.test(trigger.rel)) {
                    
                    var id = trigger.rel.replace(NEWSLETTER_REL_REGEX, "$1");
                    var node = $("newsletter-layer-" + id);
                    var key="newsletter-layer-"+id;
                    GLOBAL_LAYER_CONTROLLER[key]=new NewsletterLayer(node,trigger);

                } else if(ADDITIONAL_TRIGGER_LINKS_REL_REGEX.test(trigger.rel)){

                    var manualTriggerId=trigger.rel.replace(ADDITIONAL_TRIGGER_LINKS_REL_REGEX,"$1");
                    
                    Event.observe(trigger,'click',function(e){navigateToLayer(manualTriggerId,trigger.href);Event.stop(e);}.bind(this));
                }
                
            }.bind(this)
        );
    }
    if($('newsletter-layer-infobox')) {
        $A($('newsletter-layer-infobox').getElementsByTagName("a")).each(
            function(trigger) {
                trigger = $(trigger);
                if (EXTLIGHTBOX_REL_REGEX.test(trigger.rel)) { // layer link
                    
                    var id = trigger.rel.replace(EXTLIGHTBOX_REL_REGEX, "$1");

                    var elm = "<div id='lightbox-layer-"+id+"' class='lightbox-layer'><div class='close'><a href='javascript:void(0);'>";
                    elm += "<span class='access'>Close Layer</span></a></div>";
                    elm += "<div class='layer-content'><div id='layer-content-"+id+"'></div></div></div>";

                    new Insertion.Before($('footer-position-placeholder'), elm);

                    var node = $("lightbox-layer-" + id);
                    var key="lightbox-layer-"+id;
                    GLOBAL_LAYER_CONTROLLER[key]=new ExternalLightboxLayer(node,trigger,id);
                }
            }.bind(this)
        );
    }
}
/********************************************************************/
function checkDeepLinks(){
    var param=getUrlParameter("photonewstab");
    if(param){navigateToLayer("lightbox-layer-photonews");}
    param=getUrlParameter("pressnewstab");
    if(param){navigateToLayer("lightbox-layer-pressnews");}
    param=getUrlParameter("rss");
    if(param){navigateToLayer("lightbox-layer-rss");}
    param=getUrlParameter("press");
    if(param){
        var url = 'http://w1.siemens.com/press' + param;
        
        if(window.location.host.indexOf('edit.siemens.dev.publicis.de') > -1) {
            url = 'https://edit.siemens.dev.publicis.de/cc/corp_press/root' + param;
        }
        if(window.location.host.indexOf('stage.siemens.com') > -1) {
            url = 'https://stage.siemens.com/cc/corp/press' + param;
        }
        showUrlExternalLightboxLayer(url);
    }
    
    param=getUrlParameter("tv");
    if(param){
        var language = getUrlParameter("l");
        
        var url = 'https://w1.siemens.com/press/'+language+'/index/tv_details.php?id=' + param;
        
        if(window.location.host.indexOf('edit.siemens.dev.publicis.de') > -1) {
            url = 'https://edit.siemens.dev.publicis.de/cc/corp_press/root/'+language+'/index/tv_details.php?id=' + param;
        }
        if(window.location.host.indexOf('stage.siemens.com') > -1) {
            url = 'https://stage.siemens.com/cc/corp/press/'+language+'/index/tv_details.php?id=' + param;
        }
        showUrlExternalLightboxLayer(url);
    }
}

function showUrlExternalLightboxLayer(url) {
    var trigger = new Element('a', {href: url}).update('show');
    
    var id = "directshow";
    
    var elm = "<div id='lightbox-layer-"+id+"' class='lightbox-layer'><div class='close'><a href='javascript:void(0);'>";
    elm += "<span class='access'>Close Layer</span></a></div>";
    elm += "<div class='layer-content'><div id='layer-content-"+id+"'></div></div></div>";

    new Insertion.Before($('footer-position-placeholder'), elm);
    
    var node = $("lightbox-layer-" + id);
    var key = "lightbox-layer-"+id;
    var layer = new ExternalLightboxLayer(node,trigger,id);
    layer.toggle();

}

document.observe('dom:loaded', function() {
    init_ext_lightboxLayers();
    checkDeepLinks();
});