/* START: inline lightbox layer */
var MagnifierLightboxLayer = Class.create();

MagnifierLightboxLayer.prototype = Object.extend(new AbstractLightboxLayer, {
	/*
	 * @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.idstring = idstring;
		this.layerIdstring = "layer-content-"+idstring; 
		this.node = node;
		this.curtainidstring = "lightbox-curtain"+idstring;
		this.replacer = "replacer-"+idstring;
		
		this.initSuper(node, trigger);
		var closeButton = Helper.getCloseButton(this.node);
		closeButton.observe("click", function(){
			this.close();
			//this.contentHolder = $(this.layerIdstring).innerHTML;
			//$(this.layerIdstring).update();	
		}.bindAsEventListener(this));
		trigger.href="javascript:void(0);";
		//create the curtain
		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);
		}
		//store the listener so it can be accessed by functions add and remove
		this.listener = {'augmentDone' : this.handleOpen.bind(this) };
		//add an event handler to resize the curtain when window is resized
		Event.observe(window, "resize", function(){this.resizeCurtain();}.bindAsEventListener(this));
		
	},
	beforeOpen: function() {
		
		//calculate top value of layer
		if(!this.headerHeight) this.headerHeight = $('header-zone').getDimensions().height + $('toolbar-zone').getDimensions().height;

		//position the curtain
		this.curtain.setStyle({'top': this.headerHeight+'px'});

		//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'});

		//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;
			layerOccupation = layerOccupation - this.headerHeight;
			
			//difference between layer height and content height
			var diff2 = $('content-zone').getDimensions().height - layerOccupation;
			$('content-zone').setStyle({'height': $('content-zone').getDimensions().height - diff2 + 'px'});
			this.resizeCurtain();
		};

		//this.node.setStyle({'top': this.nodeTop+'px'});
		this.node.setStyle({'top': '210px'});
		if(this.iframeLining)
			this.iframeLining.show();
		this.curtain.setStyle({'display': 'block'});
		$('footer-position-wrapper').scrollTo();
		return true;
	},
    afterOpen: function() {
		if(typeof fireSifrHandler == 'function') {
            fireSifrHandler();
        }
	} 
});
var imageLinkId = 0;
function init_magnifier_lightboxLayers() {
	
	
	
	$$('div.block-image.img-450 img').each( function(imageitem)
    {
		var id = 'image'+imageLinkId;
		imageLinkId++;
		
		var idx = imageitem.src.lastIndexOf(".");
		var prefixImage = imageitem.src.substring(0,idx);
		var postfixImage = imageitem.src.substring(idx,imageitem.src.length);
		
		var lang = (PAGE_LANGUAGE == "de") ? "<img src='"+RESOURCES_PATH+"/css/core/img/icon-magnify.gif' title='Bild vergrössern' alt='Bild vergrössern' />" : "<img src='"+RESOURCES_PATH+"/css/core/img/icon-magnify.gif' title='Magnify image'alt='Magnify image' />";
		var trigger = new Element('a', {'class': 'magnify', id: id}).update(lang);
		var triggerP = new Element('p', {'class': 'trigger-magnifier clearfix'}).update(trigger);
		
		imageitem.up().appendChild(triggerP);
		
		var elm = "<div id='lightbox-layer-"+id+"' class='image-lightbox-layer'><div class='close'><a href='javascript:void(0);'>";
		elm += "<span class='access'>Close Layer</span></a></div>";
//	header text		
		//elm += "<div class='layer-content'><div id='layer-content-"+id+"'><div id='image-block-"+id+"' class='image-block-lightbox'><div class='sifr-header'><h2>"+imageitem.alt+"</h2></div>";
//	w/o header text		
		elm += "<div class='layer-content'><div id='layer-content-"+id+"'><div id='image-block-"+id+"' class='image-block-lightbox'>";
		elm += "<img src=" + prefixImage + "-big" + postfixImage + " alt=" + imageitem.alt + " />";
		elm += "</div></div></div></div>";
		
		registerSifrHandler('div#image-block-'+id+' div.sifr-header h2','#333333');
	
		new Insertion.Before($('footer-position-placeholder'), elm);

        var node = $("lightbox-layer-"+id);
		new MagnifierLightboxLayer(node,trigger,id);
		
	} );
}
/**********************************/
Event.onDOMReady(function(){ init_magnifier_lightboxLayers(); });