//ContentLayer
/**********************************/
/* START: external contact layer */

var ExtToolbarLayer = Class.create();

ExtToolbarLayer.prototype = Object.extend(new Layer, {
    /*
     * @base        : AbstractLightboxLayer
     * @node        : layer div holding the hidden content
     * @trigger     : element that show triggers the layer
     * @idstring    : unique id of trigger rel attribute, so that multiple layers can be instantiated
     */
    initialize: function(node, trigger, idstring) {
        this.navTo = false;
        this.idstring = idstring;
        this.layerIdstring = "toolbar-layer-content-" + idstring;
        this.node = node;
        //this.iframehref = trigger.href;
		if(location.href.match(/stage.siemens.com/))
		{
			this.iframehref = 'https://stage.siemens.com/in/corp_nwa/apps/contact/index.php	';
		}
		else
		{
			this.iframehref = 'http://www.siemens.co.in/apps/contact/index.php';
		}
        this.iframeidstring = "iframe-toolbar-" + idstring;
        this.iframeisloaded = false;
        this.iframeheight = 50;

        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%');
        //use camel case here for frameBorder else IE will ignore this attribute
        iframe.setAttribute('frameBorder', '0');
        iframe.setAttribute('border', '0');
        iframe.setAttribute('marginwidth', '0');
        iframe.setAttribute('marginheight', '0');
        iframe.setAttribute('scrolling', 'no');
        iframe.setAttribute('bgColor', '#e7e8eb');
        iframe.setAttribute('unload', 'hideIt();');
        

        this.initSuper(node, trigger);


        var closeButton = Helper.getCloseButton(this.node);
        if(!closeButton) alert("Implementation Error: no close button found");
        closeButton.observe("click", function(){this.close();}.bindAsEventListener(this));

        trigger.href="javascript:void(0);";

        //appending unique iframe to the layer div
        $(this.layerIdstring).appendChild(iframe);

        if(this.navTo) {
            this.toggle();
        }

    },
    getUrl: function(asName) {
        var lsURL = ((typeof(url) == 'undefined') || (url.length == 0)) ? window.location.href : url;
        loU = lsURL.split("?");
        if (loU.length>1){
            var loallPm = loU[1].split("&");
            for (var i=0; i<loallPm.length; i++){
                var loPm = loallPm[i].split("=");
                if (loPm[0]==asName){
                    if (loPm.length>1){
                        return loPm[1];
                    }
                }
            }
        }
        else{
            return null;
        }
    },
    afterClose: function(newLayer) {
        if (!Layer.toggle) {
            HeaderAnimation.augment();
        }
    },
    beforeClose: function() {
        HeaderAnimation.unregisterLayer();
        return true;
    },
    beforeOpen: function() {
        HeaderAnimation.registerLayer(this);
        if(!this.iframeisloaded) {
            this.iframeisloaded = false;
            this.addPreloader();
        }
        return true;
    },
    hide: function() {
        this.node.removeClassName("active-layer");
        this.trigger.up().removeClassName("active");
    },
    show: function() {
        this.node.addClassName("active-layer");
        this.trigger.up().addClassName("active");
        this.trigger.addClassName("clicked"); // avoids hover effect (only for the first time)
        this.trigger.observe("mouseout",
            function(e) {
                var elm = Event.findElement(e, "a");
                elm.removeClassName("clicked");
                elm.stopObserving("mouseout");
            }
        );
    },
    setOffset:function(offset) {
        this.node.style.top = offset + "px";
    },
    /*
     * Check if the real destination was loaded before.
     * If yes, then just correct the curtain else set the location to initiate iframe.
     */
    afterOpen: function() {
        if(!this.iframeisloaded) {
            this.setIFrameLocation();
            this.iframeisloaded = true;
        }
        HeaderAnimation.diminish();
    },
    /*
     * Switch the iframe.src attribute from "about:blank" to its real location
     */
    setIFrameLocation: function() {
        Event.observe( $(this.iframeidstring), 'load',function(e)
                {
                    this.rechunkIFrame(e);
                }.bindAsEventListener(this)
        );
        $(this.iframeidstring).src = this.iframehref;
    },
    showIFrame: function() {
        this.removePreloader();
    },
    hideIFrame: function() {
        this.addPreloader();
    },
    addPreloader: function() {
        if(!$('lightbox-preloader')) {
            new Insertion.Before($(this.iframeidstring), "<div id='lightbox-preloader'>&nbsp;</div>");
        }
        $(this.iframeidstring).style.visibility = 'hidden';
    },
    removePreloader: function() {
        if($('lightbox-preloader')) {
            $('lightbox-preloader').remove();
        }
        $(this.iframeidstring).style.visibility = 'visible';
    },
    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) {
                iframeroot.contentWindow.document.body.style.backgroundImage = "none";
                iframeroot.contentWindow.document.body.style.backgroundColor = '#E3EBEE';
                /*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.backgroundColor = '#e7e8eb';
                    contZone.down('.right-content').style.display = 'none';
                }
                */
                if (iframeroot.contentWindow.document
                        .getElementById('content-zone')) {
                	var el = iframeroot.contentWindow.document.getElementById('content-zone');
                	
                    var h = el.offsetHeight + 0 + 70;
                    
                    iframeroot.height = h;
                    this.iframeheight = h;
                }
            } else if (iframeroot.contentDocument) {
                iframeroot.contentDocument.document.body.style.backgroundImage = "none";
                iframeroot.contentDocument.document.body.style.backgroundColor = '#E3EBEE';
                /*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')) {
                    iframeroot.contentDocument.document
                            .getElementById('content-zone').style.marginLeft = '0px';
                }
                if (iframeroot.contentDocument.document
                        .getElementById('content-zone')) {
                    var contZone = $(iframeroot.contentDocument.document
                            .getElementById('content-zone'));
                    contZone.style.backgroundColor = '#e7e8eb';
                    contZone.down('.right-content').style.display = 'none';
                }
                */
                
                if (iframeroot.contentDocument.document
                        .getElementById('content-zone')) {
                    
                    var el = iframeroot.contentDocument.document.getElementById('content-zone');
                	
                    var h = el.offsetHeight + 0 + 70;
                    
                    iframeroot.height = h;
                    this.iframeheight = h;
                }
            } else {
                return;
            }
            
            this.iframeisloaded = true;
            if ($('lightbox-preloader')) {
                $('lightbox-preloader').remove();
            }
            $(this.iframeidstring).style.visibility = 'visible';
        }
    }
});


