function centerElement(element,width,height){
	element.css({
		"z-index": "9999",
		"width": width+"px",
		"height": height+"px",
		"position": "absolute",
		"left": "50%",
		"top":"50%",
		"margin-left":(-(width/2)-15)+"px",
		"margin-top":(-(height/2)-15)+"px"
	});
}
function styledFloatBanner(width,height) {
	$('#bannerFloat .border-right').css({
		"height": height+15+"px"
	});
	$('#bannerFloat .border-bottom').css({
		"width": width+15+"px"
	});
}
function closeFloatBanner() {
	$('#bannerFloat').fadeOut(250,function(){
			$('#bannerFloat').remove();
		});
	return false;
}
function styledTopBanner(){
	$('#bannerTop > a').append("<div></div>");
	$('#bannerTop > a > div').css({
		"font-size":"16px",
		"font-weight":"bold",
		"background":"url("+$('#bannerTop > a > img').attr("src")+") center top no-repeat"
	});
	$('#bannerTop > a > img').remove();
}
$(window).load(function() {
	// jQuery Plug-in Slide: Easy Slider
	$('div#highlightBillboard .slide').easySlider({
		continuous: true,
		auto: true,
		pause: 5000,
		speed: 500,
		numeric: true,
		numericId: "highlightBillboardSlideController"
	});
	// jQuery Plug-in Slide: jCarouselLite
	$('div#highlightContentSlide').jCarouselLite({
		btnNext: ".slide-right",
		btnPrev: ".slide-left",
		visible: 4,
		easing: "easeInOut",
		scroll: 4,
		speed: 500
	});
	
	// Top Banner
	styledTopBanner();
	// Float Banner
	// Manipulate DOM to make sure that banner float will top-most element of page
	if ( $('#bannerFloat').html() != null) {
		var tempBannerFloatHTML = $('#bannerFloat').html();
		$('#bannerFloat').remove();
		tempBannerFloatHTML = "<div id=\"bannerFloat\">"+tempBannerFloatHTML+"</div>";
		$('body').append(tempBannerFloatHTML);
		tempBannerFloatHTML = null;
	}
	var elementWidth = $('#bannerFloat > a > img').width();
	var elementHeight = $('#bannerFloat > a > img').height();
	centerElement($('#bannerFloat'),elementWidth,elementHeight);
	styledFloatBanner(elementWidth,elementHeight);
	// Hide until load page, display after 1.5 sec.
	if (navigator.appName == "Microsoft Internet Explorer") {
		$(window).scroll(function(){
			var marginTop = $(window).height()/2;
			var posTop = $(document).scrollTop()+marginTop+"px";
			$('#bannerFloat').stop(true,true).animate({top:posTop},400);  
		});
	} else {
		$('#bannerFloat').hide().delay(1500).fadeTo(250,1,function(){
			$(window).scroll(function(){
				var marginTop = $(window).height()/2;
				var posTop = $(document).scrollTop()+marginTop+"px";
				$('#bannerFloat').stop(true,true).animate({top:posTop},400);  
			}); 
		});
	}
	$('#bannerFloat .close').click(function() {
		closeFloatBanner();
	});
	$('#bannerFloat').draggable();
	/* Interest Rate */
	$('#interestRate > li > div').hide();
	$('#interestRate > li:eq(0)').addClass("active").children('div').show();
	$('#interestRate > li > h3 > a').click(function(){
		if ($(this).parents("li").hasClass("active") == false) {
			$('#interestRate > li').removeClass("active");
			$(this).parents("li").addClass("active");
			$('#interestRate > li > div').slideUp(250);
			$(this).parent().next("div").slideDown(250);
		}
	});
	
	/* Hide all tab and then show 1st tab */
	$('#indexNewsActivitiesContent > li').hide();
	$('#indexNewsActivitiesTab > li:eq(0)').addClass("active");
	$('#indexNewsActivitiesContent > li:eq(0)').show();
	$('#indexNewsActivitiesTab > li > a').click(function() {
		if ($(this).parents("li").hasClass("active") == false) {
			$('#indexNewsActivitiesTab > li').removeClass("active");
			$(this).parent().addClass("active");
			$('#indexNewsActivitiesContent > li').hide();
			$('#indexNewsActivitiesContent > li > div.'+$(this).attr("class")).parent().fadeIn(250);
		}
		return false;
	});
});
$(document).ready(function(){
	$('a[href="#"]').click(function(){
		return false;
	});
});
$(document).keyup(function(e) {
	if (e.keyCode == 27) {
		closeFloatBanner();
	}
});
