/**
 * SEE company directory application
 * 
 * Presents the JavaScript framework for the SSC application
 * 
 * @author Ollie Maitland
 * @copyright Byng Systems LLP
 */

var Se = {}

Se.app = new Class(
{
	
	Implements : [ByngApp],
	
	/**
	 * Holds meta data on this application
	 * 
	 */
	meta	: {
		'name'	    : 'SEE',
		'version'   : '0.1.0',
		'author'    : 'ollie@byng-systems.com',
		'copyright' : 'Byng Systems LLP',
		'date'  	: '2000-01-29'
	},
	
	icons : {
		'loader' : '/html/images/icons/ajax-loader.gif'
	},
	
	/**
	 * Initialise application
	 * 
	 */
	initialize : function ()
	{
		this.addEvent('load', this.loadEnvironment.bind(this));
	},
	
	/**
	 * Load the page environment
	 * 
	 */
	loadEnvironment : function ()
	{	
		if ($('together_bg')) {
					new multipleOpenAccordion($$('.toggler'),$$('.accordion'));				
		}	

		if ($('bottom_bg')) {

				new multipleOpenAccordion($$('.toggler'),$$('.accordion'), {
					onActive: function(toggler, element){
						toggler.setStyles({
							   'background-image':'url(/html/images/framework/hover_tr_2.gif)',
							   'background-color':'#909090',
  							  'background-repeat':'no-repeat',
							'background-position':'center right'
						});
					},
					onBackground: function(toggler, element){
						toggler.setStyles({
							   'background-image':'url(/html/images/framework/normal_tr_2.gif)',
							   'background-color':'#909090',
  							  'background-repeat':'no-repeat',
							'background-position':'center right'
						});
					}
				});

		}

		if ($('se-search')) {

			// hide the container
			//var searchBox = $('se-search').removeClass('hide').setStyle('opacity', 0);

			// add the open/close events
			/*$('search').addEvent('click', function(e) { 
			
				searchBox.fade('in'); 
				var input = searchBox.getElement('.se-search_field');
				var FAYT_DEFAULT_VALUE = 'Please type to find a company...';
				
				input.set('value', FAYT_DEFAULT_VALUE)
					 .set('defaultValue', FAYT_DEFAULT_VALUE)
					 .addEvent('focus', function(e) {
						var input = $(e.target);
						if (input.get('value') == input.get('defaultValue')) {
							input.set('value', '');
						}
					})
					.addEvent('blur', function(e) {
						var input = $(e.target);
						if (input.get('value') == '') {
							input.set('value', input.get('defaultValue'));
						}
					});
			});

			$('se-search_close').addEvent('click', function(e) { 			

				searchBox.fade('out'); 
				$$('.se-search_field').set('value', '');	
 				$('se-search_wrap').empty();
				
			});
			
			// create a new Find-as-you-type box
			var faty = new Search({	'input' 		: $('se-search').getElement('input'), 
									'gateway'		: '/ajax/site/company_view/search',
									'container' 	: $('se-search_wrap'),
									'minStrLength' 	: 1});
			*/
		}
		
		var tabContainer = $('se-tab_block');
		if ( tabContainer ) {		
			var selected = tabContainer.getAttribute('accesskey'); 
			var tabs = new SimpleTabs('se-tab_block', {
				selector: 'h4', show : (selected ? selected : 0)	
			});
		}

		if ($$('.se-tool_tip')) {			
			
			 //create the tooltips  
			 var tipz = new Tips('.se-tool_tip',{  
				 className: 'se-tool_tips',  
				 fixed: false,  
				 hideDelay: 50,  
				 showDelay: 50
			 });  

			Byng.app.addEvent('popup', function(popup) {
				this.attach(popup.getElements('.se-tool_tip'));
			}.bind(tipz));
		

		}


	}
	
});

// Set the SEE application
Byng.setApp( new Se.app );

// Set the input handles
Byng.setInput( new ByngInput() );

// load the Byng User Interface object
Byng.setUi ( new ByngUI( UI_FLAG_AJAX ) );

window.addEvent('domready', function() {
	Byng.app.fireEvent('load');
});