﻿var ifr_pv;
var ifr_ip;
var Otis = {
    Count: {
        items_arr: new Array(),
        // isConline: isCountOnlineTime; cType: 1:count pv  2 count ip  3 count pv and ip;
        add: function(val, isConline, cType) {
            if (val == undefined) {
                val = window.location.href; if (val.length > 40) { val = val.substr(val.length - 40); }
            }
            if (isConline == undefined) { isConline = false; }
            var ob = new Object(); ob.name = val;
            if (cType == undefined) { cType = 3; }
            ob.onlinc = isConline;
            ob.type = cType;
            this.items_arr.push(ob);
            return Otis.Count;
        },
        init: function() {
            for (var i = 0; i < this.items_arr.length; i++) {
                var it = this.items_arr[i];
                var val = it.name;
                ifr_pv = document.createElement("iframe");
                ifr_pv.src = "http://project.artstudio.com.tw/aodaili_pv_0622/count.ashx?p=" + val + "&t=" + it.type;
                ifr_pv.style.display = "none";
                it.ifrPV = ifr_pv;
                ifr_ip = document.createElement("iframe");
                ifr_ip.src = "";
                ifr_ip.style.display = "none";
                it.ifrIP = ifr_ip;
                document.body.appendChild(ifr_pv); document.body.appendChild(ifr_ip);
            }

            setInterval(function() {

                for (var i = 0; i < Otis.Count.items_arr.length; i++) {
                    var it = Otis.Count.items_arr[i];
                    if (it.onlinc == true) {                
                        var ifr = it.ifrIP;
                        ifr.src = "http://project.artstudio.com.tw/aodaili_pv_0622/count.ashx?p=" + it.name + "&t=2&time=" + new Date().getTime();
                    }
                }
            }, 3*60 * 1000);
        }
    }
}
