var FBR = {

	toggleFooter: function(height) {
			
			// Close
			if (!height) height = 40;
			
			return this._resizeFlash($('footer_content','footer_swf'), height);
		
	}

	, toggleHeader: function(action) {

			if (parseInt(action) > 0) {
				height = parseInt(action);
			} else {
				height = (!action || action == 'close') ? 145 : 388;			
			}
			return this._resizeFlash($('header_content','header_swf'), height);
		
	}

	, _resizeFlash: function(items, height) {
	
			items.each(function(i){		
				i.setStyle({
					height: height+'px'
				});			
			});
	
			return true;
	
	}
	

	, toggleGuides: function() {
		$$('BODY').each(function(b) { b.toggleClassName('guides') });
	}
	
	, openWindow: function(url, params) {
			if (!url) return;
			
			// <a href="javascript:FBR.openWindow('http://www.google.com', {height: 600, width: 600});">OPEN</a>

			var height 	= params.height || 300;
			var width 	= params.width 	|| 300;
			var scroll 	= params.scroll	|| 'no';
			var name 	= params.name 	|| 'PopWindow';
			var resize 	= params.resize || 0;

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

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

	, pop : {
	
		width_padding	: 134
		, top_offset	: 100
		, is_init		: false	

		, overlay		: null
		, pop_content	: null
		, pop_table		: null
		, pop_image		: null

		, init: function() {
			
				var content_html = '<div id="pop_content" style="display: none;">'
								 + '<table id="pop_table" cellpadding="0" cellspacing="0">'
								 + '<tr>'
								 + '<td class="border_tl"></td>'
								 + '<td class="border_t"></td>'
								 + '<td class="border_tr"></td>'
								 + '</tr>'
								 + '<tr>'
								 + '<td class="border_l"></td>'
								 + '<td class="middle">'
								 + '<div class="close"><a href="#CLOSE" onClick="FBR.pop.hide(); return false;">CLOSE</a></div>'
								 + '<div class="image"></div>'
								 + '</td>'
								 + '<td class="border_r"></td>'
								 + '</tr>'
								 + '<tr>'
								 + '<td class="border_bl"></td>'
								 + '<td class="border_b"></td>'
								 + '<td class="border_br"></td>'
								 + '</tr>'
								 + '</table>'
								 + '</div>';
				
				var overlay_html = '<div id="pop_overlay" style="display: none;"></div>';
				
				$$('BODY').each(function(b){
					b.insert({top: content_html +overlay_html});
				});
				
				this.overlay 		= $('pop_overlay');
				this.pop_content 	= $('pop_content');
				this.pop_table 		= $('pop_table');
				this.pop_image 		= $('pop_table').down('.image');
				
				this.is_init 		= true;

				// Assign close listener to overlay
				this.overlay.observe('click', function() {
					FBR.pop.hide()
				});			


		
		}
		
		, show: function(img, width) {
		
			if (!this.is_init) this.init();

				// Set content window top offset based on scroll position
				if (!isIE6()) {
					this.pop_content.style.top = (($('body').viewportOffset()[1] * -1) + this.top_offset) + 'px';
				}

				this._setImage(img);

				this.overlay.show();
				this.pop_content.show();

				//if (width) this.pop_table.setStyle({width: (width + this.width_padding) + 'px'});		
				//return false;
							
		}

		, _setImage: function(a) {			if (!a) return false;
			this.pop_image.update('<img src="' + a + '"/>');		
		}

		, hide: function() {
				this.overlay.hide();
				this.pop_content.hide();
		}
	
	}

	, 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')) {
						FBR.toggleDropdown(e.findElement('DIV.dropdown'));							
						drop.stopObserving('mouseout');
					}
				});

			}	
	
	}

	, selectDropdown: function(num, item) {
			
			drop 	= (parseFloat(num)) ? $('dropdown_'+num) : num;
			button	= drop.down('a.button');
			
			button.update(item.innerHTML);
			
			FBR.toggleDropdown(num);
	
	}

	
	, dropdownOption: function(list, num) {
		
			if (!list) return;
			if (!num) return;
			
			var items = $(list).select('div.option');
			
			items.each(function(i){ i.hide(); });
	
			$(list).down('div.option_'+num).show();
			
			drawSIFR();
	
	
	}


	, targetBlank : {
	
			init: function() {
	
				$$('A').each(function(a) {
					if (a.href && a.href.indexOf('ContactForm') > 0) {
						a.onclick = FBR.targetBlank.open;
					}
				});
			
			}

			, open: function(e) {

				// Accommodate IE's non-standard event handling.
				if (!e) var e = window.event;
				var a = e.target ? e.target : e.srcElement;
		
				// Open a new window with the link's href.
				var newwin = window.open(a.href);
		
				// The thought is that if the new window didn't
				// (popups blocked or whatever) we want to return
				// true so the link is follow normally. Not sure
				// if this works, but it doesn't seem to hinder.
				return !newwin;                               
			
			}
	}
	
};


document.observe('dom:loaded', function(event) {
	FBR.targetBlank.init();
});

function isIE() {
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function isIE6() {
	var version = parseInt(navigator.appVersion.split('MSIE')[1]);
	return (version == 6);
}

