function openNav(x) {
	BH.openNav(x);
}

function resizeFlash(elem, height) {
	BH.resizeFlash(elem, height);
}

var BH = {

	toggleDropdown: function(num) {
	
			drop 	= (parseFloat(num)) ? $('dropdown_'+num) : num;
			button	= drop.down('a.button');
			links	= drop.down('ul.links');
			
			if (button.hasClassName('open')) {
				// Close it
				button.removeClassName('open');
				links.hide();
				
				// Clear listener
				Event.stopObserving(drop, 'mouseout');
				
			} else {

				// Open it
				button.addClassName('open');
				links.show();

				drop.observe('mouseout', function(e){
					if (!e.relatedTarget.up('.dropdown')) BH.toggleDropdown(e.findElement('DIV.dropdown'));							
				});

			}	
	
	}


	, clearInputValue: function(input, initial) {
		
		input.onfocus = function() {
			if (input.value == initial) input.value = '';
		}

		input.onblur = function() {
			if (input.value == '') input.value = initial;
		}

	}


	, toggleCareerDesc: function(num) {	
			$('jobdesc_'+num).toggleClassName('hide');
	}
	
	, openNav: function(x) {	
			var height = ((x == "true") || (x === true)) ? 400 : 144;
			return this.resizeFlash('header', height);

	}

	, resizeFlash: function(elem, height) {
			if (!elem || !height) return;
			
			//alert('resizeFlash: '+elem+': '+height);

			$(elem+'-content').setStyle({height: height+'px'});

			setTimeout(function(){
				$(elem+'-swf').setStyle({height: height+'px'});
			},10);

			return true;
	}

	, openWindow: function(url, params) {
			if (!url) return;
			
			var height 		= params.height || 300;
			var width 		= params.width 	|| 300;
			var scroll 		= params.scroll	|| 'no';
			var name 		= params.name 	|| 'PopWindow';

			var left		= (screen.width - width) / 2;
			var top 		= (screen.height - height) / 2;

			winprops 		= 'height='+height+',width='+width+',top='+top+',left='+left+',resizable=0,scrollbars='+scroll;
		
			openwindow = window.open(url, name, winprops);
			openwindow.focus();
	}



};



/* ACCORDIAN LIST
 ---------------------------------------------------------------- */

BH.acordianList = {

	list 		: ''
	, close_btn	: false

	, init: function(list) {
	
			if (!list) return;

			this.list = list;
			
			$(list).observe('click', function(e){

				if (e.findElement('A')) { return; }
				if (e.findElement('DIV').hasClassName('content')) { e.stop(); return; }
				if (!(element = e.findElement('LI'))) return; 
				if (!(element.up('UL', 0).hasClassName('text_list'))) return;

				//console.log(element);
				
				// Hand off
				BH.acordianList.toggle(element);

			});

	
	}
	
	, toggle: function(current_item) {
	
			var opener 	= current_item.down('DIV.opener');
			var title 	= current_item.down('SPAN.title');
			if (!opener) return;
	
			if (current_item.hasClassName('open')) {

				// Close item
				
				Effect.BlindUp(opener, {
					duration		: 0.3
					, beforeStart: function() {
					
						new Effect.Morph(title, {
							style: 'color:#27282c;'
							, duration: 0.2
						});
					}
					, afterFinish: function() {
						current_item.removeClassName('open');
					}

				});

			} else {
			
				// Open item
				
				this.addCloseBtn();

				Effect.BlindDown(opener, {
					duration		: 0.3
					, beforeStart: function() {
						current_item.addClassName('open');

						new Effect.Morph(title, {
							style: 'color:#d60000;'
							, duration: 0.2
						});
					}
				});
			
			}
	
	}

	, addCloseBtn: function() {
		
		if (this.close_btn) return;

		$(this.list).insert({after: '<a href="#" class="text_list_button clearfix" onclick="BH.acordianList.closeAll(this);">( Collapse All )</a>'});
		this.close_btn = true;
	
	}

	, closeAll: function(btn) {
		
		// Remove close button
		btn.remove();
		this.close_btn = false;
	
		// Trigger close on all open elements
		$(this.list).select('LI.open').each(function(i){
			BH.acordianList.toggle(i);
		});
	
	
	}


};


/* FEATURE SET
 ---------------------------------------------------------------- */

BH.featureSet = {

	current : 1
	, count : 1
	, set	: false
	, nav	: false

	, init: function(set, count) {

			if (!set) return;

			var height = $(set).getHeight();
			
			if (height > 0) {
				$(set).setStyle({
					height: $(set).getHeight() + 'px'
				});
			}
			
			// Add item ids
			var i = 1;
			$$('#'+set+' .fi').each(function(item){
				item.setAttribute('id', 'fi_'+set+'_'+i);
				i++;
			});

			return true;			
			
			
	}

	, _getOptions: function(set) {

		this.count 		= $F(set+'_count');
		this.nav 		= $(set+'_nav') ? $F(set+'_nav') : 'undefined';
		this.current 	= $F(set+'_current');
		
		this.count		= parseInt(this.count);
		this.current	= parseInt(this.current);

//alert('count:'+this.count+'/current:'+this.current);
	}

	, next: function(set) {

			this._getOptions(set);

			var go = ((this.current + 1) > this.count) ? 1 : (parseInt(this.current) + 1);

			this._go(go, set);
	}

	, go: function(go, set) {

			this._getOptions(set);
			this._go(go, set);

	}

	, _go: function(go, set) {
	
			// alert('_go:: '+go+'/current:'+this.current);

			item_curr 	= $('fi_'+set+'_'+this.current);
			item_next 	= $('fi_'+set+'_'+go);

			item_curr.hide();
			item_next.show();
			doSifrReplace();

			/*
			Effect.Fade(item_curr, {
				duration		: 0.3
				, afterFinish	: function() {
					Effect.Appear(item_next, {
						duration		: 0.3
						, afterFinish	: function() {
							doSifrReplace();					
						}
					});				
				}
			});
			*/
			
			// Update nav
			if (this.nav && (this.nav != 'undefined')) {
			
				thenav = $(this.nav);
			
				thenav.select('A.current').each(function(a){
					a.removeClassName('current');
				});

				thenav.select('A.num'+go).each(function(a){
					a.addClassName('current');
				});
			}

			$(set+'_current').value = go;
			
			return true;
	
	}

};


/* AJAX LIST
 ---------------------------------------------------------------- */
BH.ajaxList = {

	init: function(url, list) {
			if (!list || !url) return;

			list = $(list);

			new Ajax.Request(url, {
				method: 'get'
				, onSuccess: function(transport) {
				
					json = transport.responseText.evalJSON();					
					json.jobs.each(function(job){
						list.insert({'bottom' : '<li><a href="#" onClick="BH.openWindow(\''+job.url+'\', {scroll: \'yes\', height: 500, width: 450}); return false;">'+job.location + ' - ' + job.description +'</a></li>'});
					});
				
				}
			});
			
	}

}
