if (typeof(TomRota) != "object") {
    var TomRota = {}
}
TomRota.$ = function(objId){
    if (!objId) {
        throw new Error("TomRota.$(String objId)参数必须")
    }
    if (document.getElementById) {
        return eval('document.getElementById("' + objId + '")')
    }
    else 
        if (document.layers) {
            return eval("document.layers['" + objId + "']")
        }
        else {
            return eval('document.all.' + objId)
        }
}
TomRotaFlash = function(C, v, x, V, c, X, i, O, I, l, o){
    var z = this;
    if (!document.createElement || !document.getElementById) {
        return
    }
    z.id = v ? v : "tomad";
    z.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
    z.codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + (c ? c : "7") + ",0,0,0";
    z.width = x;
    z.height = V;
	z.allowscriptaccess="always";
    z.movie = C;
    z.bgcolor = X ? X : null;
    z.quality = O ? O : "high";
    z.src = z.movie;
    z.pluginspage = "http://www.macromedia.com/go/getflashplayer";
    z.type = "application/x-shockwave-flash";
    z.useExpressInstall = i ? i : null;
    z.xir = (I) ? I : window.location;
    z.redirectUrl = l ? l : null;
    z.detectKey = o ? o : null;
    z.escapeIs = false;
    z.objAttrs = {};
    z.params = {};
    z.flashVars = [];
    z.flashVarsStr = "";
    z.embedAttrs = {};
    z.forSetAttribute("id", z.id);
    z.objAttrs["classid"] = z.classid;
    z.forSetAttribute("codebase", z.codebase);
    z.forSetAttribute("width", z.width);
    z.forSetAttribute("height", z.height);
    z.forSetAttribute("movie", z.movie);
    z.forSetAttribute("quality", z.quality);
    z.forSetAttribute("pluginspage", z.pluginspage);
    z.forSetAttribute("type", z.type);
    z.forSetAttribute("bgcolor", z.bgcolor);
	z.forSetAttribute("allowscriptaccess",z.allowscriptaccess)
}
TomRotaFlash.prototype = {
    getFlashHtml: function(){
        var I = this, i = '<object ';
        for (var l in I.objAttrs) {
            i += l + '="' + I.objAttrs[l] + '" '
        }
        i += '>';
        for (var l in I.params) {
            i += '<param name="' + l + '" value="' + I.params[l] + '" /> '
        }
        if (I.flashVarsStr != "") {
            i += '<param name="FlashVars" value="' + I.flashVarsStr + '" /> '
        }
        i += '<embed ';
        for (var l in I.embedAttrs) {
            i += l + '="' + I.embedAttrs[l] + '" '
        }
        i += ' ></embed></object>';
        return i
    },
    forSetAttribute: function(I, i){
        var l = this;
        I = I.toLowerCase();
        switch (I) {
            case "classid":
                break;
            case "pluginspage":
                l.embedAttrs["pluginspage"] = i;
                break;
            case "src":
                l.embedAttrs["src"] = i;
                l.params["movie"] = i;
                break;
            case "movie":
                l.params["movie"] = i;
                l.embedAttrs["src"] = i;
                break;
            case "onafterupdate":
            case "onbeforeupdate":
            case "onblur":
            case "oncellchange":
            case "onclick":
            case "ondblClick":
            case "ondrag":
            case "ondragend":
            case "ondragenter":
            case "ondragleave":
            case "ondragover":
            case "ondrop":
            case "onfinish":
            case "onfocus":
            case "onhelp":
            case "onmousedown":
            case "onmouseup":
            case "onmouseover":
            case "onmousemove":
            case "onmouseout":
            case "onkeypress":
            case "onkeydown":
            case "onkeyup":
            case "onload":
            case "onlosecapture":
            case "onpropertychange":
            case "onreadystatechange":
            case "onrowsdelete":
            case "onrowenter":
            case "onrowexit":
            case "onrowsinserted":
            case "onstart":
            case "onscroll":
            case "onbeforeeditfocus":
            case "onactivate":
            case "onbeforedeactivate":
            case "ondeactivate":
            case "type":
                l.embedAttrs["type"] = i;
                break;
            case "codebase":
                l.objAttrs["codebase"] = i;
                break;
            case "width":
                l.objAttrs["width"] = i;
                l.embedAttrs["width"] = i;
                break;
            case "height":
                l.objAttrs["height"] = i;
                l.embedAttrs["height"] = i;
                break;
            case "align":
                l.objAttrs["align"] = i;
                l.embedAttrs["align"] = i;
                break;
            case "vspace":
                l.objAttrs["vspace"] = i;
                l.embedAttrs["vspace"] = i;
                break;
            case "hspace":
                l.objAttrs["hspace"] = i;
                l.embedAttrs["hspace"] = i;
                break;
            case "class":
                l.objAttrs["class"] = i;
                l.embedAttrs["class"] = i;
                break;
            case "title":
                l.objAttrs["title"] = i;
                break;
            case "accesskey":
                l.objAttrs["accesskey"] = i;
                break;
            case "name":
                l.objAttrs["name"] = i;
                l.embedAttrs["name"] = i;
                break;
            case "id":
                l.objAttrs["id"] = i;
                l.embedAttrs["name"] = i;
                break;
            case "tabindex":
                l.objAttrs["tabindex"] = i;
                break;
            default:
                l.params[I] = l.embedAttrs[I] = i
        }
    },
    forGetAttribute: function(i){
        var I = this;
        i = i.toLowerCase();
        if (I.objAttrs[i] != undefined) {
            return I.objAttrs[i]
        }
        else 
            if (I.embedAttrs[i] != undefined) {
                return I.embedAttrs[i]
            }
            else 
                if (I.embedAttrs != undefined) {
                    return I.embedAttrs[i]
                }
                else {
                    return null
                }
    },
    setAttribute: function(I, i){
        this.forSetAttribute(I, i)
    },
    getAttribute: function(i){
        return this.forGetAttribute(i)
    },
    addVariable: function(I, i){
        var l = this;
        if (l.escapeIs) {
            I = escape(I);
            i = escape(i)
        }
        if (l.flashVarsStr == "") {
            l.flashVarsStr = I + "=" + i
        }
        else {
            l.flashVarsStr += "&" + I + "=" + i
        }
        l.embedAttrs["FlashVars"] = l.flashVarsStr
    },
    getVariable: function(I){
        var o = this, i = o.flashVarsStr;
        if (o.escapeIs) {
            I = escape(I)
        }
        var l = new RegExp(I + "=([^\\&]*)(\\&)", "i").exec(i);
        if (o.escapeIs) {
            return unescape(RegExp.$1)
        }
        return RegExp.$1
    },
    addParam: function(I, i){
        this.forSetAttribute(I, i)
    },
    getParam: function(){
        return this.forGetAttribute(name)
    },
    write: function(i){
        var I = this;
        if (typeof i == "string") {
            TomRota.$(i).innerHTML = I.getFlashHtml()
        }
        else 
            if (typeof i == "object") {
                i.innerHTML = I.getFlashHtml()
            }
    }
}



