var t = 0;
var update_dt_ms = 1000;
var isgmt = 0;
var timezone = "Europe/London";
var timezone2 = "Asia\/Hong_Kong";

function InitJClock()
{
	$(function($) {
		var optionsHKT = {
				utc: true,
				utcOffset: 8,
				//format: '%A %B %d, %Y %I:%M:%S %p' // 12-hour
				format: 'HKT  %A %B %d, %Y %H:%M:%S' // 12-hour
				}
				
		
      $('#jclock1').jclock(optionsHKT);
	});
	
	$(function($) {
		var optionsGMT = {
				utc: true,
				utcOffset: 0,
				//format: '%A %B %d, %Y %I:%M:%S %p' // 12-hour
				format: 'GMT %A %B %d, %Y %H:%M:%S' // 12-hour
				}
				
		
      $('#jclock2').jclock(optionsGMT);
	});	
}

function createBookmark(){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title,location.href,"");
	}else if( window.external ) { // IE Favorite
		window.external.AddFavorite(location.href,document.title);
	}else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function init_submenu()
{
	ddsmoothmenu.init({
		mainmenuid: "smoothmenu1", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})

	ddsmoothmenu.init({
		mainmenuid: "smoothmenu2", //Menu DIV id
		orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
		//customtheme: ["#804000", "#482400"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})	
}
function toggle_datetime()
{
	
	
	if (isgmt%2 == 0)
	{
		timezone = "Europe/London";
		$('#datatime_switch').html("GMT");
		$('#datetime').removeClass("hkt");
		$('#datetime').toggleClass("gmt");
	}
	else
	{
		timezone = "Asia\/Hong_Kong";
		$('#datatime_switch').html("HKT");
		$('#datetime').removeClass("gmt");
		$('#datetime').toggleClass("hkt");
	}
	update_datetime();	
	
	isgmt++;
}

function update_datetime()
{
	
	$.getJSON("http://json-time.appspot.com/time.json?tz="+timezone+"&callback=?",
			function(data){
				$('#datetime').html("GMT " + data.datetime);
				
			})	
	$.getJSON("http://json-time.appspot.com/time.json?tz="+timezone2+"&callback=?",
					function(data){
						$('#datetime2').html("HKT " + data.datetime);
						
					})	
	
}


$(document).ready(function(){
	//$("a[rel^='prettyPhoto']").prettyPhoto();
	InitJClock();
	
	if (search_text != ''){
		//$("#rightcontent:contains(" + search_text + ")").css("background-color", "#ff0000");
		$('#SearchResultList:contains("'+search_text+'")').each(function(){  
			$(this).html($(this).html().replace(new RegExp(search_text,'g'), '<span class="searchhighlight">'+search_text+'</span>'));  
			$(this).find('span.searchhighlight').fadeIn("slow");  
		});  		
	}

	$('a.MySubmitButton').click( function(ev) {
		ev.preventDefault();
		if ($(this).attr('target') != '') {
			$('#' + $(this).attr('target')).submit();
		}
	});
	

	
	//t = setInterval(update_datetime, update_dt_ms);
	
	$("#newslist tr:odd").css("background-color", "#66ff66");
	$("#newslist tr:even").css("background-color", "#ccffcc");

	$("#calendar tr:odd").css("background-color", "#66ff66");
	$("#calendar tr:even").css("background-color", "#ccffcc");
	
	$("#editor tr:odd").css("background-color", "#ffffce");
	$("#editor tr:even").css("background-color", "#ffff9a");
	
	//$('#flash').wrap("<a rel='prettyPhoto[iframe]' href='ad.html?iframe=true&amp;width=50%&amp;height=20%'/>");
	
	

	//pro players
	$("#playercontent.color_4033 tr:odd").each(function(intIndex) 
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4033 tr:odd").eq(intIndex).css("background-color", "#ffcc66");
			}
		}
	);
	
	//men players
	$("#playercontent.color_4036 tr:odd").each(function(intIndex) 
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4036 tr:odd").eq(intIndex).css("background-color", "#6666ff");
			}
		}
	);
	
	//ladies players
	$("#playercontent.color_4037 tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4037 tr:odd").eq(intIndex).css("background-color", "#ff99cc");
			}
		}
	);
	
	//master players
	$("#playercontent.color_4039 tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4039 tr:odd").eq(intIndex).css("background-color", "#339933");
			}
		}
	);	
	//youth players
	$("#playercontent.color_4038 tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4038 tr:odd").eq(intIndex).css("background-color", "#ccffcc");
			}
		}
	);		
	//member players
	$("#playercontent.color_4035 tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4035 tr:odd").eq(intIndex).css("background-color", "#ccffff");
			}
		}
	);		
	//referee players
	$("#playercontent.color_4041 tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_4041 tr:odd").eq(intIndex).css("background-color", "#999999");
			}
		}
	);
	//sample players
	$("#playercontent.color_ tr:odd").each(function(intIndex)
		{
			if (intIndex < 7)
			{
				$("#playercontent.color_ tr:odd").eq(intIndex).css("background-color", "#ffcc66");
			}
		}
	);		
	
	 var myvalue = "url('" +  $('.frontpage_headline_img img').attr("src") + "')";
	 $('.frontpage_headline_real_img').css({"background-image":myvalue});
	
	 $(".GalleryListDesc_Subhead_Block").hover(function() {
			$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
			$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
				.animate({
					marginTop: '-110px', /* The next 4 lines will vertically align this image */ 
					marginLeft: '-110px',
					top: '50%',
					left: '50%',
					width: '200px', /* Set new width */
					height: '150px', /* Set new height */
					padding: '5px'
					
				}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

			} , function() {
			$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
			$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
				.animate({
					marginTop: '0', /* Set alignment back to default */
					marginLeft: '0',
					top: '0',
					left: '0',
					width: '66px', /* Set width back to default */
					height: '50px', /* Set height back to default */
					padding: '0px'
				}, 400);
		});
	 
	 //$("*[class^=prettyPhoto]").prettyPhoto();
	 

});

