/* START: FormerTopic layer */
var FormerTopicLayer = Class.create();

FormerTopicLayer.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);
		}

		//store the listener so it can be accessed by functions add and remove
		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() {
		//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'});
		
		// calculate top position dynamically (was before: this.nodeTop = this.headerHeight + parseInt(this.node.getStyle('top')))
		if(!this.nodeTop) {
			this.nodeTop = 	this.headerHeight + 
							parseInt($('breadcrumb-zone').getDimensions().height) + 
							parseInt($('presscrumb-zone').getDimensions().height) +
							parseInt($$('.left-content')[0].getDimensions().height);
		}
		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;
	},

	beforeClose: function() {
		if(this.iframeLining)
			this.iframeLining.hide();
		return true;
	},

	handleOpen: function() {
		HeaderAnimation.listenerQueue.remove(this.listener);
		Layer.prototype.open.call(this);
	}
});

/* END: FormerTopic layer */
document.observe('dom:loaded', function() {
    if($('former-topics-trigger'))
    {
        var trigger = $('former-topics-trigger');
        var id = "01";
        var node = $("former-topic-layer-" + id);
        new FormerTopicLayer(node, trigger);
    }
});