$(document).ready(function(e) {
	tabbing();
	showtime();
	changeLicense(0);
	
	formFunction();
});

function tabbing()	{
	$('.tabbing').each(function(index, element) {
		$(this).children('li').each(function(i,e) {
			if(i==0)	{
				makeTabOn($(this));
			}
			
			$(this).mouseover(function(e) {
				makeTabOn($(this));
			});
		});
		
		if($(this).hasClass('autoplay'))	{
			var t = $(this);
			int = setInterval( function() { gotoNextItem(t); }, 10000 );
		}
		
	});
	
	function gotoNextItem(e)	{
		var i = $(e).children('li.on').index();
		i = (i+1)%($(e).children('li').length);
		var nextItem = $(e).children('li').eq(i);
		makeTabOn($(nextItem));
	}
	
	function makeTabOn(e)	{
		$(e).parent('ul').children('li').removeClass('on');
		$(e).addClass('on');
		var x = $(e).attr('rel');
		var tar = $(e).parent('ul').attr('rel');
		
		$('#'+tar).children('div').hide();
		$('#'+x).show();
	}
}

var delta = 0 ;//= (new Date()).getTime() - 1301554066092;// how much is client faster than server
function showtime() {
	var today = new Date((new Date()).getTime() - delta);
	
	var hour = today.getHours();
	var minute = today.getMinutes();
	var second = today.getSeconds();
	if (hour <= 9)
		hour = "0" + hour;
	if (minute <= 9)
		minute = "0" + minute;
	if (second <= 9)
		second = "0" + second;
		      
	var utc = today.getTime() + (today.getTimezoneOffset() * 60000);
	var ldDate = new Date(utc + (3600000 * (1)));
	var nyDate = new Date(utc + (3600000 * (-4)));
	var tyDate = new Date(utc + (3600000 * (9)));
	var sxDate = new Date(utc + (3600000 * (2)));
	
	var ldhour = ldDate.getHours() < 9 ? ("0" + ldDate.getHours()) : ldDate.getHours();
	var nyhour = nyDate.getHours() < 9 ? ("0" + nyDate.getHours()) : nyDate.getHours();
	var tyhour = tyDate.getHours() < 9 ? ("0" + tyDate.getHours()) : tyDate.getHours();
	var sxhour = sxDate.getHours() < 9 ? ("0" + sxDate.getHours()) : sxDate.getHours();
	
	var strldtime = ldhour + ":" + minute + ":" + second + "&nbsp;";
	var strnytime = nyhour + ":" + minute + ":" + second + "&nbsp;";
	var strtytime = tyhour + ":" + minute + ":" + second + "&nbsp;";
	var strhktime = hour + ":" + minute + ":" + second + "&nbsp;";
	var strsxtime = sxhour + ":" + minute + ":" + second;
	
	$('#ldtime').html(strldtime);
	$('#nytime').html(strnytime);
	$('#tytime').html(strtytime);
	$('#hktime').html(strhktime);
	$('#sxtime').html(strsxtime);
	/*
	document.getElementById('ldtime').innerHTML = strldtime; // 显示时间
	document.getElementById('nytime').innerHTML = strnytime; // 显示时间
	document.getElementById('tytime').innerHTML = strtytime; //显示时间
 
	document.getElementById('hktime').innerHTML = strhktime; //显示时间
	document.getElementById('sxtime').innerHTML = strsxtime;  //显示时间
	*/
	//document.getElementById('dbtime').innerHTML = strdbtime; //显示时间
	setTimeout("showtime();", 500); 
}


function changeLicense(i)	{
	//<span id="licenseUL"><a href="http://www.sfc.hk/sfcprd/eng/pr/html/search_result_name.jsp?charset=MS950" target="_blank"><img src="img/tw/fsa.gif"></a></span></div>
	
	//var licenseList
	
	var obj = licenseList[i];
	$('#licenseUL').attr('class', '');
	$('#licenseUL').addClass(obj[0]);
	$('#licenseUL').attr('src', obj[1]);
	
	//('<a href="'+obj[1]+'" target="_blank"><img src="'+obj[0]+'" /></a>');
	
	i = (i+1)%licenseList.length;
	setTimeout("changeLicense("+i+");", 5000); 
}



function formFunction()	{
	$('.textreset').focus(function() {
		var val = $(this).attr('rel');
		if($(this).val()==val)	{
			$(this).val('');
		}
	})
	$('.textreset').blur(function() {
		var val = $(this).attr('rel');
		if($(this).val()=="")	{
			$(this).val(val);
		}
	})
	$('.textreset').each(function(index, element) {
		var val = $(this).attr('rel');
		$(this).val(val);
		
	});
}

function openPopup(url, winName, mode){
	var size = "width=636,height=408";//eg. 交易操作
	if(mode=="1"){
		size = "width=636,height=356";//eg. 開戶流程
	}else if(mode=="online_cs"){
		size = "width=600,height=565";//online customer service
	}
	window.open(url, winName, size);
}

