var menu_slide_down_speed = 200;

//Bind mouse enter and mouse leave events for relevant menus
$(function() {
	
	//Make jquery style buttons
	$('.button').button();
		
	//Fade in the main container and then fade in the social media links
	//$('#main').fadeIn(600, function(){
		$('#social_media').delay(3000).fadeIn('slow');
	//});

	//Sub menu item
	$('#li_menu_item_2').hover(
		function(){	
			//Show nothing on enter
			$('#sub_menu_item_2').slideDown(menu_slide_down_speed);	
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_2').fadeOut(menu_slide_down_speed);	
		}
	);
	$('#sub_menu_item_2').hover(
		function(){	
			//Do nothing on enter
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_2').fadeOut(menu_slide_down_speed);	
		}
	);
	
	//Next menu item
	$('#li_menu_item_3').hover(
		function(){	
			//Show nothing on enter
			$('#sub_menu_item_3').slideDown(menu_slide_down_speed);	
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_3').fadeOut(menu_slide_down_speed);	
		}
	);
	$('#sub_menu_item_3').hover(
		function(){	
			//Do nothing on enter
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_3').fadeOut(menu_slide_down_speed);	
		}
	);

	//Next menu item
	$('#li_menu_item_4').hover(
		function(){	
			//Show nothing on enter
			$('#sub_menu_item_4').slideDown(menu_slide_down_speed);	
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_4').fadeOut(menu_slide_down_speed);	
		}
	);
	$('#sub_menu_item_4').hover(
		function(){	
			//Do nothing on enter
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_4').fadeOut(menu_slide_down_speed);	
		}
	);
	
	//Next menu item
	$('#li_menu_item_5').hover(
		function(){	
			//Show nothing on enter
			$('#sub_menu_item_5').slideDown(menu_slide_down_speed);	
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_5').fadeOut(menu_slide_down_speed);	
		}
	);
	$('#sub_menu_item_5').hover(
		function(){	
			//Do nothing on enter
		},
		function(){
			//on mouse leave slideUp the sub menu
			$('#sub_menu_item_5').fadeOut(menu_slide_down_speed);	
		}
	);
});


/*
<!-- Sponsors rotator START -->
var slideShowSpeed = 4000; //2 seconds
var divNum = 1; //starting div number
var numberOfSponsorDivs = 2;

var menu_slide_down_speed = 200;
function runSlideShow()
{
	//Hide all first
	for (i=1; i<=numberOfSponsorDivs; i++)
	{	
		$('#sponsor_div_' + i).hide();	
	}
	
	//Show current divNum
	$('#sponsor_div_' + divNum).fadeIn('slow');	
	
	//Increment divNum if we hvae not reached the numberOfSponsorDivs

if(divNum != numberOfSponsorDivs)
	{
		divNum = divNum + 1;
	}
	else //Set back to 1
	{
		divNum = 1;
	}
	
	var t = setTimeout('runSlideShow()', slideShowSpeed);
}
/
<!-- Sponsors rotator END -->
*/

//Used for right column items
function toggleAndChangeHeading(obj, title)
{
	if($(obj).next().is(':hidden'))
	{
		$(obj).html('&#8657;&nbsp;' + title + '&nbsp;&#8657;');
	}
	else
	{
		$(obj).html('&dArr;&nbsp;' + title + '&nbsp;&dArr;') ;
	}
	//SlideToggle needs to go after if statement to ensure that the display has changed from none to block and vice-versa
	$(obj).next().slideToggle();
}

//News item read more/less links
/*
function ReadMore(obj) {
	$(obj).hide();
	$(obj).next().fadeIn('slow');
}
function ReadLess(obj) {
	//Fade out the link
	$(obj).hide(); 
	//Fade out the text and when complete then fade in the read more link
	$(obj).prevUntil('span').fadeOut('slow',function(){
		$(obj).parent().prev('.more_less').fadeIn('slow');
	}); 
}
*/
function ReadMore(num) {
	$('#read_more_link_' + num).hide();
	$('#read_more_text_' + num).slideDown('slow');
}
function ReadLess(num) {
	//Fade out the text and when complete then fade in the read more link
	$('#read_more_text_' + num).slideUp('slow', function(){
		$('#read_more_link_' + num).fadeIn('slow');
	});
}

//Show the loading panel div (located in lay_defaultLayout.cfm) when a user presses onclick just before the page load 
function ShowLoading(txt){
	if(txt != ''){
		$('#loadingPopup span').html(txt);
	}
	//$('#loadingPopup').slideDown(300);
	$('#loadingPopup').show('fast');

	//Block user activity on the page 	
	$.blockUI({
		message: 	null, 
		overlayCSS:{
			opacity:			0.4,
			backgroundColor:	'#525252'
		}
	});
}
function HideLoading () {
	$('#loadingPopup').hide();
	$.unblockUI();
}

//General dialog popup
function ShowGeneralAlert(ttl, msg, loader){
	//Set the title and message
	$('#alert_popup').attr('title', ttl);
	$('#alert_msg').html(msg);

	//Popup the form
	$('#alert_popup').dialog({
		width: 500,
		minHeight: 100,
		modal: true,
		show: 'fade',
		hide: 'fade',
		autoOpen: false
	});

	if(loader == true) {
		$('#alert_loader').css('display','inline');
		//No buttons
		$('#alert_popup').dialog({
			buttons: {}
		});
	}
	else {
		$('#alert_loader').css('display','none');

		//Add Close button as this is a message
		$('#alert_popup').dialog({
			buttons: {
				Close: function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}
	
	//Open it now
	$('#alert_popup').dialog('open');
}

function HideGeneralAlert () {
	//Popup the form
	$('#alert_popup').dialog('close');
}

function SortPlayerStatsTable (col) {
	ShowGeneralAlert('Sorting Table', 'Please wait - Updating table...', true);
	$('#ajax_player_statistics').load('../pages/player_statistics/ajax_sortTable.cfm?nolayout&sort_col=' + col, function(){
		HideGeneralAlert ();
	});	
}

function FilterByMatch (val) {
	ShowGeneralAlert('Filtering Table', 'Please wait - Updating table...', true);
	$('#ajax_player_statistics').load('../pages/player_statistics/ajax_filterTable.cfm?nolayout&news_id=' + val, function(){
		HideGeneralAlert ();
	});	
}
