/* START: inline lightbox layer */
var ImageLightboxLayer = Class.create();

ImageLightboxLayer.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) {
		//lightbox layers can not occur in these page types
		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;
		
		//start flash controller
		this.flashcontent = false;
		//end flash controller

		
		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() {
		
		if(this.flashcontent && flashRewriter[this.idstring] != null) {
			flashRewriter[this.idstring].write('banner-block-'+this.idstring);
			this.flashcontent = false;
		}
		
		//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();   
        }
	},
	afterClose: function() {
		this.flashcontent = true;
		$(this.layerIdstring).down().update();
		
		// get info for ste
		var swf_o_id 	= flashRewriter[this.idstring].getVariable('tracking_id');
		var swf_o_type 	= flashRewriter[this.idstring].getVariable('tracking_type');
		var swf_o_path 	= flashRewriter[this.idstring].getVariable('tracking_path');
		var swf_o_flv 	= flashRewriter[this.idstring].getVariable('flv_src');
		
		// convert path to filename
		swf_o_flv = swf_o_flv.substring((swf_o_flv.lastIndexOf('/')+1));
		
		// manually track video close through ste  
		ste.flash.video.close({'id':swf_o_id, 'type':swf_o_type, 'path':swf_o_path, 'name':swf_o_flv});
	} 
});
var flashRewriter = [];
var videoLinkId = 0;

function init_ml_lightboxLayers() {
	$$('div.right-content div.videobanner div.image a').each( function(trigger)
    {
		var id = 'video'+videoLinkId;
		var flv = trigger.href;
		
		videoLinkId++;
		
		trigger.id = id;
		
		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 id='banner-block-"+id+"'></div></div></div></div>";
		/* elm += "<div class='layer-content' onMouseOut=\"hideFlvPlayerControl('flv_player')\" onMouseOver=\"showFlvPlayerControl('flv_player')\"><div id='layer-content-"+id+"'><div id='banner-block-"+id+"'></div></div></div></div>";*/
		
	
		new Insertion.Before($('footer-position-placeholder'), elm);

        var node = $("lightbox-layer-"+id);
		new ImageLightboxLayer(node,trigger,id);
		//new ImageLightboxLayer(node,trigger,"video");
  		
  		var video = null;
  		var uid = new Date().getTime();
  		
		var src = FRAMEWORK_PATH + "img/flv_player.swf";
		video = new SWFObject(src, "flv_player", "570px", "280px", "8,0,0,0", "#b0b4bf");
        video.addParam("allowFullscreen", "true");
		video.addParam("scale", "noscale");
		video.addParam("wmode", "transparent");
		video.addVariable('lcId', uid);
  	    video.addVariable("stage_width", 480);
  	    video.addVariable("stage_height", 270);		
  	    video.addVariable("flv_src", flv);
  	    
	    video.addVariable("tracking_id", "gb2008");
	    video.addVariable("tracking_type", "video");
	    video.addVariable("tracking_path", s.hier1);	
  	    
		video.write("banner-block-"+id);
		//video.write("banner-block-video");		
		
		flashRewriter[id] = video;
	} 
	);
}

/**
 * init_open: remove video tracking IE bug - this function is called by the flv player and by the HV
 */

function init_open (track_o) {
	// call video.open
	ste.flash.video.open({	'id':			track_o.id, 
							'type':			track_o.type, 
							'path':			track_o.path, 
							'name':			track_o.name,
							'length':		track_o.length,
							'playername':	track_o.playername
						});
	
	// call video.play
	ste.flash.video.play({
								'id':			track_o.id,
								'type': 		track_o.type, 
								'path':			track_o.path,  
								'name':			track_o.name,
								'offset':		track_o.offset
						});
}

/**********************************/
Event.onDOMReady(function(){ init_ml_lightboxLayers(); });