	var rbs = 
{
	//*------------------------------------------------------------------//
	tools: function()
	{
		if($$('.tools').length>0)
		{
			new Asset.images(['/img/tools/icon_share_hover.gif', '/img/tools/icon_bookmark_hover.gif', '/img/tools/icon_email_hover.gif', '/img/tools/icon_print_hover.gif']);
			$$('.tools img').each
			(
				function(el)
				{		
					el.addEvent
					(
						'mouseover',
						function()
						{
							this.setAttribute('src',this.src.replace('.gif', '_hover.gif'));
						}
					)
					.addEvent
					(
						'mouseout',
						function()
						{
							this.setAttribute('src',this.src.replace('_hover.gif', '.gif'));
						}
					);
				}
			)
			
			$$('.print').addEvent
			(
				'click',
				function(e)
				{
					e.stop();
					window.print();
				}
			)


			function bookmarksite(title,url)
			{
				if (window.sidebar)
				{
					window.sidebar.addPanel(title, url, "");
				}
				else if(window.opera && window.print)
				{
					var elem = document.createElement('a');
					elem.setAttribute('href',url);
					elem.setAttribute('title',title);
					elem.setAttribute('rel','sidebar');
					elem.click();
				} 
				else if(document.all)
				{
					window.external.AddFavorite(url, title);
				}
			}
			
			if(Browser.Engine.trident || Browser.Engine.gecko)
			{
				$$('.bookmark').addEvent
				(
					'click',
					function(e)
					{
						e.stop();
						bookmarksite(document.title, document.location.href);
					}
				)
			}
			
			$$('#socialDropButton').each(
				function(a)
				{
					new Menu(a,{links:[
						'<a href="http://del.icio.us/post?url=' + document.location.href + '" target="_blank" title="Delicious. Opens in a new window." class="delicious">Delicious</a>',
						'<a href="http://digg.com/submit?url=' + document.location.href + '" target="_blank" title="Digg. Opens in a new window." class="digg">Digg</a>',
						'<a href="http://www.facebook.com/share.php?u=' + document.location.href + '" target="_blank" title="Facebook. Opens in a new window." class="facebook">Facebook</a>',
						'<a href="http://reddit.com/submit?url=' + document.location.href + '" target="_blank" title="Reddit. Opens in a new window." class="reddit">Reddit</a>',
						'<a href="http://www.stumbleupon.com/submit?url=' + document.location.href + '" target="_blank" title="StumbleUpon. Opens in a new window." class="stumbleupon">StumbleUpon</a>',
						'<a href="http://www.rbs.com/global/share-links-guide.ashx" target="_blank" title="What are these? Opens in a new window." class="social_last">What are these?</a>'
					]});
				}
			);

		}
	},

	rotator: function()
	{
		$$('.rotator').each(
			function(rotator)
			{
				new Rotator(rotator,{
					content:[
						'.rotator-content-00',
						'.rotator-content-01',
						'.rotator-content-02'
					],
					interval: 10000
				});
			}
		);
	},
	
	hoverstates: function() {
		
		$$('.infoPod').each(
			function(pod) {
				pod.getParent().addEvent(
						'mouseover',
						function(){pod.addClass('show');}
					)
					.addEvent(
						'mouseout',
						function(){pod.removeClass('show');}
					);
			}
		);
		
	},
	
	accordions: function() {
		
		$$('div.accordion').each(
			
			function(accordion) {
				
				var _accordion = new HWAccordion(
					accordion.getElements('.heading .button a'),
					accordion.getElements('.group'),
					{
						display: -1,
						initialDisplayFx: false,
						alwaysHide: true,
						opacity: false,
						multiOpen: true,
						onActive: function(toggler, element) {
							toggler.addClass('hide').set('text', 'Hide this group');
						},
						onBackground:function(toggler, element) {
							toggler.removeClass('hide').set('text', 'Show this group');

						}
					}
				);
				
				accordion.getElements('.showAll').addEvent('click',function(e){
					_accordion.showAll();
					e.stop();
				});
					
			}
			
		);

	},
	
	gallery: function() {
		
		this.galleryGroup('a.overlay1');
		this.galleryGroup('a.overlay2');
		this.galleryGroup('a.overlay3');
		
	},
	
	galleryGroup: function(selector) {
		
		// set overlay handle in global scope to avoid opening multiple overlays
		var overlay;
		
		// find any links toopen in an overlay and loop
		$$(selector).each(function(a,i,all){
			
			a.addEvent('click',function(e) {
				e.stop();
				
				var href = this.get('href').split('#'),
					ajax = new Request.HTML();
				
				// define ajax success handler
				ajax.addEvent('success',function(content,elements,html){
					// if specific hash value is defined then find element with that id
					if(href[1]) {
						elements = elements.filter('#'+href[1]);
					}
					else {
						elements = content;
					}
					
					// if overlay exists then empty it, otherwise build a new overlay
					if(overlay && overlay.isOpen) {
						overlay.clearContent();
					}
					else {
						overlay = new Overlay();
						overlay.open();
					}
					overlay.insertContent(elements);
					
					// if more than one link, add next and prev buttons
					if(all.length > 1) {
						
						var buttons = new Element('div',{'class':'buttons'}),
							p = new Element('p',{'class':'button'}),
							a = new Element('a',{'href':'#'});
						
						// previous
						if(i > 0) {
							var prev = a.clone()
										.set('html','Previous image')
										.addEvent('click',function(e){
											all[i-1].fireEvent('click',e);
										});
							buttons.grab(p.clone().grab(prev).addClass('previous'));
						}
						// next
						if(i < all.length - 1) {
							var next = a.clone()
										.set('html','Next image')
										.addEvent('click',function(e){
											all[i+1].fireEvent('click',e);
										});
							buttons.grab(p.clone().grab(next).addClass('next'));
						}
						
						overlay.insertContent(buttons);
					}
				});
				// send ajax request for content
				ajax.get(href[0]);
			});
			
		});
		
	},

	//*------------------------------------------------------------------//
	init: function()
	{
		this.tools();
		this.rotator();
		this.accordions();
		this.gallery();
	}
};


/*------------------------------------------------------------------
REGISTER MAIN EVENTS
------------------------------------------------------------------*/

window.addEvent('domready', function(){rbs.init();});