if (typeof(TomADRota) != 'function') {
    var TomADRota = function(_tad, _id, _w, _h, _c, _did){
        this.tbary = new Array();
        this.tbary = _tad;
        this.w = _w;
        this.h = _h;
        this.did = _did
        this.o = _tad.length;
        this.id = TomADRota.id++;
        this.a = _c + this.id;
        this.j = new Array();
        this.t = new Date();
        this.s = 0;
        var M;
        var DC = false;//cookie
        for (var i = 0; i < this.o; i++) {
            M = this.a + '_' + (i + 1);
            z = TomADRota.GC(M);
            if (z != '') {
                this.j[i] = z;
                DC = true;
            }
            else {
                this.j[i] = 0;
            }
        }
        
        if (!DC) {
            var r = (parseInt(_id) != 0) ? parseInt(_id) : Math.ceil(Math.random() * this.o);
            var t = this.a + '_' + r;
            TomADRota.SC(t, this.t.getTime(), 1440);
            this.s = r;
            //return r;
        }
        else {
            var R = this.j.join(',').split(',');
            var k = R.sort();
            var max = Number(k[k.length - 1]);
            var min = Number(k[0]);
            var F;
            for (var i = 0; i < this.j.length; i++) {
                if (max == this.j[i]) {
                    F = i + 1;
                    break;
                }
            }
            if (typeof(F) != 'undefined') {
                G = this.a + '_' + F;
                
                H = Number(TomADRota.GC(G));
                I = F % this.o + 1;
                J = this.a + '_' + I;
                TomADRota.SC(J, this.t.getTime(), 1440);
                this.s = I;
                //return I;
            }
        }
        
        //Show AD
        if (this.s == 0 || this.o == 0) 
            return; //如果没有广告则不显示
        var n = this.s - 1;
        var AdSrc = this.tbary[n][0];
        var AdUrl = this.tbary[n][1];
        var AdType = AdSrc.substring(AdSrc.length - 3).toLowerCase();
        TomADRota.ShowAd(AdSrc, AdUrl, AdType, this.w, this.h, this.did);
    };
    
    
    TomADRota.id = 1;
    
    TomADRota.GC = function(N){
        var cook = document.cookie.split("; ");
        for (var i = 0; i < cook.length; i++) {
            var d = cook[i].split("=");
            if (d[0] == N) 
                return unescape(d[1]);
        }
        return '';
    };
    
    TomADRota.SC = function(N, V, Q){
        var L = new Date();
        var z = new Date(L.getTime() + Q * 60000);
        document.cookie = N + "=" + escape(V) + "; path=/; expires=" + z.toGMTString() + ";";
    };
    
    TomADRota.ShowAd = function(S, U, T, W, H, D){
        if (T != "swf") {
            if (T == "htm") {
                var s = "<iframe src='" + S + "' WIDTH='" + W + "' HEIGHT='" + H + "'  frameborder='no' border='0' marginwidth='0' marginheight='0' scrolling='no'></iframe>";
				 document.getElementById(D).innerHTML = s;
				}
           else if(T == "jpg" || T == "gif" || T == "png"){
                var s = "<a href='" + U + "' target = '_blank'><img src='" + S + "' WIDTH='" + W + "' HEIGHT='" + H + "'  border = 0></a>";
				 document.getElementById(D).innerHTML = s;
				}
				 //document.write(s);
           else{
			var objFlash = new TomRotaFlash(S, "", W, H, "7", "");
            objFlash.addParam("quality", "high");
            objFlash.addParam("wmode", "opaque");
            objFlash.write(D);
			}
        }
        else {
            var objFlash = new TomRotaFlash(S, "", W, H, "7", "");
            objFlash.addParam("quality", "high");
            objFlash.addParam("wmode", "opaque");
            objFlash.write(D);
        }
    }
};
