// Globals
var znzSHReal = null;
var znzSZReal = null;
var znz300Real = null;
var znzIdx = null;
var znzLast = null;
var znzMystocks = null;
var znzHot = null;
var znzDS = null;
var znzSmryBaidu = null;
var znzSmryIndec = null;
var znzBlockIndec = null;
var znz6181 = null;
var znzAD1 = null;
var znzAD2 = null;
var znzAD3 = null;
var znzAD4 = null;
var znzAD5 = null;
var znzAD6 = null;
var znz4Top = null
var znzShBigTrade = null;
var znzSzBigTrade = null;

// rewrite znzMarketBigTradeStock's _set function
znzMarketBigTradeStock.prototype._set = function()
{   
    //alert([].constructor == Array);
    
    //alert(this.tradeItems.length < 1);
    var divBlk = $('stock-bigtrade');
    if(divBlk.style.display == "")
    {
        divBlk.style.display = "block";
        
    }
    
    var tableStr = '<table cellpadding=0 cellspacing=0>';
    for(i=this.tradeItems.length -1; i>= 0; i--)
    {
        var volColor = 'nocolor';
        var valColor = 'nocolor';
    
        if (this.tradeItems[i][1][3] == 'B')
            volColor = 'incolor';
        if (this.tradeItems[i][1][3] == 'S')
            volColor = 'decolor';
        if(i == 0)
            tableStr += '<tr><td align=\'left\' width=\'40px\'>' + this.tradeItems[i][1][0].substr(0, 2) + ":" + this.tradeItems[i][1][0].substr(2, 2) + '</td>';
        else
            tableStr += '<tr class=\'hasbtm\'><td align=\'left\' width=\'40px\'>' + this.tradeItems[i][1][0].substr(0, 2) + ":" + this.tradeItems[i][1][0].substr(2, 2) + '</td>';    
        tableStr += '<td align=\'left\' ><a href="./realstock.php?code=' + this.stockType.toLowerCase() + this.tradeItems[i][0] +'">' + decodeURIComponent(this.tradeItems[i][2]) + '</a></td>'
        tableStr += '<td align=\'right\'  class=\'' + volColor + '\'>' + this.tradeItems[i][1][2] + '</td>';
        tableStr += '</tr>';    
    }
    
    tableStr +='</table>';
    innerSet($(this.divID + '-table'), tableStr, null);
}


function start()
{

    znzMystocks =  new  znzMyStock('stock-mystock-table-content', 10 * 1000, 'znzMystocks');    
    
    var onloadtime = new Date().getTime();
    
    var sugReal = new suggestQuery('realstock-query-query', 'realstock-query-select', 'realstock-query-code', 'realstock-query-form', null, null, null, true);
    
    var titleMargin = [20, 90, 155, 215, 270, 345];
    znzSHReal = new znzRealStock('znzRealIndex', 'stock-idx-swf', '000001',
        '上证指数', 'SH', onDataChange, 10 * 1000, realstock_data, 480, 238, titleMargin);
    
    znzIdx = new znzIdxSummary('stock-index-all', 10 * 1000, idxsumry_data);
    znzLast = new znzLastVisit('stock-lastv-table', 10 * 1000, false, null, null, null, 6);    
    znzSmryIndec = new znzIndec('stock-news-indec-table', 20 * 1000, 'summary', false, idxindec_data);
    znzBlockIndec = new znzIdxBlock('stock-news-block399-table', 'stock-news-block300-table', 20 * 1000);
    znzDS = new znzDDZSort('stock-ddzsort-table', 60 * 1000, 'stock-ddzsort-order', ddzsort_data);            
    var keys = {
                'inc_sh_a_top':'sh_ratio_inc:涨跌幅',       'inc_sz_a_top':'sz_ratio_inc:涨跌幅', 
                'inc_sh_a_last':'sh_ratio_dec:涨跌幅',      'inc_sz_a_last':'sz_ratio_dec:涨跌幅',
                'amount_sh_a_top':'sh_amount:成交额',    'amount_sz_a_top':'sz_amount:成交额',
                'vr_sh_a_top':'sh_liangbi:量比',        'vr_sz_a_top':'sz_liangbi:量比'
               };

    znz6181 = new znzIdxSort(keys, 5, 30 * 1000, stock6181_data);
    //big trade sh market
    znzShBigTrade = new znzMarketBigTradeStock("stock-shbigtrade", 20 * 1000, "SH");
    
    //special
    eventInit();
    var inittime = new Date().getTime();
}

