$(document).ready(function(){
	$('#main_nav a.off + ul.sub-nav').parent().addClass('closed');
	$('#main_nav a.on + ul.sub-nav').css({visibility: "visible",display: "block"}).parent().addClass('open');
	if (!$.browser.msie6) {
	    	$("#main_nav > ul li.closed").hoverIntent(config);
	 }
	$('#member_nav a:contains("Members")').eq(0).addClass('member-trigger');
	$('a.member-trigger').toggle(function(){
		$('div.wrong-login').hide();
		$('#member_login').fadeIn('slow');
	},
	function(){
		$('#member_login').fadeOut('fast');
	});
	$('#search input.search-box').focus(function () {
		$(this).css('background-image','none');
	});
	$('#team_logos a.team-logo').each(function(index){
		$(this).hover(function(){
			$(this).children('span.hover-'+(index+1)+'').fadeIn(500).css('display','block');
		},
		function(){
			$(this).children('span.hover-'+(index+1)+'').fadeOut(500).css('display','none');
		});
	});
	$('#soccer_logos a.soccer-logo').each(function(index){
		$(this).hover(function(){
			$(this).children('span.hover-'+(index+1)+'').fadeIn(500);
		},
		function(){
			$(this).children('span.hover-'+(index+1)+'').fadeOut(500);
		});
	});
	$('#cal_right').click(function(){		
		$('.cal-div:visible').hide().next().show();
		
		if($('.cal-div:visible').attr('id') == 'cal_12') {
			$(this).hide();
			
		} else if( $('.cal-div:visible').attr('id') == 'cal_2') {
			$('#cal_left').show();
		}
	});
	$('#cal_left').click(function(){
		$('.cal-div:visible').hide().prev().show();	
		
		if($('.cal-div:visible').attr('id') == 'cal_1') {
			$(this).hide();
			
		} else if( $('.cal-div:visible').attr('id') == 'cal_11') {
			$('#cal_right').show();
		}
	});
	$('table#myTable').tablesorter({ 
		headers: {
		0: { sorter: false }
		},
		widgets: ['zebra'] 
	});
	$('table.cal a').hoverIntent(function(){
		var eventTitle = $(this).attr('title');
		$('#widget_event_title').fadeIn(500).html(eventTitle);
	},
	function(){
		$('#widget_event_title').fadeOut(200);
	});
	if($.browser.msie){
		$("input").keypress(function (e) {  
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
			    $('input.button').click();  
			    return false;  
			} else {  
			    return true;  
			}  
		});
	}
	$('p#login_required').hide();
	if($.browser.msie){
		$('div#team_logos a', this).click(function(){
			//var teamURL = (location.href = this.href);
			window.open(this.href,'_blank');
			return false;
		});
		$('div#soccer_logos a', this).click(function(){
			//var teamURL = (location.href = this.href);
			window.open(this.href,'_blank');
			return false;
		});
	}
});
var config = {    
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over: hoverOn, // function = onMouseOver callback (REQUIRED)    
     timeout: 300, // number = milliseconds delay before onMouseOut    
     out: hoverOff // function = onMouseOut callback (REQUIRED)    
};

function hoverOn(){
	$(this).find('ul.sub-nav').css({visibility: "visible",display: "none"}).slideDown(600, function(){
		$(this).css("display", "block");
	}); 
}
function hoverOff(){
	$(this).find('ul.sub-nav').slideUp(400, function(){
		$(this).css("display", "none");
	}); 
}