$(window).load(function() {

	/*
	 * To make sure the image won't exceed claimed width
	 */
	$(".layout_main_70 img").each( function(intIndex) 
		{
			if ($(this).width() > 530 )
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");	
				$(this).css("width", "520px");
			}
			
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");		
				$(this).wrap("<a title='' rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
		}	
	
	);
	
	$(".layout_side_30 img").each( function(intIndex) 
		{
			if ($(this).width() > 200)
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "200px");				
				
			}	
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
			
		}			
	);	

	$(".layout_main_50 img").each( function(intIndex) 
	{
			if ($(this).width() > 350 )
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "350px");
			}
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
			
		}	
	
	);
	
	$(".layout_side_50 img").each( function(intIndex) 
		{
			if ($(this).width() > 350)
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "350px");				
				
			}	
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
			
		}			
	);		
	

	$(".layout_main_60 img").each( function(intIndex) 
	{
			if ($(this).width() > 440 )
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "440px");
			}
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
		}	
	
	);
	
	$(".layout_side_40 img").each( function(intIndex) 
		{
			if ($(this).width() > 270)
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "270px");				
				
			}	
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
		}			
	);	
	
	$(".layout_main_100 img").each( function(intIndex) 
	{
			if ($(this).width() > 750 )
			{
				$(this).removeAttr("width");
				$(this).removeAttr("height");
	
				$(this).css("width", "750px");
			}
			if ($(this).parent("a").length <= 0)
			{
				var src = $(this).attr("src");
				$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
			}
			
		}	
	
	);	

	// adding prettyphoto to 1col
	$("#aboutus img").each( function(intIndex) 
			{
				if ($(this).width() > 270)
				{
					if (!$(this).hasClass("noresize")) {
						$(this).removeAttr("width");
						$(this).removeAttr("height");
						
						
						$(this).css("width", "270px");
					}
					
				}	
				if ($(this).parent("a").length <= 0)
				{
					var src = $(this).attr("src");
					$(this).wrap("<a rel='prettyPhoto[Media]' href='" + src + "'></a>");
				}
			}			
		);		

	$(function() {
		$("div#makeMeScrollable").smoothDivScroll({ autoScroll: "always", autoScrollDirection: "endlessloopright", autoScrollStep: 1, autoScrollInterval: 100, visibleHotSpots: "always"});
	});
	
	$("*[rel^=prettyPhoto]").prettyPhoto();
});
