
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

$(document).ready( function() {

	// body onload 
	MM_preloadImages('/english/images/home/but_give2.jpg');
	
	//Features - Start
	//var featureCurrentIndex = features_setting.bRandom ? Math.floor(Math.random()*features_data.length) : features_setting.iDefaultIndex;
	var features_data = [];
	var features_setting = {
		bRandom : false,
		iDefaultIndex : 0 // if bRandom is false, please set which feature is the default image when the main page is loaded.
	};
	var featuresTimeoutId;
	var featureCurrentIndex = features_setting.bRandom ? Math.floor(Math.random()*features_data.length): features_setting.iDefaultIndex;
	
	//Random arrangement
	//calling ajax to get the latest CUHK Features
	$.get("http://www.iso.cuhk.edu.hk/cuhk-website-services/iso/main-page-features-ajax.aspx", {"lang":"english"} , function(data) {
		if (data.status == "success") {
			features_data = data.structure;
			setFeature(featureCurrentIndex, false);
			featuresTimeoutId = setTimeout("FeaturesAutoRotate()", iFeatureRotateTime);
		}
	}, "jsonp");
	
	
	
	function setFeature(index, bAnim) {

		//Set up thumbnail		
		if (bAnim == false) {
			$("div#features img#thumbnail").attr("src", features_data[index].image).attr("height", "239");
			$("div#features img#thumbnail").attr("alt", features_data[index].description);
		
			//Set up Read Story Link
			var strLinkName = "";
			var $arrowImageButton = $("<img></img>").attr({"src":"/english/images/home/slide_btn-play.gif", "width":"7", "height":"7", "border":"0", "title":""});
			var linkTarget = (/^\/english\//.test(features_data[index].link) == true) ? "" : "_blank";
			
			
			if (features_data[index].type == "webfeature") {
				strLinkName = "Read Story ";
				$arrowImageButton.attr({"alt":strLinkName});
				$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
				$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
				//$("div#features span#read-link a").show();
			} else if (features_data[index].type == "photoalbum") {
				strLinkName = "Photo Album ";
				$arrowImageButton.attr({"alt":strLinkName});
				$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
				$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
				//$("div#features span#read-link a").show();
			} else if (features_data[index].type == "readmore") {
				strLinkName = "Read More ";
				$arrowImageButton.attr({"alt":strLinkName});
				$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
				$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
				//$("div#features span#read-link a").show();
            } else if (features_data[index].type == "videolink") {
				strLinkName = "Watch Video ";
				$arrowImageButton.attr({"alt":strLinkName});
				$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
				$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
				//$("div#features span#read-link a").show();
			} else {
				$("div#features span#read-link a").attr("href", "javascript:;").attr("target", linkTarget).html("&nbsp;&nbsp;&nbsp;").css({"cursor":"default"});
				$("div#features a#read-link2").attr("href", "javascript:;").attr("target", "").css({"cursor":"default"});
				//$("div#features span#read-link a").hide();
			}
			
			$("div#features span#features-caption").html(features_data[index].description)
		} else {
			$("div#features img#thumbnail").fadeTo("slow", 0, function() {
				$("div#features img#thumbnail").attr("src", features_data[index].image).attr("height", "239"); 
				$("div#features img#thumbnail").fadeTo("slow", 1);

				$("div#features img#thumbnail").attr("alt", features_data[index].description);
		
			//Set up Read Story Link
			var strLinkName = "";
			var $arrowImageButton = $("<img></img>").attr({"src":"/english/images/home/slide_btn-play.gif", "width":"7", "height":"7", "border":"0", "title":""});
			var linkTarget = (/^\/english\//.test(features_data[index].link) == true) ? "" : "_blank";
			
			
				if (features_data[index].type == "webfeature") {
					strLinkName = "Read Story ";
					$arrowImageButton.attr({"alt":strLinkName});
					$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
					$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
					//$("div#features span#read-link a").show();
				} else if (features_data[index].type == "photoalbum") {
					strLinkName = "Photo Album ";
					$arrowImageButton.attr({"alt":strLinkName});
					$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
					$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
					//$("div#features span#read-link a").show();
				} else if (features_data[index].type == "readmore") {
					strLinkName = "Read More ";
					$arrowImageButton.attr({"alt":strLinkName});
					$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
					//$("div#features span#read-link a").show();
				} else if (features_data[index].type == "videolink") {
					strLinkName = "Watch Video ";
					$arrowImageButton.attr({"alt":strLinkName});	
					$("div#features span#read-link a").attr("href", features_data[index].link).attr("target", linkTarget).html("").css({"cursor":"pointer"}).text(strLinkName).append($arrowImageButton);
					$("div#features a#read-link2").attr("href", features_data[index].link).attr("target", linkTarget).css({"cursor":"pointer"});
					//$("div#features span#read-link a").show();
				} else {
					$("div#features span#read-link a").attr("href", "javascript:;").html("&nbsp;&nbsp;&nbsp;").css({"cursor":"default"});
					$("div#features a#read-link2").attr("href", "javascript:;").attr("target", "").css({"cursor":"default"});
					//$("div#features span#read-link a").hide();
				}
				
				$("div#features span#features-caption").html(features_data[index].description);
			});
		}

	}
	
	

	$("img#features-prev-button, img#features-next-button, img#features-play-pause").css("cursor","pointer");
	$("img#features-prev-button").click( function(e) {
		e.stopPropagation();
		//If it is rotating
		if ($("img#features-play-pause").attr("src").indexOf("pause") >= 0) {
			//Reset the feature timer
			clearTimeout(featuresTimeoutId);
			//rotate to next feature after ten seconds
			featuresTimeoutId = setTimeout("FeaturesAutoRotate()", iFeatureRotateTime);
		}
		if (featureCurrentIndex == 0) {
			featureCurrentIndex = features_data.length-1;
		} else {
			featureCurrentIndex--;
		}
		setFeature(featureCurrentIndex);
	});
	
	$("img#features-next-button").click( function(e) {
		e.stopPropagation();
		//If it is rotating
		if ($("img#features-play-pause").attr("src").indexOf("pause") >= 0) {
			//Reset the feature timer
			clearTimeout(featuresTimeoutId);
			//rotate to next feature after ten seconds
			featuresTimeoutId = setTimeout("FeaturesAutoRotate()", iFeatureRotateTime);
		}
		if (featureCurrentIndex == features_data.length-1) {
			featureCurrentIndex = 0;
		} else {
			featureCurrentIndex++;
		}
		setFeature(featureCurrentIndex);
	});
	
	
	
	$("img#features-play-pause").click(function(e) {
		e.stopPropagation();
		var imgSrc = $(this).attr("src");
		if (imgSrc.indexOf("pause") >= 0) {
			clearTimeout(featuresTimeoutId);
			$(this).attr("src", imgSrc.replace("pause.gif", "play.gif")).attr("alt", "play");
		} else {
			featuresTimeoutId = setTimeout("FeaturesAutoRotate()", iFeatureRotateTime);
			$(this).attr("src", imgSrc.replace("play.gif", "pause.gif")).attr("alt", "pause");
		}
	})
	//Features - End
	
		//Web-within-web  - Start
	
	//Initialization
	/*var www_setting = {
		bRandom : true,
		iDefaultIndex : 0 // if bRandom is false, please set which feature is the default image when the main page is loaded.
	};
	
	
	var wwwCurrentindex = www_setting.bRandom ? Math.floor(Math.random()*$("#web-within-web .jCarouselLite ul li").length): www_setting.iDefaultIndex;
	alert("Length : " + $("#web-within-web .jCarouselLite ul li").length + " : " + wwwCurrentindex);
	$("#web-within-web .jCarouselLite ul li:lt("+ wwwCurrentindex +")").clone().appendTo("#web-within-web .jCarouselLite ul").end();
	$("#web-within-web .jCarouselLite ul li:lt("+ wwwCurrentindex +")").remove();
	alert("Length : " + $("#web-within-web .jCarouselLite ul li").length + " : " + wwwCurrentindex);
	*/
	//alert(www_setting.bRandom + " : " + wwwCurrentindex)

	//calling ajax to get the latest web-within-web
	$.get("http://www.iso.cuhk.edu.hk/cuhk-website-services/iso/web-within-web-ajax.aspx", {"lang":"english", "mode":"front"} , function(data) {
		if (data.status == "success") {
			for (i=0; i<data.structure.length; i++) {
				var $li = $("<li></li>");
				var $a = $("<a></a>").attr({"target":"_blank", "href":data.structure[i].link});
				var $img = $("<img/>").attr({"src":data.structure[i]["small_image"], "alt":data.structure[i].title, "width":30, "border":0});
				
				$img.appendTo($a);
				$a.appendTo($li);
				
				$li.appendTo($("#web-within-web .jCarouselLite ul"));
			}
		}

		$("#web-within-web .jCarouselLite ul li:first img").addClass("selected");
		
		$("#web-within-web img#www-selected-image").attr("alt", $("#web-within-web .jCarouselLite ul li:first img").attr("alt"))
			.attr("src", $("#web-within-web .jCarouselLite ul li:first img").attr("src").replace(/_s\.jpg$/,".jpg"))
			.parent().attr("href", $("#web-within-web .jCarouselLite ul li:first img").parent().attr("href"))
					.attr("target", $("#web-within-web .jCarouselLite ul li:first img").parent().attr("target"));
		
		$("#web-within-web h3#title >a").attr("href", $("#web-within-web .jCarouselLite ul li:first img").parent().attr("href"))
				.attr("target", $("#web-within-web .jCarouselLite ul li:first img").parent().attr("target"))
				.text($("#web-within-web .jCarouselLite ul li:first img").attr("alt"));
			
		
		$("div.jCarouselLite").jCarouselLite({
			btnNext: "a#www-right-button",
			btnPrev: "a#www-left-button",
			auto : 10000,
			speed: 600,
			visible: 3,
			eventHandler: "selected"
		});
		
		if ($("#web-within-web .jCarouselLite ul li:first").width() > 60) {
		
			$("#web-within-web .jCarouselLite ul li").css("width", "50px");
			$("#web-within-web .jCarouselLite ul").css("width", "650px");
			$("#web-within-web .jCarouselLite").css("width", "150px");
		}
		
		var imgsrc = "";
		$("#web-within-web .jCarouselLite img").hover(function() {
			$(this).trigger("selected");
		});
		
		$("#web-within-web .jCarouselLite img").bind("selected",function() {
			$("#web-within-web .jCarouselLite img.selected").removeClass("selected");
			$(this).addClass("selected");
			imgsrc = $(this).attr("src").replace(/_s\.jpg$/,".jpg");
			
			var objSelectedImage = $("#web-within-web img#www-selected-image");
			objSelectedImage.fadeTo("slow", 0, function() {objSelectedImage.attr("src", imgsrc); objSelectedImage.fadeTo("slow", 1);});
			objSelectedImage.attr("alt", $(this).attr("alt"));
			objSelectedImage.parent().attr("href", $(this).parent().attr("href"));
			objSelectedImage.parent().attr("target", "_blank");
			$("#web-within-web h3#title >a").attr("href", $(this).parent().attr("href"))
				.attr("target", $(this).parent().attr("target"))
				.text($(this).attr("alt"));
		})    
		
	}, "jsonp");
	
	//Web-within-web  - End
	
	//Shortcut
	var objShortcutFadeOutId;
	$("img#short-cut-button").click(
		function(event) {
			if ($("div#short-cut-pane-inner:visible").length >0) {
				$("div#short-cut-pane-inner").fadeOut("slow");
				$(this).attr("src", "/english/images/home/shortcut-in.gif");
			} else {
				$("div#short-cut-pane-inner").fadeIn("slow");
				$(this).attr("src", "/english/images/home/shortcut-out.gif");
			}
		}
	)
	//Short - End
	
	//RSS List
	var objRSSFadeOutId;
	$("img#rss-button").click(
		function(event) {
			if (objRSSFadeOutId != null) {
				clearTimeout(objRSSFadeOutId);
			} 

			if ($("div#rss-pane-inner:visible").length >0) {
				$("div#rss-pane-inner").fadeOut("slow");
				$(this).attr("src", "/english/images/home/btn-rss.jpg");
			} else {
				$("div#rss-pane-inner").fadeIn("slow");
				$(this).attr("src", "/english/images/home/btn-rss-out.jpg");
			}
		}
	)
	//RSS List - End
	
	//Announcement List
	//Initialization

	var announcement_data;
	var iSingleCycleWidth;

	function animate_scrolling() {
		var iWidth = iSingleCycleWidth;
		var iLeft = $("div#announcement-rolling").position().left;
		var iSpeed = 30; //scroll 30px per second		

		//$("div#announcement-rolling:animated").stop(true,false);
		$("div#announcement-rolling").animate({left:'-='+ (iWidth+iLeft)}, ((iWidth+iLeft)/iSpeed * 1000), 'linear', 
			function() {
				//alert($("div#announcement-rolling").index($(this)));
				$("div#announcement-rolling").css("left", "0px");
				animate_scrolling();
			});
	}
	
	function setAnnouncementList2() {
		
		var $selectedAnnouncement;
		
		for (i in announcement_data) {
		
			var objList;
			var $objMarqueeItem = $("<a></a>");

			//Marquee - Start
			var $separator = $("<img/>").attr("src", "/english/images/home/separator-off.gif").css("padding", "2px 3px").attr("border", "0").attr("align", "absmiddle").appendTo($("div#announcement-rolling"));
			
			var $objMarqueeCloneItem = $objMarqueeItem.clone().append($separator).append(announcement_data[i].name).attr("href", announcement_data[i].link).attr("target", "_blank").addClass("nav_menu").css({"white-space":"nowrap", "padding":"2px 0px"});
				
			$objMarqueeCloneItem.appendTo($("div#announcement-rolling"));
				
			//Marquee - End
			
		}
		
		var strHTML = $("div#announcement-rolling").html();
		
		iSingleCycleWidth = ($("div#announcement-rolling").width());
		
		//The following while-loop is to make sure the total length of "div#announcement-rolling" is longer than "div#annoucemnets-container"
		while ($("div#announcement-rolling").width() < $("div#announcement-container").width()) {
			$("div#announcement-rolling").html($("div#announcement-rolling").html() + strHTML);
		}
		//Add one more 
		$("div#announcement-rolling").html($("div#announcement-rolling").html() + strHTML);
		
		//Pause for 2 seconds and then start scrolling
		$("div#announcement-rolling").animate({opacity:1}, 2000, function() {animate_scrolling();});
		
		$("div#announcement-rolling > a").hover( function(e) { 
		
			$selectedAnnouncement = $(this);

			var iLayerWidth = $("div#announcement-pane").width();
			var iLayerHeight;	//Autoheight
			
			//Highlight the text color
			$(this).attr("class", "on");
			//Highlight the separator image
			$("img", this).attr("src", "/english/images/home/separator-on.gif");
			
			//Stop Any Animation
			$("div#announcement-rolling").stop(true,false);
			
			//Calculate the position of announcement detail pane
			var iMarqueeLeft = $("div#announcement-outer").position().left;
			var iMarqueeRight = $("div#inner-main").position().left + $("div#inner-main").width();
			var iMarqueeTop = $("div#announcement-container").position().top + 1;
			var iItemLeft = $(this).position().left;
			var iItemRight = $(this).position().left + $(this).width();
			var iMouseLeft = e.pageX;
			
			var iIndex = $("div#announcement-container  a").index($(this)) % announcement_data.length;
			
			//Clear all the html content of h3 and p elements.
			$("div#announcement-pane .body h3, div#announcement-pane .body p").html("");
			//Write Title of Announcement
			$("div#announcement-pane .body h3").css("height","").html($(this).clone().css("white-space",""));
			//Remove the separator image
			$("div#announcement-pane .body h3 a img").remove();
			
			//Image 
			var $announcement_image = "";
			if (announcement_data[iIndex].img != null && announcement_data[iIndex].img != "") {
				$announcement_image = $("<img />").attr("src",announcement_data[iIndex].img).attr("alt",announcement_data[iIndex].name).attr({align:"right", border:0}).css("height", "30px");
			}
			
			//Exception on JUPAS|Early Admissions Scheme - no title but image only
			if (announcement_data[iIndex].name.indexOf("JUPAS") >= 0 || announcement_data[iIndex].name.indexOf("Early Admissions Scheme") >= 0) {
				//Remove the text within the link
				$("div#announcement-pane .body h3").css("text-align","center");
				$("div#announcement-pane .body h3 a").text("");
				//Don't set the height of the image to 30 and align to center
				$announcement_image.attr("align", "middle").css("height", "");
			} else {
				$("div#announcement-pane .body h3").css("text-align","");
			}

			if (announcement_data[iIndex].description != "") {
				//Write Description of Announcement
				$("div#announcement-pane .body p").html("").append($announcement_image).append(announcement_data[iIndex].description);
			} else if ($announcement_image != "") {
				//If description is empty, put the image next to the title.
				$("div#announcement-pane .body h3 a").prepend($announcement_image);
				var iImageHeight = $announcement_image[0].height;
				if ($("div#announcement-pane .body h3").height() < iImageHeight) {$("div#announcement-pane .body h3").height(iImageHeight)}
			}
			
			iLayerHeight = $("div#announcement-pane").height();
			
			var iLayerTop = iMarqueeTop - iLayerHeight;
			//var iLayerLeft = Math.max((iMouseLeft - (iLayerWidth/2)), iMarqueeLeft, iItemLeft);
			var iLayerLeft = iMouseLeft < iMarqueeLeft ? iMarqueeLeft : iMouseLeft - 5;
			//iLayerLeft = Math.min(iLayerLeft, (iMarqueeRight - iLayerWidth));
			//$objAnnouncementLayer.css({left:iLayerLeft + "px", top:iLayerTop + "px"}).show('slow');
			$("div#announcement-pane").css({left:"0px", top:iLayerTop + "px"}).stop(true,false).show().animate({opacity:1}, 200);
		}, function(e) {
			$("div#announcement-pane").stop(true,false).animate({opacity:0}, 500, function() {$("div#announcement-pane").hide()});
			//Reset the text color
			$(this).attr("class", "off");
			//Reset the separator image
			$("img", this).attr("src", "/english/images/home/separator-off.gif");
			
			animate_scrolling();
		});

		$("div#announcement-pane").hover( 
			function() {
				//Highlight the text color
				$selectedAnnouncement.attr("class", "on");
				//Highlight the separator image
				$("img", $selectedAnnouncement).attr("src", "/english/images/home/separator-on.gif");

				$(this).stop(true, false).show().animate({opacity:1}, 500);
				$("div#announcement-rolling").stop(true,false);
			},
			function() {
				//Reset the text color
				$selectedAnnouncement.attr("class", "off");
				//Highlight the separator image
				$("img", $selectedAnnouncement).attr("src", "/english/images/home/separator-off.gif");
				
				$("div#announcement-pane").stop(true,false).animate({opacity:0}, 500, function() {$("div#announcement-pane").hide()});
				animate_scrolling();
			}
		);
		
	}
	
	//calling ajax to get the latest announcements
	$.get("http://mmlab.itsc.cuhk.edu.hk/iso/announcements/announcements-ajax.aspx", {} , function(data) {
		if (data.status == "success") {
			announcement_data = data.structure;
			setAnnouncementList2();
			$("div#announcement-pane tr:first td.frameContent").css("padding-top", "0px");
		}
		
	}, "jsonp");
	
	var objAnnouncementFadeOutId;
	$("img#announcement-button, div#announcement-close").click(
		function(event) {
			if (objAnnouncementFadeOutId != null) {
				clearTimeout(objAnnouncementFadeOutId);
			} 
			
			if ($("div#announcement-pane-inner:visible").length >0) {
				$("div#announcement-pane-inner").fadeOut("slow");
				$("img#announcement-button").attr("src", "/english/images/home/btn-annc.jpg");
			} else {
				$("div#announcement-pane-inner").fadeIn("slow", function() {
					$('div#announcement-pane .scroll-pane-content').jScrollPane({showArrows:true, dragMinHeight:40, dragMaxHeight:40 });
					//IE6 bug, "announcement-pane-inner" cannot be minimized at run time and thus hard-code the width
					if ($("div#announcement-pane-inner").width() > 300) {
						$("div#announcement-pane-inner").css("width", "292px");
						$("div#announcement-pane-inner").css("width", "");
					}
				});
				$("img#announcement-button").attr("src", "/english/images/home/btn-annc-out.jpg");
			}
		}
	)
	
	//Announcement List - End

	//Auto - create Announement pane if mode=announcements in the url
	var selectedmode = $.query.get("mode");
	
	if (selectedmode == "announcements") {
		$("img#announcement-button").click();
	}
	
	//News & Events
	$.get("http://www.iso.cuhk.edu.hk/cuhk-website-services/cpr/cpro-frontpage-press-release-ajax.aspx", {}, function(data) {
			
			$("div#cuhk-news-events").html("");
			
			if (data.status=="success") {
				for (i in data.structure) {
					var objCurrent = data.structure[i];
					var $a = $("<a/>").attr("href", objCurrent.link).attr("target", "_blank").html(objCurrent.title);
					var $p = $("<p/>");
					
					$a.appendTo($p);
					$p.appendTo("div#cuhk-news-events");
				}
				$('div#cuhk-news-events').jScrollPane({showArrows:true, dragMinHeight:40, dragMaxHeight:40});
			}
		}	
	, "jsonp");
	//News & Events - End
	
	//VC Speeches & Blog - Start
	
	var latestblog = {"title":"", "description":"", "url":"http://www.vco.cuhk.edu.hk/js_blog/?lang=en-GB"};
	var latestspeech = {"title":"", "description":"", "url":"/governance/officers/joseph-sung/english/speeches/speeches.html"};
	
	$.get("http://mmlab.itsc.cuhk.edu.hk/iso/vcblog/vcblog-rss-ajax.aspx", "", function(result) {
		if (result.status == "success") {
			latestblog = result.structure[0];
		}
	} , "jsonp");

	var $temp = $("<span></span>");
	
	$temp.load("/governance/officers/joseph-sung/english/speeches/includes/highlights.html a.navSpeech strong:first", function() {
		latestspeech.title = $temp.text();
	});
	
	$("div#vc-speech-blog > div#vc-speech a").attr({"href":latestspeech.url, "target":"_blank"});
	$("div#vc-speech-blog > div#vc-blog a").attr({"href":latestblog.url, "target":"_blank"});
	
	
	$("div#vc-speech-blog > div#vc-speech, div#vc-speech-blog > div#vc-blog").hover( function(e) { 
	
		//Check if content is loaded
		if (this.id == "vc-speech") {
			if (latestspeech.title == "") {
				return;
			}
		} else if (this.id == "vc-blog") {
			if (latestblog.title == "") {
				return;
			}
		}
	
		var iLayerWidth = $("div#vc-pane").width();
		var iLayerHeight;	//Autoheight
		
		//Highlight the text color
		//$(this).attr("class", "on");
		//Highlight the separator image
		//$("img", this).attr("src", "/english/images/home/separator-on.jpg");
		
		//Calculate the position of vc detail pane
		var iMarqueeLeft = $("div#vc-speech-blog").position().left;
		var iMarqueeRight = $("div#right-container").position().left + $("div#right-container").width();
		var iMarqueeTop = $("div#vc-speech-blog").position().top + 1;
		var iItemLeft = $(this).position().left;
		var iItemRight = $(this).position().left + $(this).width();
		//var iMouseLeft = e.pageX;
		
		//Fill in the content
		if (this.id == "vc-speech") {
			$("div#vc-pane .body h3 a").text(latestspeech.title).attr("href", latestspeech.url);
			if (latestspeech.description == "") {
				$("div#vc-pane .body p").hide();
			} else {
				$("div#vc-pane .body p").show().text(latestspeech.description);
			}
		} else if (this.id == "vc-blog") {
			$("div#vc-pane .body h3 a").text(latestblog.title).attr("href", latestblog.url);
			if (latestblog.description == "") {
				$("div#vc-pane .body p").hide();
			} else {
				$("div#vc-pane .body p").show().text(latestblog.description);
			}
		}

		iLayerHeight = $("div#vc-pane").height();
		
		var iLayerTop = iMarqueeTop - iLayerHeight;
		var iLayerLeft = iItemLeft;
		iLayerLeft = Math.min(iLayerLeft, (iMarqueeRight - iLayerWidth));
		$("div#vc-pane").css({left:iLayerLeft + "px", top:iLayerTop + "px"}).stop(true,false).show().animate({opacity:1}, 200);
	}, function(e) {
		$("div#vc-pane").stop(true,false).animate({opacity:0}, 500, function() {$("div#vc-pane").hide()});
		//Reset the text color
		$(this).attr("class", "off");
	});

		$("div#vc-pane").hover( 
			function() {
				$(this).stop(true, false).show().animate({opacity:1}, 500);
			},
			function() {
				$("div#vc-pane").stop(true,false).animate({opacity:0}, 500, function() {$("div#vc-pane").hide()});
			}
		);
	
	
	
	//VC Speeches & Blog - End
	
})

var featuresTimeoutId;
var iFeatureRotateTime = 10000; //10 seconds

function FeaturesAutoRotate() {
	$("img#features-next-button").click();
}

