
var loc = document.location.href;
if ( loc.lastIndexOf("/tc/") != -1 ){
	currlang = 'big5';
} else {
	currlang = 'gb2312';
}

$(document).ready(function(){	
	loadRate();
	animatedNews();
	

	$('.scrollbox').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 3000,
		type: 'sequence',
		containerheight: '90px'
	});

	//Key visual function: Gold Trading
	loadPrice();
});

var refreshCount = 1;
function loadPrice(){
	var params = {};	
	params["type"] = "price";
	if (refreshCount%2 == 0) {
		$('#header').text('黄金报价');
		params["pair"] = "xauusd";
		$('#silverBg').fadeOut("slow"); 

	} else {
		$('#header').text('白银报价');
		params["pair"] = "xagusd";
		$('#silverBg').fadeIn("slow"); 		
	}
	$.ajax({
		url: '/js/post.php', cache: false, dataType: 'json', type: 'GET', data: params,
		success: function(data) {
			$('#bid').text(data.bid);
			$('#ask').text(data.ask);
			$('#high').text(data.high);
			$('#low').text(data.low);
		}
	});
	refreshCount++;
	setTimeout(loadPrice, 5000);		
}
					//Key visual function: Gold Trading END	
					
			
					function loadRate(){
						$.ajax({
							url: '/js/price.php', cache: true, dataType: 'json', type: 'GET', data: "lang="+currlang,
							success: function(data) {
								var header = "Name | Sell | Buy | High | Low <br>";
								var pricelist = "<ul>";
								var k = ' class="alt"';	
								$.each(data, function(i, item) {
									if (k == ' class="alt"') { k = ''; }  else { k = ' class="alt"'; }
									pricelist += '<li'+ k + '><span class="pair">' + data[i]["name"] + '</span> <span class="sell">' + data[i]["bid"] + '</span> <span class="buy">' + data[i]["ask"] + '</span></li>';datetime = data[i]["datetime"];
								});
								pricelist += '</ul>';
								$("div#rate").html(pricelist);
								$("div.datetime").html(datetime);
								clearInterval(window['price']); 
								animatedPrice();
							}
						});
						
						setTimeout(loadRate, 60000);
					}
					function animatedPrice() {
						$('#rate').vTicker({
							speed: 500,
							pause: 3000,
							showItems: 9,
							animation: 'fade',
							mousePause: false,
							height: 0,
							direction: 'up',
							intervalName: 'price'
						});
					}
					
					function animatedNews() {
						$('#bottomNews').vTicker({
							speed: 500,
							pause: 3000,
							showItems: 1,
							animation: 'fade',
							mousePause: true,
							height: 0,
							direction: 'up',
							intervalName: 'news'
						});
					}	
