// JavaScript Document






		var toggleModal = function(backgroundColour, options) {
			// modal view for the whole screen
			// ver 2.02 17/10/2008 03:42:06
			if ($("modal")) {
				$("modal").dispose();
				return false;
			}
		
			var options = $merge({
				zIndex: 1000,
				opacity: .5,
				events: $empty()
			}, options);
		
			if (!$type(backgroundColour) && !$("modal"))
				return false;
		
			return new Element("div", {
				id: "modal",
				styles: {
					position: "absolute",
					top: 0,
					left: 0,
					width: window.getScrollWidth(),
					height: window.getScrollHeight(),
					background: backgroundColour,
					"z-index": options.zIndex
				},
				opacity: options.opacity,
				events: options.events
			}).inject(document.body);
		} // end toggleModal
		
		
		
window.addEvent('domready', function() {
		
		//this bit does the modal dialogue
			$('fb-modal').setStyles({
				opacity:0,
				display:'block',
				zIndex:1001
			});
			/* hiders */
			$('fb-close').addEvent('click',function(e) { $('fb-modal').fade('out');  toggleModal();});
			window.addEvent('keypress',function(e) { if(e.key == 'esc') { $('fb-modal').fade('out'); toggleModal(); } });
			$(document.body).addEvent('click',function(e) { 
				if($('fb-modal').get('opacity') == 1 && !e.target.getParent('.generic_dialog')) { 
					$('fb-modal').fade('out'); 
					 toggleModal();
				} 
			});
			
			
			
			var elements = $$('a[rel="modalbox"]');
			
			/* click to show */
			elements.addEvent('click',function(e) {
				
				e = new Event(e);
            	e.stop();
				
				
				$('fb-modal-title').set('text', this.getProperty('title'));
				//load dialogue contents here!
				$('fb-modal-content').set('text', 'Loading...');
				toggleModal("#000");
				$('fb-modal').fade('in');
						
				var req = new Request.HTML({url:this.getProperty('href'), 
					onSuccess: function(html) {
						//Clear the text currently inside the results div.
						$('fb-modal-content').set('text', '');
						//Inject the new DOM elements into the results div.
						$('fb-modal-content').adopt(html);
						
					},
					//Our request will most likely succeed, but just in case, we'll add an
					//onFailure method which will let the user know what happened.
					onFailure: function() {
						$('fb-modal-content').set('text', 'Ooops, there was a problem loading the content.       Please try again.');
						
					}
				});
				req.send();
				
				
				
			});
});