/* END:*/

/********************************************************************/
/*  overwritten function of _resources/js/compiled/script.js (208)  */
/********************************************************************/
var IFRAME_TOOLBAR_REL_REGEX = /^ext-toolbar-layer-(.+)$/;
//var IFRAME_TOOLBAR_LAYER = new Array();
function init_contentLayers() {};
function init_toolbarLayers() {
    if ($("toolbar-nav")) {
        $A($("toolbar-nav").getElementsByTagName("a")).each(
            function(trigger) {
                trigger = $(trigger);
                if (IFRAME_TOOLBAR_REL_REGEX.test(trigger.rel)) {
                    var id = trigger.rel.replace(
                            IFRAME_TOOLBAR_REL_REGEX, "$1");
                    var elm = "<div id='toolbar-layer-"
                            + id
                            + "' class='toolbar-layer'><div class='close'><a href='javascript:void(0);'>";
                    elm += "<span class='access'>Close Help Layer</span></a></div>";
                    elm += "<div class='layer-content'><div id='toolbar-layer-content-"
                            + id + "'></div></div></div>";
                    new Insertion.Before(
                            $('footer-position-placeholder'), elm);
                    var node = $("toolbar-layer-" + id);
                    var key = "toolbar-layer-" + id;
                    GLOBAL_LAYER_CONTROLLER[key] = new ExtToolbarLayer(
                            node, trigger, id);
                } else { // standard link, probably external
                    trigger.observe("click", function() {
                        Layer.closeCurrent();
                    }.bindAsEventListener(this));
                }
            }.bind(this)
        );
    }
}
