jQuery.preloadNaviImages = function() {
	for(var i = 0; i < arguments.length; i++) {
		jQuery("<img>").attr("src", siteurl + "/wp-content/themes/wsg/images/generic_icons/" + arguments[i]);
	}
}
jQuery.preloadHomeImages = function() {
	for(var i = 0; i < arguments.length; i++) {
		jQuery("<img>").attr("src", siteurl + "/wp-content/themes/wsg/images/post_icons/" + arguments[i]);
	}
}

jQuery("<img>").attr("src", siteurl + "/wp-content/themes/wsg/images/bg_sidebar_current.gif");

jQuery.preloadHomeImages("00_o_afc.jpg", "00_o_afc_ovr.jpg", "00_o_fifa.jpg", "00_o_fifa_ovr.jpg", "00_o_omega.jpg", "00_o_omega_ovr.jpg");
jQuery.preloadNaviImages("08_press.png","08_press_ovr.png","08_partners.png","08_partners_ovr.png","08_sales.png","08_sales_ovr.png","08_assets.png","08_assets_ovr.png","08_services.png","08_services_ovr.png","08_home.png","08_home_ovr.png","08_aboutus.png","08_aboutus_ovr.png");
var tb_pathToImage = siteurl + "/wp-content/themes/wsg/js/thickbox/loadingAnimation.gif";
var tb_closeImage = siteurl + "/wp-content/themes/wsg/js/thickbox/tb-close.png";
var window_open_var = "width=900,height=940,left=0,top=0,toolbar=0,menubar=0,location=0,resizable=0,scrollbars=1,status=0";
function open_mangement_profile(profile) {
	window.open(siteurl + "/about-us/management/" + profile + "/printpage/", "_blank", window_open_var);
}
function open_senior_mangement_profile(profile) {
	window.open(siteurl + "/about-us/management/senior-management/" + profile + "/printpage/", "_blank", window_open_var);
}
function open_news(url) {
	window.open(url + "print/", "_blank", window_open_var);
}
function open_page_url(page) {
	window.open(page + "printpage/", "_blank", window_open_var);
}
function open_management_page() {
	window.open(siteurl + "/about-us/management/senior-management/", "_blank",  "width=820,height=836,left=0,top=0,toolbar=0,menubar=0,location=0,resizable=0,scrollbars=1,status=0");
}
function partners(array_num) {
	var quotes = new Array();
	quotes[0] = "The world's fastest growing sports marketing group.";
	quotes[1] = "The world's largest single-brand advertising company and top agency brand.";
	quotes[2] = "Key media player and rights owner in the Middle East.";
	quotes[3] = "The leading provider of digital media worldwide, creating and distributing a range of assets.";
	quotes[4] = "World leaders in monetising sport and entertainment content in digital media.";
	quotes[5] = "Key sports rights agency and consultancy in Australia.";
	quotes[6] = "The governing body of football in Asia.<div style=\"margin-top: 10px; font-size: 12px;\">Asian Football Confederation (AFC)</div>";
	quotes[7] = "The governing body of football in Southeast Asia.<div style=\"margin-top: 10px; font-size: 12px;\">ASEAN Football Federation (AFF)</div>";
	quotes[8] = "The governing body of golf in Southeast Asia.<div style=\"margin-top: 10px; font-size: 12px;\">ASEAN Golf Tour</div>";
	quotes[9] = "First ever Youth Games in Asia.<div style=\"margin-top: 10px; font-size: 12px;\">Asian Youth Games (AYG)</div>";
	quotes[10] = "Cricket's administrative body in India.<div style=\"margin-top: 10px; font-size: 12px;\">Board of Control for Cricket in India (BCCI)</div>";
	quotes[11] = "Golf's administrative body in China.<div style=\"margin-top: 10px; font-size: 12px;\">China Golf Association (CGA)</div>";
	quotes[12] = "The most successful twenty20 cricket league in the world.<div style=\"margin-top: 10px; font-size: 12px;\">DLF Indian Premier League (IPL)</div>";
	quotes[13] = "Government agency tasked with developing sport in Singapore.<div style=\"margin-top: 10px; font-size: 12px;\">Singapore Sports Council (SSC)</div>";
	quotes[14] = "Singapore's first-ever sports, lifestyle and entertainment hub.<div style=\"margin-top: 10px; font-size: 12px;\">Singapore Sports Hub (SSH)</div>";
	quotes[15] = "Governing body for football in the South Asian region.<div style=\"margin-top: 10px; font-size: 12px;\">South Asian Football Federation (SAFF)</div>";
	quotes[16] = "Governing body for football in West Asia.<div style=\"margin-top: 10px; font-size: 12px;\">West Asian Football Federation (WAFF)</div>";
	if(array_num == -1) {
		jQuery("#partner_quote").html("");
	} else {
		jQuery("#partner_quote").html(quotes[array_num]);
	}
}
function home_mouseover(icon_id, post_id, ext, state) {
	if(state == "over") {
		jQuery("#img-" + icon_id + '-' + post_id).attr('src', siteurl + "/wp-content/themes/wsg/images/post_icons/" + icon_id + "_ovr." + ext);
	} else if(state == "out") {
		jQuery("#img-" + icon_id + '-' + post_id).attr('src', siteurl + "/wp-content/themes/wsg/images/post_icons/" + icon_id + "." + ext);
	}
}
function show_network_map(country, state) {
	var countries = [ "singapore", "beijing", "beirut", "delhi", "hongkong", "mumbai", "tokyo" ];
	jQuery.each(countries, function(){
		if(state == "over") {
			if(this == country) {
				jQuery("#" + this).show();
			} else {
				jQuery("#" + this).hide();
			}
		} else if(state = "click") {
			if(this == country) {
				jQuery("#" + this).show();
			} else {
				jQuery("#" + this).hide();
			}
		} else if(state == "out") {
			jQuery("#" + this).hide();
		}
	});
}
function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
	return "";
	else
	return results[1];
}

