// Execute when the DOM tree is ready
window.addEvent('domready', function(){
	new Asset.images(['http://www.colorbearers.com/staging/images/buttons/watch_trailer_btn.png', 'http://www.colorbearers.com/staging/images/buttons/watch_trailer_active_btn.png']);

	// Add open in new window functionality
	$E('html').getElements('a[rel=external]').each(function(a) {
		a.addEvent('click', function(e) {
			e = new Event(e);
			window.open(a.href);
			e.stop();
		})
	})
	
	// Make Submit Buttons Links
	$ES('input.submit').each(function (input) {
		var subLink = new Element('a');
		subLink.setProperty('href', '#');
		subLink.addClass('sendit');
		subLink.setText(input.value);
		subLink.addEvent('click', function (e) {
			e = new Event(e);
			// check if form validation is required - affects only forms
			if ($E('.validate')) {
				submitValidParentForm(this);
			} else {
				submitParentForm(this);
			}
			e.stop();
		});
		input.replaceWith(subLink);
	});
	
	
	var accordion = new Accordion('h5.toggler', 'div.acc_content', {
		opacity: false,
		alwaysHide: true,
		start: 'all-closed',
		duration: 600
	}, $('accordion'));
	
	
	 $$('a.readMore').each(function(a){
 
		 var block = a.getNext();

		 var fx = new Fx.Slide(block).hide();
		 block.removeClass('hide');	
 		 //if (block != current) fx.hide();

		 a.addEvent('click', function(){
		
 		 fx.toggle();
 	});

 });
	
});

if(window.ie6) {
	window.addEvent('domready', function(){
		$ES('#main_nav span').each(function (s) {
			s.addEvent('mouseenter', function(e) {
				s.setStyle('background-color', '#005590');
			});
			
			s.addEvent('mouseleave', function(e) {
				s.setStyle('background-color', '#000000');
			});
		});								 
	});
}

function submitParentForm(el) {
	var parent = el.getParent();
	while (parent.getTag() != 'form') {
		parent = parent.getParent();
	}
	parent.submit();
}

function submitValidParentForm(el) {
	var parent = el.getParent();
	while (parent.getTag() != 'form') {
		parent = parent.getParent();
	}
	if(formValid.validate()){
		parent.submit();
	}
}

try {
 document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
	