$(document).ready(function(){AaronDugan.Init();});

var AaronDugan = {
	Settings:{
		FooterOpacity:0.2
	},
	Init:function(){
		AaronDugan.InitSifr();
		AaronDugan.InitMediaBox();
		AaronDugan.InitLightBox();
		AaronDugan.InitContactForm();
		AaronDugan.InitFooter();
	},
	InitSifr:function(){
		$('h1').flash(
			{ 
				src: 'flash/32impact.swf',
				wmode: 'transparent',
				flashvars: { 
					css: [
						'* {color:#790E25;background:transparent;}',
						'h1 {color:#002a89;}',
						'a {color:#0099CC; text-decoration: none;}',
						'a:hover {text-decoration: underline;}'
					].join(' ')
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));						
			}
		);
	    
		$('h2').flash(
			{ 
				src: 'flash/32impact.swf',
				wmode: 'transparent',
				flashvars: { 
					css: [
						'* {color:#002a89;background:transparent;}',
						'a {color:#0099CC; text-decoration: none;}',
						'a:hover {text-decoration: underline;}'
					].join(' ')
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));						
			}
		);
		
		$('#sidebar h4').flash(
			{ 
				src: 'flash/helveticanueue-boldcondensed.swf',
				wmode: 'transparent',
				flashvars: { 
					css: [
						'* {color:#333333;background:transparent;}'
					].join(' ')
				}
			},
			{ version: 7 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = '30px';
				htmlOptions.width = '220px';
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));						
			}
		);
	},
	InitMediaBox:function(){
		$('.media').mediabox();
	},
	InitLightBox:function(){
		$('a.lightbox').lightBox();
	},
	InitContactForm:function(){
		// add has-error on page load to account for captcha
		$('.error:visible').each(function(){
			$(this).parent('li').addClass('has-error');
		});
		
		$('body#contact fieldset input:text, body#contact fieldset textarea').change(function(){
			if($(this).siblings('.error:visible').size() > 0){
				$(this).parent('li').addClass('has-error');
			}
			else {
				$(this).parent('li').removeClass('has-error');
			}
		});
		$('body#contact fieldset input.button').click(function(){
			// disable is there are no other error messages
//			if($('.error:visible').size() == 0){
//				$('body#contact input:submit')[0].disabled = true;
//			}
		
			$('body#contact fieldset input:text, body#contact fieldset textarea').each(function(i){
				if($(this).siblings('.error:visible').size() > 0){
					$(this).parent('li').addClass('has-error');
				}
				else {
					$(this).parent('li').removeClass('has-error');
				}
			});
		});
	},
	InitFooter:function(){
		$('#footer').fadeTo(0,AaronDugan.Settings.FooterOpacity);
		
		$('#footer').hover(
			function(){$(this).fadeTo('normal',1.0);},
			function(){$(this).fadeTo('normal',AaronDugan.Settings.FooterOpacity);}
		);
	}
};