function initMenus() {
	jQuery('ul.list-event-news ul').hide();
	/*
	jQuery.each(jQuery('ul.list-event-news'), function(){
		jQuery('#' + this.id + '.expandfirst ul:first').show();
	}); 
	
	jQuery.each(jQuery('ul.list-event-news li a'), function(){
		jQuery(this).attr('href', '#');									 
	});
	*/
	jQuery('.yrlink').click(
		function() {
			var checkElement = jQuery(this).next();
			var parent = this.parentNode.parentNode.id;

			if(jQuery('#' + parent).hasClass('noaccordion')) {
				jQuery(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if(jQuery('#' + parent).hasClass('collapsible')) {
					jQuery('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				jQuery('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

jQuery(document).ready(function() {
	var url = window.location.pathname;	
	initMenus();	
	if (gup('mn') == 3) {
		
		jQuery('.page-item-asian-football-newsletter ul#list-asian-football-newsletter').slideDown();	
		jQuery("#asian-football-newsletter-archives").hide();
		//jQuery(".event-news-year").hide();
				
		jQuery("#asian-football-newsletter-archiveslink").click(function () { 
			jQuery("#asian-football-newsletter-archives").slideToggle();		
		});
		
	} 
	else if (gup('mn') == 2) {
		
		jQuery('.page-item-event-news ul#list-event-news').slideDown();	
		jQuery("#event-news-archives").hide();
		jQuery(".event-news-year").hide();
				
		jQuery("#event-news-archiveslink").click(function () { 
			jQuery("#event-news-archives").slideToggle();		
		});
		
	} else if (gup('mn') == 1) {
	
		jQuery('.page-item-wsg-news ul#list-wsg-news').slideDown();
		jQuery("#wsg-news-archives").show();
		
		jQuery("#wsg-news-archiveslink").click(function () { 
				jQuery("#wsg-news-archives").slideToggle();				
			});			
		
	} else {	
		
		jQuery('ul.menu ul').hide();
	
		if (url.indexOf('wsg-news') > 0) {
			jQuery('.page-item-wsg-news ul#list-wsg-news').slideDown();
			
			jQuery("#wsg-news-archiveslink").click(function () { 
				jQuery("#wsg-news-archives").slideToggle();				
			});			
		} else if (url.indexOf('asian-football-newsletter') > 0) {
			jQuery('.page-item-asian-football-newsletter ul#list-asian-football-newsletter').slideDown();
			
			jQuery("#asian-football-newsletter-archiveslink").click(function () { 
				jQuery("#asian-football-newsletter-archives").slideToggle();				
			});			
		}else if (url.indexOf('event-news') > 0) {
			jQuery('.page-item-event-news ul#list-event-news').slideDown();
			jQuery("#event-news-archives").hide();
			jQuery(".event-news-year").hide();
				
			jQuery("#event-news-archiveslink").click(function () { 
				jQuery("#event-news-archives").slideToggle();				
			});
		}
		
	}
	
	if (gup('mn').length > 0) {
		jQuery('.expandfirst').parent().show();
		jQuery('.expandfirst ul').show();
	}	
	 	
	
	var in_32 = false;
	var in_42 = false;
	var in_52 = false;
	var in_56 = false;
	jQuery("#sidebar UL LI UL LI UL LI").each(function(){
		jQuery(this).prepend("- ");
	});
	jQuery("#sidebar .page-item-32 A:first, #sidebar .page-item-42 A:first").attr("href", "#");
	
	// Events
	jQuery("#sidebar .page-item-32 UL LI").each(function(){
		if(jQuery(this).is(".current_page_item")) {
			in_32 = true;
		}
	});
	
	if(!in_32) {
		jQuery("#sidebar .page-item-32 UL").hide();
	}
	jQuery("#sidebar .page-item-32 A:first").click(function () { 
      jQuery("#sidebar .page-item-32 UL").slideToggle(); 
    });
	// Programming
	jQuery("#sidebar .page-item-42 UL LI").each(function(){
		if(jQuery(this).is(".current_page_item")) {
			in_42 = true;
		}
	});
	if(!in_42) {
		jQuery("#sidebar .page-item-42 UL").hide();
	}
	jQuery("#sidebar .page-item-42 A:first").click(function () { 
      jQuery("#sidebar .page-item-42 UL").slideToggle(); 
    });
	// Venues
	jQuery("#sidebar .page-item-52 UL LI").each(function(){
		if(jQuery(this).is(".current_page_item")) {
			in_52 = true;
		}
	});
	if(!in_52 && !jQuery("#sidebar .page-item-52").is(".current_page_item")) {
		jQuery("#sidebar .page-item-52 UL").hide();
	}
	// Player Management
	/*
	jQuery("#sidebar .page-item-56 UL LI").each(function(){
		if(jQuery(this).is(".current_page_item")) {
			in_56 = true;
		}
	});
	if(!in_56) {
		jQuery("#sidebar .page-item-56 UL").hide();
	}
	jQuery("#sidebar .page-item-56 A:first").click(function () { 
      jQuery("#sidebar .page-item-56 UL").slideToggle(); 
    });
	*/
	jQuery("#sitemap UL LI UL LI").each(function() {
		jQuery(this).prepend("- ");
	});
	if(jQuery("map *").length > 0) {
		jQuery("map *").tooltip({ positionRight: true, showURL: false });
	}
	if(jQuery("#home_marquee").length > 0) {
		jQuery("#home_marquee marquee").marquee();
	}
});