
// set form action
if(typeof(realDomain) && realDomain)
    $('realstock-query-form').action = 'http://' + realDomain + '/stock/realstock.php';

// initialize query suggestion
queryInit();

// initialize indexes summary
var _set_tmp = znzIdxSummary.prototype._set;

var modIndex = new znzIdxSummary('stock-index-all', 30 * 1000, null, realDomain, '_blank');

modIndex._set = function(dataStr){
    var retObj = KISSY.JSON.parse(dataStr);//.parseJSON();
               
    var div = '<table><tr>';
    
    var color = 'nocolor';
    var arrow = '';
    
    if (retObj['sh000001'][2] > retObj['sh000001'][1])
    {
        color = 'incolor';
        arrow = '↑';
    }
    if (retObj['sh000001'][2] < retObj['sh000001'][1])
    {
     	   color = 'decolor';
     	   arrow = '↓';
    }
    
    var urlPrefix = '';
    
    if (this.realDomain)
    {
        urlPrefix = 'http://' + this.realDomain + '/stock/';
    }
        
    div += '<td><a href=\'' + urlPrefix + 'realstock.php?code=sh000001\' target=\'' + this.targetType + '\'>上证指数</a></td><td class=\''+ color + '\'>' + retObj['sh000001'][2].toFixed(2) 
         + '</td><td class=\''+ color + '\'>' + arrow + (retObj['sh000001'][2]-retObj['sh000001'][1]).toFixed(2)
         + '</td><td class=\''+ color + '\'>' + ((retObj['sh000001'][2]-retObj['sh000001'][1])*100/retObj['sh000001'][1]).toFixed(2) + '%'
         + '</td><td>' +  (retObj['sh000001'][3]/10000).toFixed(2) + '亿元</td>';
    
    color = 'nocolor';
    arrow = '';     
    if (retObj['sz399001'][2] > retObj['sz399001'][1])
    {
        color = 'incolor';
    		arrow = '↑';
    }
    if (retObj['sz399001'][2] < retObj['sz399001'][1])
    {
        color = 'decolor';
        arrow = '↓';
    }
                   
    div += '</tr><tr><td><a href=\'' + urlPrefix + 'realstock.php?code=sz399001\' target=\'' + this.targetType + '\'>深证成指</a></td><td class=\''+ color + '\'>' + retObj['sz399001'][2].toFixed(2) 
        + '</td><td class=\''+ color + '\'>' + arrow + (retObj['sz399001'][2]-retObj['sz399001'][1]).toFixed(2) 
        + '</td><td class=\''+ color + '\'>' + ((retObj['sz399001'][2]-retObj['sz399001'][1])*100/retObj['sz399001'][1]).toFixed(2) + '%'
        + '</td><td>' +  (retObj['sz399001'][3]/10000).toFixed(2) + '亿元</td>';
    
    color = 'nocolor';  
    arrow = '';         
    if (retObj['sh000300'][2] > retObj['sh000300'][1])
    {
        color = 'incolor';
    		arrow = '↑';
    }
    if (retObj['sh000300'][2] < retObj['sh000300'][1])
    {
        color = 'decolor';
        arrow = '↓';
     }
         
    div += '</tr><tr><td><a href=\'' + urlPrefix + 'realstock.php?code=sh000300\' target=\'' + this.targetType + '\'>沪深300</a></td><td class=\''+ color + '\'>' + retObj['sh000300'][2].toFixed(2)
        + '</td><td class=\''+ color + '\'>' + arrow + (retObj['sh000300'][2]-retObj['sh000300'][1]).toFixed(2)
        + '</td><td class=\''+ color + '\'>' + ((retObj['sh000300'][2]-retObj['sh000300'][1])*100/retObj['sh000300'][1]).toFixed(2) + '%'
        + '</td><td>' +  (retObj['sh000300'][3]/10000).toFixed(2) + '亿元</td>';
        
    div += '</tr></table>';
    
    innerSet(document.getElementById(this.divID), div, null);
}

var mb_codes = ["000001", "399001", "000300"];
var mb_names = ["上证指数", "深证成指", "沪深300"];
var mb_shorts = ["sh", "sz", "sh"];
var mb_swfs = ["Real", "Real", "Real"];

function znzRealStockMod(swfID)
{
    this.swfID = swfID;
    this.running = false;
}

znzRealStockMod.prototype._realURLGet = function()
{
    return rdmDataDomainNameGet();
}

znzRealStockMod.prototype.resetmod = function(stockCode, stockName, stockType){
    this.stockCode = stockCode || '000001';
    this.stockName = stockName || '上证指数';
    this.stockType = stockType || 'SH';
    this._start();
}

znzRealStockMod.prototype._start = function()
{
    var realSwf = document.getElementById(this.swfID);
    if(!realSwf)
        realSwf = document[this.swfID];
    
    try{
        var infoURL = this._realURLGet(); 
  
        realSwf.start(infoURL, this.stockCode, this.stockType, this.stockName,
         ["real"], [], 398, 170, 2, [35, 16, 35, 18],[10,10,10, 12],[30, 105, 180, 270, -1, 340],
         true, 'http://' + realDomain + '/stock/' + 'realstock.php?code='+ this.stockType+this.stockCode);
  
        this.running = true;               
    }catch(E)
    {
        this.running = false;
        window.setTimeout(this._start.bind(this), 100);
    }        
}

var znzReal = null;
znzReal = new znzRealStockMod('znzRealMod');

var mb_changeto = function (cid){
  for (var i = 0; i < 3; i ++){
    if (cid == i){
      $('mb-li'+i).className = "modblock-current";
      if (znzReal&&znzReal._start){
        znzReal.resetmod(mb_codes[i], mb_names[i], mb_shorts[i]);
      }
    }else{
      $('mb-li'+i).className = "modblock-normal";
    }
  }
}

setTimeout(function(){mb_changeto(0)}, 100);



