HW.LightBox = {
	contentToShow:null,
	cls:null,
	// set alpha level of the mask layer
	maskAlpha:70,
	// set colour of mask layer
	maskColour:'#000000',
	// set content of close button
	// if set as null then no close button will appear and the overlay can be removed by clicking anywhere outside the overlay window	
	/* HWremark closeButton:'<img src="<%=response.encodeURL("/content/images/business_banking/lightbox-close.gif")%>" alt="close" />', */
	closeButton:'Close',
	
	//closeButton:'Close',//
	// HTML code of popup window
	// Note: ids on wrapper element and content area are required and should be as set below
	popupHTML:'<div class="jvsLightBoxPopup" id="jvsLightBoxPopup"><div class="jvsLightBoxPopupInner" id="jvsLightBoxPopupInner"><div class="jvsLightBoxPopupContentArea" id="jvsLightBoxPopupContentArea"></div></div></div>',
	popupId:'jvsLightBoxPopup',
	contentId:'jvsLightBoxPopupContentArea',
	// give the option to set a callback function to call once lightbox content is loaded
	callback:function(){return;},
	/*
	* init(c)
	* set up the event handlers on links
	* c:		The classname on links which should open in an overlay
	* Returns:	Nothing
	*/
	init:function(c) {
		if(c) {
			this.cls = c;
			// find the link with the right class
			var links = $$(this.cls,document.body,null);
			for(var i=0,j=links.length;i<j;i++) {
				var obj = this;
				// set click handlers
				HW.attachEvent(links[i],'click',function(e) {
					HW.preventDefault(e);
					e=e||window.event;
					trg = e.srcElement||e.target;
					if (trg.tagName == "IMG"){trg = trg.parentNode;}
					if ($('jstCloseText')){obj.closeButton = $('jstCloseText').value; }
					obj.openLightBox(trg.href);
				});
			}
		}
	},
	buildReg:function (param) {
		return new RegExp("<object [^>]*"+param+"=\"([^>^\"]+)\"[^>]*>");
	},
	
	
	
	/*
	* MacFFcrack()
	* show / hide all background Flash objects while overlay on Mac FireFox 2
	* Returns:	Nothing
	*/
	MacFFcrack:function(displayValue) {
		var agt = navigator.userAgent.toLowerCase();											
		if((agt.indexOf("macintosh") != -1) && (agt.indexOf("firefox/2") != -1)) {
			var objs = document.getElementsByTagName('embed');
			for (i=0; i < objs.length; i++ )
			{
				document.getElementsByTagName('embed')[i].style.display = displayValue;
			}
		}
	},
	/*
	* displayContent()
	* if the popup overlay and mask do not exist, create them
	* Returns:	Nothing
	*/
	displayContent:function() {
		if(!this.mask) {this.createMask();}
		if(!this.popup) {this.createPopup();}
		if(this.mask && this.popup) {
			this.popup.contentArea.innerHTML = '';
			this.popup.contentArea.appendChild(this.contentToShow);
			this.showMask();
		}
	},
	/*
	* createMask()
	* creates the mask overlay
	* Returns:	Nothing
	*/
	createMask:function() {
		// if we're using IE then add an iframe to layer over select boxes
		if(HW.isIE) {
			this.ieFixIframe = HW.createNode('iframe',document.body);
			this.ieFixIframe.className = 'jvsLightBoxMask';
			HW.setStyle(this.ieFixIframe,{display:'none'});
			this.ieFixIframe.frameBorder = 0;
			HW.setFade(this.ieFixIframe,0);
		}
		this.mask = HW.createNode('div',document.body);
		this.mask.className = 'jvsLightBoxMask';
		HW.setStyle(this.mask,{display:'none'});
		// if the user is using Mac Firefox then we need to use a png for the mask
		if(HW.isMacFF) {
			HW.addClass(this.mask,'jvsLightBoxMaskMacFF');
			this.maskAlpha = 100;
		}
		else {
			var c = this.maskColour;
			HW.setStyle(this.mask,{background:c});
			HW.setFade(this.mask,this.maskAlpha);
		}
		var obj = this;
		// hide the overlay when the user clicks outside the popup
		HW.attachEvent(this.mask,'click',function(){obj.hidePopup();});
	},
	/*
	* createPopup()
	* creates the popup window
	* Returns:	Nothing
	*/
	createPopup:function() {
		// create an empty div...
		var div = HW.createNode('div',document.body);
		// ... and set its contents
		div.innerHTML = this.popupHTML;
		//HW.log(div);
		//HW.setStyle(div, {background-color:#fff;});
		// set popup and content elements
		this.popup = $(this.popupId);
		this.popup.contentArea = $(this.contentId);
		if(!this.popup || !this.popup.contentArea) {HW.error('Elements with correct ids not found.');}
		HW.setStyle(this.popup,{display:'none'});
		// if the close button is set then create it
		if(this.closeButton !== null) {
			var obj = this;
			this.popup.closeButton = HW.createNode('a',this.popup);
			this.popup.closeButton.href = '#';
			this.popup.closeButton.innerHTML = this.closeButton;
			this.popup.closeButton.className = 'jvsLightBoxClose';
			this.popup.closeButton.id = 'jvsLightBoxClose';
			HW.attachEvent(this.popup.closeButton,'click',function(e) {obj.hidePopup();HW.preventDefault(e);});
		}
	},
	/*
	* showMask()
	* displays the mask layer
	* Returns:	Nothing
	*/
	showMask:function() {
		this.setMaskSize();
		// fade in if we can
		if(HW.Animate) {
			HW.setFade(this.mask,0);
			HW.setStyle(this.mask,{display:''});
			var obj = this;
			HW.Animate.fade(this.mask,this.maskAlpha,500,function(){obj.showPopup();});
		}
		else {
			HW.setStyle(this.mask,{display:''});
			this.showPopup();
		}
	},
	/*
	* showPopup()
	* displays the popup window
	* Returns:	Nothing
	*/
	showPopup:function() {
		var obj = this;
		// fade in if we can
		if(HW.Animate) {
			//HW.setFade(this.popup,0);
			HW.setStyle(this.popup,{display:''});
			this.setPopupSize();
			//HW.Animate.fade(this.popup,100,0,function(){obj.callback();});
		}
		else {
			HW.setStyle(this.popup,{display:''});
			this.setPopupSize();
			this.callback();
		}
	},
	/*
	* hidePopup()
	* hides the popup window and mask layer
	* Returns:	Nothing
	*/
	hidePopup:function() {
		var s = {display:'none'};
		HW.setStyle(this.popup,s);
		HW.setStyle(this.mask,s);
		if(this.ieFixIframe) {
			HW.setStyle(this.ieFixIframe,s);
		}
		if (this.flashVideo)this.flashVideo.StopPlay();/* stop flash video in IE6*/ 
		this.popup.contentArea.removeChild(this.contentToShow);
	},

	/*
	* setMaskSize()
	* set the size of the mask layer to fill the window
	* Returns:	Nothing
	*/
	setMaskSize:function() {
		var dims = this.getDocSize();
		this.mask.style.height = dims[1]+'px';
		if(this.ieFixIframe) {
			this.ieFixIframe.style.height = dims[1]+'px';
			this.ieFixIframe.style.display = '';
		}
	},
	/*
	* setPopupSize()
	* set the size of the popup window and centre on screen
	* Returns:	Nothing
	*/

	setPopupSize:function() {
		var dims = this.getWinSize();
		var scrY = window.scrollY||document.documentElement.scrollTop||document.body.scrollTop;
		var _left = Math.max((dims[0]-this.popup.offsetWidth)/2,0)+'px';
		var _top = Math.max((dims[1]-this.popup.offsetHeight)/2+scrY,0)+'px';
		HW.setStyle(this.popup,{left:_left,top:_top});
	},
	/*
	* getDocSize()
	* gets the size of the document, if the document is shorter than the window, returns window height
	* Returns:	Array of dimensions
	*/
	getDocSize:function() {
		var dims = this.getWinSize();
		var w = dims[0];
		var h = dims[1];
		w = Math.max(w,document.body.offsetWidth);
		w = Math.max(w,document.documentElement.offsetWidth);
		h = Math.max(h,document.body.offsetHeight);
		h = Math.max(h,document.documentElement.offsetHeight);
		h = Math.max(h,document.documentElement.scrollHeight);
		return [w,h];
	},
	/*
	* getWinSize()
	* gets the size of the window
	* Returns:	Array of dimensions
	*/
	getWinSize:function() {
		var w = 0;
		var h = 0;
		if(window.innerWidth) {
			w = window.innerWidth;
			h = window.innerHeight;
		}
		else if(document.documentElement.clientWidth) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
			//h = document.documentElement.scrollHeight;
		}
		else if(document.body.clientWidth) {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		return [w,h];
	},
	/*
	* openLightBox(href)
	* loads a lightbox with content from the spcified url
	* href:		String - URL of the content to load, with hash reference if required
	* Returns:	Nothing
	*/
	openLightBox:function(href) {
		var obj = this;
		this.contentToShow = document.createElement('div');
		var url = href.split('#');
		this.contentToShow.innerHTML = $('flash_demo').innerHTML;
		this.displayContent();
	}
};
// set up the lightbox
HW.onload(function(){HW.LightBox.init('lightbox');});

/*
--- END LIGHTBOX FUNCTIONS ---
*/

	
	
	
	
	
