/*
 * Thread 生成部分です。最初に実行されます。
 * XML ファイル / インターバルはここで設定します。
 */

// namespace object
var top = new Object();

var XML_DIR = '/common/xml/';

// Thread 生成処理 部分 - "OnLoadイベント" にフック
top.FEP = Class.create(
{
    initialize: function() {
//        document.observe("contentloaded", function() {
        document.observe("dom:loaded", function() {
            /*
             * OnLoad で表示
             * top.FEP.controlObj.doControl('HTMLのid', 'データXML', 描写用の関数, インターバル(秒));
             * インターバル：
             *       0 以下のときは、onLoad 時に一度だけ XML を読み込む
             *       1 以上のときは、onLoad 時 + インターバル(+ジッタ)秒毎に XML を読み込む。
             */
            LOCATION = window.location.pathname ;
            var category = "";
            
            if (LOCATION.match(/drama/) != null )        category = "drama";
            if (LOCATION.match(/news/) != null )         category = "news";
            if (LOCATION.match(/sports/) != null )       category = "sports";
            if (LOCATION.match(/variety/) != null )      category = "variety";
            if (LOCATION.match(/infotainment/) != null ) category = "infotainment";
            if (LOCATION.match(/music/) != null )        category = "music";
            if (LOCATION.match(/special/) != null )      category = "special";
            
            if (category == null) return;
            
            var category_xml = XML_DIR + 'category_newarrival_' + category + '08.xml';
            var program_xml  = XML_DIR + 'category_shop_' + category + '08.xml';
			
            // カテゴリ
            top.FEP.controlObj.doControl(category      , category_xml , top.View.dispCategory, 120);
            // 番組一覧
            top.FEP.controlObj.doControl(category      , program_xml  , top.View.dispShop, 120);
            // 新着ニュース
            top.FEP.controlObj.doControl('newsContent'    , XML_DIR + 'index_whatsnew08.xml'  , top.View.dispWhatsNew, 120);
            // ランキング
            top.FEP.controlObj.doControl('rankingArea' , XML_DIR + 'index_ranking08.xml'   , top.View.dispRanking, 120);
            // タイミングでstatusバーが消えないのを…
            top.FEP.controlObj.doControl('rankingArea' , XML_DIR + 'index_hot08.xml'       , top.View.statusClear, 120);

        });
    },


    doControl: function(id, xmlpath, dispFunc, interval) {
        // わざと発生させるジッタの最大値 (秒)
        var jitter = 10;
        // OnLoad 実行
        Concurrent.Thread.create(top.Controller.exec, id, xmlpath, dispFunc);
        // タイマ処理
        if (interval > 0)
            Concurrent.Thread.create(top.Controller.updateChecker, id, xmlpath, dispFunc, interval + Math.floor(Math.random() * jitter));

    }
}
);

// オブジェクト生成 -> 処理開始
top.FEP.controlObj = new top.FEP();

