// JavaScript Document

function riddell_DropDownAnimations( button, list ) {
	jQuery(button).mouseenter(function() {
		offset = jQuery(this).offset();
		real_offset_top = offset.top - jQuery(document).scrollTop();
		jQuery(this).find(list)
			.css('height', 'auto')
			.css('overflowY', 'hidden')
			.css('maxHeight', 
				(jQuery(window).height() - real_offset_top - jQuery(this).height() - 62)+'px'
			)
			.stop()
			.slideDown(500, function() {
				if (jQuery(this).height() >= parseInt(jQuery(this).css('maxHeight').replace('px',''))){
					jQuery(this).css('overflowY', 'scroll');
				} else {
					jQuery(this).css('overflowY', 'hidden');
				}
			});
	});
	
	jQuery(button).mouseleave(function() {
		jQuery(this).find(list).stop().slideUp(250);
	});
}

function riddell_DropDownTieSelect( input, list ){
	if (typeof(input) == 'string') {
		input = jQuery(input);
	}
	
	if (typeof(list) == 'string') {
		list = jQuery(list);
	}
	
	input.find('option').each(function() {
		list.append('<span value="'+ jQuery(this).val() +'">'+ jQuery(this).text() +'</span>');
	});
	
	list.find('span').click(function() {
		jQuery(this).parent().find('span').removeClass('on');
		jQuery(this).addClass('on');
		jQuery(this).parents('li').find('option[value="'+ jQuery(this).attr('value') +'"]').attr('selected', 'selected');
	});
}

jQuery(document).ready(function() {
	riddell_DropDownAnimations('.filter', '.filter_list');
});
