/**
 * $Id: js.js 35 2009-03-11 20:39:51Z jlencion $
 * @version $Revision: 35 $
 * @date $Date: 2009-03-11 15:39:51 -0500 (Wed, 11 Mar 2009) $
 */
var currentlyViewing	= null;

var calendar = {
	navHook: function(container)
	{
		currentlyViewing	= jQuery.trim($('#type-nav').text());
		
		$(container + ' .select').click(function() {
			if (!$('#' + $(this).attr('id') + '-options-open').length) // open the options
			{
				calendar.select($(this));
				return false;
			}
			else // close the options
			{
				calendar.deselect();
				return false;
			}
		});
		
		$(container + ' form input:first').focus(function() {
			this.select();
		});
		
		$(container + ' form').submit(function() {
			$(this).after(' Loading&hellip;');
			window.location	= $(this).attr('action') + $(this).find('input:first').val();
			return false;
		});
	}, // navHook()
	
	select: function(clicked)
	{
		calendar.deselect();
			
		var id		= clicked.attr('id');
		var text	= jQuery.trim(clicked.text());
		
		clicked.addClass('selected');
		clicked.append('<ul id="' + id + '-options-open" class="options options-shown" style="display: none;">' + $('#' + id + '-options').html() + '</ul>');
		$('#title-nav .options-shown').css('top', (clicked.height() + 2) + 'px').slideDown(100);
		
		$('#title-nav .options-shown li').one('click', function(){
			calendar.optionsClick($(this), id);
			return false;
		});
		
		$('body').one('click', function(){
			calendar.deselect();
		});
		
		return false;
	}, // select()
	
	deselect: function()
	{
		$('#title-nav .options-shown')
			.removeClass('options-shown')
			.stop()
			.fadeTo(1, .8)
			.slideUp(100, function() { $(this).remove(); });
		
		$('#title-nav .selected').removeClass('selected');
	}, // deselect()
	
	optionsClick: function(clicked, selectId)
	{
		newLocation	= null;
		
		clicked.parent().parent().text(clicked.text());
		calendar.deselect();
		
		var clickedText	= jQuery.trim(clicked.text());
		switch(clickedText)
		{
			case 'All items':
				$('#third').html('');
				newLocation	= '/calendar/' + date + '/';
			break; // All items
			
			case 'Search':
				$('#third').html(' / ' + $('#search-nav-options').html());
				$('#third form input:first').focus();
				calendar.navHook('#third');
			break; // Search
			
			default:
				switch(selectId)
				{
					case 'type-nav':
						var name = clicked.text().toLowerCase();
						$('#third').html(' /&nbsp;<span id="' + name + '-nav" class="select">Select your ' + name + '&hellip;</span>');
						calendar.navHook('#third');
						calendar.select($('#' + name + '-nav'));
						return false;
					break; // type-nav
					
					case 'sport-nav':
						newLocation	= '/calendar/category/Athletic/' + encodeURIComponent(encodeURIComponent(clickedText)) + '/' + date + '/';
					break; // sport-nav
					
					default:
						newLocation	= '/calendar/' + encodeURIComponent(encodeURIComponent(jQuery.trim($('#type-nav').text()))) + '/' + encodeURIComponent(encodeURIComponent(clickedText)) + '/' + date + '/';
					break; // default
				} // switch
			break; // default
		} // switch
		
		if (clickedText != currentlyViewing && newLocation)
		{
			$('#third').append(' Loading&hellip;');
			window.location	= newLocation;
		}
		
		return false;
	} // optionsClick()
};

$.datepicker.setDefaults({
	changeMonth: false,
    changeYear: false,
    changeFirstDay: false,
	showOtherMonths: true,
	
	prevText: '&#x25C0;',
	nextText: '&#x25B6;',
	currentText: '',
	dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
});

admin.autoSubtitle	= false;