window.addEvent('domready',function() {
	SetSlant();
	SetAccordion();
	
	// Fix IE6's background image problem for the triangular image portal
	if (Browser.Engine.trident && Browser.Engine.version == 4 && $('content_wrapper').className == 'slanted') {
		$('content_wrapper').setStyle('background-image','url("/images/background-slant.gif")');
	}
	if ($('return_info')) {
		TripTyper($('direction').value);
	}
});

function SetSlant() {
	if ($('slant')) {
		var size = $('slant').getSize();
		var current = $('slant');
		
		while (size.x > 0 & current.getCoordinates().bottom < $('content').getCoordinates().bottom) {
			var current = current.clone().injectAfter(current).setStyle('width', (size.x -= size.y) + 'px');
		}
	}
}

function SetAccordion() {
	if ($$('.toggler').length) {
		var myAccordion = new Accordion($$('.toggler'), $$('.togglee'), {
			show: -1,
			alwaysHide: true,

			onActive: function(toggler) { toggler.addClass('selected'); },
			onBackground: function(toggler) { toggler.removeClass('selected'); }

		});
	}
}

function TripTyper(type) {
	if (type == 'One Way') {
		$('return_info').fade('hide');
		$('return_date').value = '';
		$('return_info').setStyle('display','none');
		
		if (!window.OWCalendar) {
			OWCalendar = new Calendar({ departure_date: 'm/d/Y' }, { direction: 1, draggable: true, pad: 0 } );
		}
	}
	else if (type == 'Round Trip') {
		$('return_info').setStyle('display','table-row-group');
		$('return_info').fade('in');

		if (!window.RTCalendar) {
			RTCalendar = new Calendar({ return_date: 'm/d/Y' }, { direction: 1, draggable: true, pad: 0 } );
		}
	}
}