function eventInit()
{
    if($('stock-lastv-name'))
    {
        $('stock-lastv-name').onclick = function()
        {
            this.className = 'title-current';
            $('stock-mystock').className = "title-uncurr";
            
            $('stock-lastv-table').style.display = "block";
            $('stock-mystock-table').style.display = "none";
        }
    }
    
    if($('stock-mystock'))
    {
        $('stock-mystock').onclick = function()
        {
            this.className = 'title-current';
            $('stock-lastv-name').className = "title-uncurr";
            
            $('stock-lastv-table').style.display = "none";
            $('stock-mystock-table').style.display = "block";
        }
    }
    
    if($('stock-shbigtrade-name'))
    {
        $('stock-shbigtrade-name').onclick = function()
        {
            $('stock-szbigtrade-name').className = "title-uncurr";
            this.className = 'title-current';
            if(!znzShBigTrade.running)
                znzShBigTrade.restart();
            if(znzSzBigTrade)
            {
                znzSzBigTrade.stop();
            }
            $('stock-shbigtrade-table').style.display = "block";
            $('stock-szbigtrade-table').style.display = "none";            
        }
        
        $('stock-szbigtrade-name').onclick = function()
        {
            $('stock-shbigtrade-name').className = "title-uncurr";
            this.className = "title-current";
            if(!znzSzBigTrade)
            {
                znzSzBigTrade = new znzMarketBigTradeStock("stock-szbigtrade", 20 * 1000, "SZ");
            }
            else if(!znzSzBigTrade.running)
                znzSzBigTrade.restart();
            if(znzShBigTrade)
            {
                znzShBigTrade.stop();
            }
            $('stock-shbigtrade-table').style.display = "none";        
            $('stock-szbigtrade-table').style.display = "block"; 
        }
    }
    
    $('stock-idx-sh').onclick = function(){

        znzSHReal.restart('000001', '上证指数', 'SH');        
        $('stock-idx-sh').className = 'title-current';
        $('stock-idx-sz').className = 'title-uncurr';
        $('stock-idx-300').className = 'title-uncurr';
    }
    
    $('stock-idx-sz').onclick = function(){
        
        znzSHReal.restart('399001', '深证成指', 'SZ');        
        $('stock-idx-sh').className = 'title-uncurr';
        $('stock-idx-sz').className = 'title-current';
        $('stock-idx-300').className = 'title-uncurr';
    }
    
    $('stock-idx-300').onclick = function(){
        
        znzSHReal.restart('000300', '沪深300', 'SH');        
        
        $('stock-idx-sh').className = 'title-uncurr';
        $('stock-idx-sz').className = 'title-uncurr';
        $('stock-idx-300').className = 'title-current';
    }
    
    
    $('stock-news-block399').onclick = function(){       

        znzBlockIndec.start();
        // change content
        $('stock-news-block300-table').className = 'hide';       
        $('stock-news-block399-table').className = '';  
        $('stock-news-indec-table').className = 'hide';
        $('stock-foreign-index-table').className = 'hide';
        
        // change tab
        $('stock-news-block300').className = 'title-uncurr';
        $('stock-news-block399').className = 'title-current';
        $('stock-news-indec').className = 'title-uncurr';
        $('stock-foreign-index').className = 'title-uncurr';  
    }
    
    $('stock-foreign-index').onclick = function(){
        // change content
        $('stock-news-block300-table').className = 'hide';       
        $('stock-foreign-index-table').className = '';  
        $('stock-news-indec-table').className = 'hide';
        $('stock-news-block399-table').className = 'hide';
        
        // change tab
        $('stock-news-block300').className = 'title-uncurr';
        this.className = 'title-current';
        $('stock-news-indec').className = 'title-uncurr';
        $('stock-news-block399').className = 'title-uncurr';
          
    }
    
    $('stock-news-indec').onclick = function(){
        // change content
        $('stock-news-indec-table').className = '';
        $('stock-news-block300-table').className = 'hide';
        $('stock-news-block399-table').className = 'hide';
        $('stock-foreign-index-table').className = 'hide';
        
        // change tab
        $('stock-news-indec').className = 'title-current';
        $('stock-news-block300').className = 'title-uncurr';
        $('stock-news-block399').className = 'title-uncurr';
        $('stock-foreign-index').className = 'title-uncurr';
    }  
    
    $('stock-news-block300').onclick = function(){
        znzBlockIndec.start();
        
        // change content
        $('stock-news-block300-table').className = '';
        $('stock-news-block399-table').className = 'hide';
        $('stock-news-indec-table').className = 'hide';
        $('stock-foreign-index-table').className = 'hide';
        
        // change tab
        $('stock-news-block300').className = 'title-current';
        $('stock-news-block399').className = 'title-uncurr';
        $('stock-news-indec').className = 'title-uncurr';
        $('stock-foreign-index').className = 'title-uncurr'; 
    }   
    
    // 研究报告 start
    $('stock-guide-macro-name').onclick = function(){        
      
        // change tab
        clearResRepTab()
        this.className = 'title-current';
        // change content
        $('stock-guide-macro-content').style.display = 'block';
        
        // set iframe src
        if(!$('stock-guide-macro-iframe').src)
            $('stock-guide-macro-iframe').src = $('stock-guide-macro-iframe').getAttribute('frmsrc');
        
    }  
    
   $('stock-guide-industry-name').onclick = function(){        
      
        // change tab
        clearResRepTab()
        this.className = 'title-current';

        // change content
        $('stock-guide-industry-content').style.display = 'block';        
        // set iframe src
        if(!$('stock-guide-industry-iframe').src)
            $('stock-guide-industry-iframe').src = $('stock-guide-industry-iframe').getAttribute('frmsrc');
        
    }  
    
   $('stock-guide-invest-name').onclick = function(){        
      
        // change tab
        clearResRepTab()
        this.className = 'title-current';

        // change content
        $('stock-guide-invest-content').style.display = 'block';
        
        // set iframe src
        if(!$('stock-guide-invest-iframe').src)
            $('stock-guide-invest-iframe').src = $('stock-guide-invest-iframe').getAttribute('frmsrc');     
    }  
    
   $('stock-guide-morning-name').onclick = function(){        
      
        clearResRepTab()
        // change tab
        this.className = 'title-current';
        // change content        
        $('stock-guide-morning-content').style.display = 'block';
        
        // set iframe src
        if(!$('stock-guide-morning-iframe').src)
            $('stock-guide-morning-iframe').src = $('stock-guide-morning-iframe').getAttribute('frmsrc');
   }  
    
  $('stock-guide-company-name').onclick = function(){        
      
        // change tab
        clearResRepTab()
        this.className = 'title-current';
        // change content
        $('stock-guide-company-content').style.display = 'block';
        
        // set iframe src
        if(!$('stock-guide-company-iframe').src)
            $('stock-guide-company-iframe').src = $('stock-guide-company-iframe').getAttribute('frmsrc');        
   }
    
   $('stock-guide-company-research-name').onclick = function(){        
      
        // change tab
        clearResRepTab()
        this.className = 'title-current';
        // change content
        $('stock-guide-company-research-content').style.display = 'block';
        
        // set iframe src
        if(!$('stock-guide-company-research-iframe').src)
            $('stock-guide-company-research-iframe').src = $('stock-guide-company-research-iframe').getAttribute('frmsrc');        
    } 
   // 交易提示
   $('stock-notice-trade-name').onclick = function(){        
      
        // change tab
        $('stock-notice-trade-name').className = 'title-current';
        $('stock-notice-suspension-name').className = 'title-uncurr';
        $('stock-notice-globalshare-name').className = 'title-uncurr';
        $('stock-notice-newstock-name').className = 'title-uncurr';
        
        // change content
        $('stock-notice-trade-content').style.display = 'block';
        $('stock-notice-suspension-content').style.display = 'none';
        $('stock-notice-globalshare-content').style.display = 'none';
        $('stock-notice-newstock-content').style.display = 'none';
        // set iframe src
        if(!$('stock-notice-trade-iframe').src)
            $('stock-notice-trade-iframe').src = $('stock-notice-trade-iframe').getAttribute('frmsrc');
        
    }  
    
   $('stock-notice-suspension-name').onclick = function(){        
      
        // change tab
        $('stock-notice-trade-name').className = 'title-uncurr';
        $('stock-notice-suspension-name').className = 'title-current';
        $('stock-notice-globalshare-name').className = 'title-uncurr';
        $('stock-notice-newstock-name').className = 'title-uncurr';
        
        // change content
        $('stock-notice-trade-content').style.display = 'none';
        $('stock-notice-suspension-content').style.display = 'block';
        $('stock-notice-globalshare-content').style.display = 'none';
        $('stock-notice-newstock-content').style.display = 'none';
        
        // set iframe src
        if(!$('stock-notice-suspension-iframe').src)
            $('stock-notice-suspension-iframe').src = $('stock-notice-suspension-iframe').getAttribute('frmsrc');
        
    }  
    
   $('stock-notice-globalshare-name').onclick = function(){        
      
        // change tab
        $('stock-notice-trade-name').className = 'title-uncurr';
        $('stock-notice-suspension-name').className = 'title-uncurr';
        $('stock-notice-globalshare-name').className = 'title-current';
        $('stock-notice-newstock-name').className = 'title-uncurr';
        
        // change content
        $('stock-notice-trade-content').style.display = 'none';
        $('stock-notice-suspension-content').style.display = 'none';
        $('stock-notice-globalshare-content').style.display = 'block';
        $('stock-notice-newstock-content').style.display = 'none';
        
        // set iframe src
        if(!$('stock-notice-globalshare-iframe').src)
            $('stock-notice-globalshare-iframe').src = $('stock-notice-globalshare-iframe').getAttribute('frmsrc');        
    }
    
    $('stock-notice-newstock-name').onclick = function(){        
      
        // change tab
        $('stock-notice-trade-name').className = 'title-uncurr';
        $('stock-notice-suspension-name').className = 'title-uncurr';
        $('stock-notice-globalshare-name').className = 'title-uncurr';
        $('stock-notice-newstock-name').className = 'title-current';
        
        // change content
        $('stock-notice-trade-content').style.display = 'none';
        $('stock-notice-suspension-content').style.display = 'none';
        $('stock-notice-globalshare-content').style.display = 'none';
        $('stock-notice-newstock-content').style.display = 'block';
        // set iframe src
        if(!$('stock-notice-newstock-iframe').src)
            $('stock-notice-newstock-iframe').src = $('stock-notice-newstock-iframe').getAttribute('frmsrc');        
    }  

}

function clearResRepTab()
{
    // change tab
    $('stock-guide-macro-name').className = 'title-uncurr';
    $('stock-guide-industry-name').className = 'title-uncurr';
    $('stock-guide-invest-name').className = 'title-uncurr';
    $('stock-guide-morning-name').className = 'title-uncurr';
    $('stock-guide-company-name').className = 'title-uncurr';
    $('stock-guide-company-research-name').className = 'title-uncurr';
    
    // change content
    $('stock-guide-macro-content').style.display = 'none';
    $('stock-guide-industry-content').style.display = 'none';
    $('stock-guide-invest-content').style.display = 'none';
    $('stock-guide-morning-content').style.display = 'none';
    $('stock-guide-company-content').style.display = 'none';
    $('stock-guide-company-research-content').style.display = 'none';
}
function onDataChange(dataStr)
{
    //alert(dataStr);
}

window.onload = start;