window.addEvent( 'domready', function() {
	
	// Set up any accordians on the page
	var aAccordians = $$( 'div.accordion' );
	aAccordians.each( function( item, index ) {
		var oAccordian = new Accordion( item, 'div.toggler', 'div.element', {
			opacity: false,
			onActive: function(toggler, element){
				//toggler.setStyle('color', '#41464D');
			},
			onBackground: function(toggler, element){
				//toggler.setStyle('color', '#528CE0');
			}
		});
	});
	
	// Add a confirmation popup to any element with the confirm class
	var aConfirm = $$( '.confirm' );
	aConfirm.each( function( item, index ) {
		
		item.addEvent( 'click', function( event ) {
			var bConfirm = confirm( "Are you sure?" )
			
			if( !bConfirm ) {
				Event.stop( event );
			}
		});
	});
	
	// Collects a list of anchors which have class="ajax".
	// When one of these link are clicked the page content is updated through ajax rather than refreshing the whole page
	var ajaxAnchors = document.getElements( 'a.ajax' );
	ajaxAnchors.each( function( item, index ){
		item.addEvent( "click", function( event ) {
			$( 'content' ).load( item.getProperty( 'href' ) );
			event.stop();
		});
	});
	
	// Add a popup to links
	var aConfirm = $$( '.throwpop' );
	aConfirm.each( function( item, index ) {
		
		item.addEvent( 'click', function( event ) {
			Event.stop( event );
			
			var sTarget = event.target.getProperty( "href" );
			
			var w = 800;
			var h = 600;
			var LeftPosition=(screen.width)?(screen.width-w)/2:100;
			var TopPosition=(screen.height)?(screen.height-h)/2:100;
			
			var sSettings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=yes,menubar=yes,toolbar=yes,resizable=yes';
			
			win=window.open( sTarget, "", sSettings );
		});
	});
	
	
	
	// Add tool tips
	var oTipAccordian = new Tips( '.tip_accordian' );
	$$( '.tip_accordian' ).store( 'tip:text', '<p>To make an accordion, you must wrap the <br />content in --accordion-- and --/accordion--.</p><p>Any content inside these two tags which <br />has been given the HEADING 2 style will<br />become a toggler, whilst any other content <br />will be displayed in the accordion body.</p><p>--accordion--<br />&nbsp;Heading 2<br />&nbsp;Lorem Ipsum<br />--/accordion--</p>' );
	
	oTipAccordian.addEvent('show', function(tip){
		tip.fade('in');
	});

	oTipAccordian.addEvent('hide', function(tip){
		tip.fade('out');
	});
	
	// Make sure that clicking on tool tips does nothing
	var aTips = $$( '.tooltip' );
	aTips.each( function( item, index ) {
		
		item.addEvent( 'click', function( event ) {
			Event.stop( event );
		});
	});

	
});