var initPage = function() {
	/** web track index btn* */
	jQuery(".track-btn").click(trackBtn);
	var cursorLink = jQuery('#cursorLink').val();
	if (cursorLink !='')
	{
		jQuery('#' + cursorLink).removeClass('sidebarNav').addClass('sidebarNavCur');
	}
	initPageMenu();
};

jQuery(document).ready(initPage);

var initPageMenu = function() {
	// Preload other button-like images
	jQuery("#FtagContent .introSec").each(function(i) {
		jQuery(this).hide();
		var sectionId = jQuery(this).attr("id");
		jQuery("#" + sectionId + "Link").click(function() {
			var tabId = jQuery(this).attr("id").replace("Link", "Tab");
			jQuery(".FeaturesTag #" + tabId).trigger("click");
		});
	});
	jQuery(".FeaturesTag li").not(".Ftag5").click(function() {
		jQuery(this).children("h2").css({
			"background-position" : "left 0px"
		});
		var tabId = jQuery(this).attr("id");
		jQuery(".FeaturesTag li").not("#" + tabId).each(function() {
			jQuery(this).children("h2").css({
				"background-position" : "left -24px"
			});
		});
		var sectionId = jQuery(this).attr("id").replace("Tab", "");
		jQuery("#FtagContent .introSec").each(function(i) {
			jQuery(this).hide();
		});
		jQuery("#FtagContent #" + sectionId).show();
	});

	var tabIdIdx = jQuery("#overviewCurTab").val();
	if (tabIdIdx != null && tabIdIdx != "") {
		var tabId = tabIdIdx + "Tab";
		var tab = DWRUtil.byId(tabId);
		var pageURL = document.location.toString();
		if (tab != null) {
			jQuery(".FeaturesTag #" + tabId).trigger("click");
			if (pageURL.match("#")) { // the URL contains an anchor
				var anchorPoint = "#" + pageURL.split("#")[1];
				jQuery.scrollTo("#FtagContent a" + anchorPoint);
			}
		} else {
			jQuery(".FeaturesTag li:first").trigger("click");
		}
	} else {
		jQuery(".FeaturesTag li:first").trigger("click");
	}

	// swap img file
	jQuery('.swapNewsImg').click(function() {
		var smallNewsImg = jQuery(this).attr('src');
		jQuery('#bigNewsImg').attr('src', smallNewsImg);
	});

	jQuery('.swapPodcastImg').click(function() {
		var smallPodcastImg = jQuery(this).attr('src');
		jQuery('#bigPodcastImg').attr('src', smallPodcastImg);
	});
	var openDonwloader = function(dialog) {
		dialog.overlay.fadeIn('slow', function() {
			dialog.container.slideDown('slow', function() {
				dialog.data.fadeIn('slow');
			});
		});
	};

	var closeDonwloader = function(dialog) {
		dialog.data.fadeOut('slow', function() {
			dialog.container.slideUp('slow', function() {
				dialog.overlay.fadeOut('slow', function() {
					jQuery.modal.close();
				});
			});
		});
	};
	// pop download dialog
	jQuery('#syncDetail span').click(function() {
		jQuery("#mobileImg").modal({
			containerCss : {
				height : jQuery("#mobileImg").height(),
				width : jQuery("#mobileImg").width()
			},
			onOpen : openDonwloader,
			onClose : closeDonwloader
		});
	});
};
