function Template(str, data) {
    var fnText = "var __p__=[]; with(obj){__p__.push('" + str.replace(/[\r\t\n]/g, " ").replace(/\'/g, '"').split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split("\t").join("');").split("%>").join("__p__.push('").split("\r").join("\\'") + "');}return __p__.join('');";
    var fn = new Function("obj", fnText);
    return fn(data);
}
function makeColorBall(d) {	
    var cls = d.type.indexOf('足彩') === -1 ? 'red': 'small';
    var numArr = d.WareResult.split(':'),
    html = ['<span class="' + cls + '">', numArr[0].replace(/,/g, '</span><span class="' + cls + '">'), '</span>'];
    if (numArr[1]) {
        html = html.concat(['<span class="blue">', numArr[1].replace(/,/g, '</span><span class="blue">'), '</span>']);
    }
    return html.join('');
}
function isLast(key, obj) {
    var temp = [];
    for (var p in obj) {
        temp.push(p);
    }
    return key === temp[temp.length - 1];
}
var caipiao = function() {
    var url = G_dirUrl+'images/caipiao/Ajax_value.asp?v=1',
    tpl = $('#table_template').html(),
    tplMap = {
        '超级大乐透': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/dlt/',
            'date': '一、三、六',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/dlt.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/dlt/',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/dlt/'
            },
            'type': '体彩'
        },
        '七星彩': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/qxc/',
            'date': '二、五、日',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/qxc.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/qxc/zoushi/jbzs.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/qxc/'
            },
            'type': '体彩'
        },
        '排列五': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/plw/',
            'date': '每日',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/plw.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/plw/zoushi/jbzs.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/plw/'
            },
            'type': '体彩'
        },
        '排列三': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/pls/',
            'date': '每日',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/pls.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/pls/zoushi/jbzs.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/pls/'
            },
            'type': '体彩'
        },
        '双色球': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/ssq/',
            'date': '二、四、日',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/ssq.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/ssq/zoushi/jbzs_redblue.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/ssq/'
            },
            'type': '福彩'
        },
        '福彩3D': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sd/',
            'date': '每日',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/sd.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/sd/zoushi/jbzs.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sd/'
            },
            'type': '福彩'
        },
        '七乐彩': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/qlc/',
            'date': '一、三、五',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://kaijiang.500wan.com/qlc.shtml',
                '走势': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://datachart.500wan.com/qlc/zoushi/jbzs_sanf.shtml',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/qlc/'
            },
            'type': '福彩'
        },
        '足彩胜负彩': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sfc/index.php?',
            'date': '一、三、五',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://zx.500wan.com/zc/',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sfc/index.php?'
            },
            'type': '足彩'
        },
        '半全场胜负彩': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/zc6/index.php?',
            'date': '一、三、五',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://zx.500wan.com/zc/',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/zc6/index.php?'
            },
            'type': '足彩'
        },
        '足彩任选九场': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sfc/index.php?',
            'date': '一、三、五',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://zx.500wan.com/zc/',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/sfc/index.php?'
            },
            'type': '足彩'
        },
        '四场进球彩': {
            'link': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/jq4/index.php?',
            'date': '一、三、五',
            'opt': {
                '详情': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://zx.500wan.com/zc/',
                '立即购买': 'http://www.500wan.com/pages/info/public/interfacehezuo.php?regfrom=1616net&tourl=http://trade.500wan.com/jq4/index.php?'
            },
            'type': '足彩'
        }
    };
    return {
        init: function() {
            var lists = $('#cai>li:not(:last)'),
            timer;
            lists.click(function() {
                if (this.className === 'on') return false;
                var index = lists.index(this);
                $('.day').html(index == 2 ? '': '开奖日');
                lists.removeClass('on').eq(index).addClass('on');
                $('#piao>table').hide().eq(index).show();
            }).mouseover(function() {
                var _this = $(this);
                timer = setTimeout(function() {
                    _this.click();
                },
                300);
            }).mouseout(function() {
                clearTimeout(timer);
            });
            this.getData();
        },
        getData: function() {
            var _this = this;
            $.getJSON(url,
            function(data) {
                data = $.extend(true, tplMap, data);
                var result = {};
                for (var p in data) {
                    var type = data[p]['type'];
                    if (type) {
                        if (!result[type]) result[type] = {};
                        result[type][p] = data[p];
                    }
                }
                _this.renderer(result);
            });
        },
        renderer: function(d) {
            d = Template(tpl, {
                data: d
            });
            $('#piao').html(d).find('table').hide().eq(0).show();
        }
    }
} ();
parent === self ? caipiao.init() : parent.J.add('caipiao', caipiao, window);