﻿var W = "www.pedaily.cn";
var G = "http://" + W + "/Ad/data.ashx";
var H = "http://" + W + "/Ad/hit.ashx";
var I = "http://www.pedaily.cn/uploadfiles/";
function adDefaultShow(obj) { document.write("<div id=\"pe_ad_" + obj.ZoneID + "\" style=\"width:" + obj.Width + "px;height:" + obj.Height + "px;background-color:#fff;color:#000;text-align:center;\">虚位以待<br/>投放热线：400-600-9460</div>"); }
function ValidExpires(overdue) {
    var date = new Date();
    var getdate = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
    var today = new Date(getdate);
    overdue = overdue.replace(/-/g, '/');
    var overdueDate = new Date(overdue);
    if (today <= overdueDate) { return true; }
    return false;
}
function FLS(c, t, d, w, h) { var obj = document.getElementById(c), frame = document.createElement("iframe"); var frameid = 'pe_adframe_' + d; frame.id = frameid; frame.name = frameid; frame.width = w; frame.height = h; frame.vspace = 0; frame.hspace = 0; frame.allowTransparency = 'true'; frame.scroll = 'no'; frame.marginWidth = 0; frame.marginHeight = 0; frame.frameBorder = 0; frame.style.border = 0; obj.insertBefore(frame, obj.firstChild); var doc = frame.contentWindow.document ? frame.contentWindow.document : document.getElementById(frameid).document; doc.write(t); window.setTimeout(function () { doc.close(); }, 0); }
function AdShow(obj) {
    if (!obj.Active) {
        adDefaultShow(obj);
        return;
    }
    var ad = null;
    if (obj.ShowType == 2) {
        var priority = -1;
        for (var i = 0; i < obj.Ads.length; i++) {
            if (!obj.Ads[i].Status || !ValidExpires(obj.Ads[i].Expires)) continue;
            if (obj.Ads[i].Priority > priority) {
                priority = obj.Ads[i].Priority;
                ad = obj.Ads[i];
            }
        }
    } else if (obj.ShowType == 1) {
        var num = obj.Ads.length;
        var sum = 0;
        for (var i = 0; i < num; i++) {
            if (!obj.Ads[i].Status || !ValidExpires(obj.Ads[i].Expires)) continue;
            sum = sum + obj.Ads[i].Priority;
        }
        var rndNum = Math.random() * sum;
        i = 0;
        j = 0;
        while (true) {
            j = j + obj.Ads[i].Priority;
            if (j >= rndNum) { break; }
            i++;
        }
        ad = obj.Ads[i];
    } else {
        ad = obj.Ads[0];
        if (ad.ImgUrl.indexOf("http://") == -1) {
            ad.ImgUrl = I + ad.ImgUrl;
        }
        document.write("<div id=\"pe_ad_loop_" + obj.ZoneID + "\" style=\"width:" + obj.Width + "px;height:" + obj.Height + "px;text-align:center;\">");
        document.write("<a target=\"_blank\" href=\"" + H + "?id=" + ad.AdID + "\">");
        document.write("<img src=\"" + ad.ImgUrl + "\" alt=\"" + ad.ToolTips + "\" style=\"" + (ad.Width <= 0 ? "" : "width:" + ad.Width + "px;") + (ad.Height <= 0 ? "" : "height:" + ad.Height + "px;") + "border:none;\"/>");
        document.write("</a>");
        document.write("</div>");
        var variable = 1;
        window.setInterval(function () {
            if (variable >= obj.Ads.length) variable = 0;
            ad = obj.Ads[variable];
            if (ad.ImgUrl.indexOf("http://") == -1) {
                ad.ImgUrl = I + ad.ImgUrl;
            }
            var xx = ("<a target=\"_blank\" href=\"" + H + "?id=" + ad.AdID + "\">");
            xx += ("<img src=\"" + ad.ImgUrl + "\" alt=\"" + ad.ToolTips + "\" style=\"" + (ad.Width <= 0 ? "" : "width:" + ad.Width + "px;") + (ad.Height <= 0 ? "" : "height:" + ad.Height + "px;") + "border:none;\"/>");
            xx += ("</a>");
            variable++;
            document.getElementById("pe_ad_loop_" + obj.ZoneID).innerHTML = xx;
        }, 5000);
        return;
    }
    if (ad == null) {
        adDefaultShow(obj);
        return;
    }
    if (ad.ImgUrl.indexOf("http://") == -1) {
        ad.ImgUrl = I + ad.ImgUrl;
    }
    if (ad.AdType == 1) {
        document.write("<div style=\"width:" + obj.Width + "px;height:" + obj.Height + "px;text-align:center;\">");
        document.write("<a target=\"_blank\" href=\"" + H + "?id=" + ad.AdID + "\">");
        document.write("<img src=\"" + ad.ImgUrl + "\" alt=\"" + ad.ToolTips + "\" style=\"" + (ad.Width <= 0 ? "" : "width:" + ad.Width + "px;") + (ad.Height <= 0 ? "" : "height:" + ad.Height + "px;") + "border:none;\"/>");
        document.write("</a>");
        document.write("</div>");
    }
    else if (ad.AdType == 2) {
        if (ad.Width <= 0) ad.Width = obj.Width;
        if (ad.Height <= 0) ad.Height = obj.Height;
        var containerid = "pe_adcontainer_" + obj.ZoneID;
        document.write("<div id=\"" + containerid + "\"></div>");
        var fsh = '';
        fsh += ("<div style=\"position:relative;width:" + obj.Width + "px;height:" + obj.Height + "px;\">");
        fsh += ("<a style=\"position: absolute; filter: alpha(opacity=0); WIDTH: 100%; bottom: 0px; display: block; height: expression(this.parentNode.scrollHeight); TOP: 0px; right: 0px; left: 0px;*background:#FFFFFF;\" href=\"" + H + "?id=" + ad.AdID + "\" target=\"_blank\"></a>");
        fsh += ("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" id=\"pe_adobj_" + obj.ZoneID + "\" name=\"pe_adobj_" + obj.ZoneID + "\" width=\"" + ad.Width + "\" height=\"" + ad.Height + "\" align=\"middle\">");
        fsh += ("<param name=\"allowScriptAccess\" value=\"always\">");
        fsh += ("<param name=\"quality\" value=\"high\">");
        fsh += ("<param name=\"wmode\" value=\"Opaque\">");
        fsh += ("<param name=\"movie\" value=\"" + ad.ImgUrl + "\">");
        fsh += ("<embed wmode=\"Opaque\" name=\"pe_adembed_" + obj.ZoneID + "\" src=\"" + ad.ImgUrl + "\" quality=\"high\" width=\"" + ad.Width + "\" height=\"" + ad.Height + "\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">");
        fsh += ("</object></div>");
        FLS(containerid, fsh, obj.ZoneID, ad.Width, ad.Height);
    } else if (ad.AdType == 3 || ad.AdType == 4) {
        document.write("<div style=\"width:" + obj.Width + "px;height:" + obj.Height + "px;\">");
        document.write(ad.Intro);
        document.write("</div>");
    } else if (ad.AdType == 5) {
        document.write("<iframe id=\"AD_" + obj.ZoneID + "\" marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no width=100% height=100% src=\"" + ad.Intro + "\">AD</iframe>");
    }
    document.write("<script type=\"text/javascript\" src=\"http://" + W + "/ad/show.ashx?id=" + ad.AdID + "\"></" + "script>");
}
//adover,others
function ShowPictures(_pics,_links,_width,_height,_src)
{
	if(parent.location.hostname.split('.')[0] != "www")
	{
		_links = _links.replace(/http:\/\//g,"http://" + parent.location.hostname.split('.')[0] + ".");
	}
    var writeText = "";
    writeText += "<embed id=\"focus_flash1\" src=\"" + _src + "\" wmode=\"opaque\" bgcolor=\"#FDD248\"";
    writeText += " FlashVars=\"pics=";
    writeText += _pics;
    writeText += "&links=";
    writeText += _links;
    writeText += "&borderwidth=" + _width + "&borderheight=" + _height + "\" ";
    writeText += "menu=\"false\" quality=\"high\" width=\"" + _width + "\" height=\"" + _height + "\" ";
    writeText += " allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" ";
    writeText += " pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
    document.write(writeText);
}					
function changeRankStyle(o)
{
	var rank=document.getElementById(o);
	var nLi = $(rank).children("li");
	for(var i=0;i<nLi.length; i++)
	{
		$(nLi[i]).find("span").first().text(i+1);
	}
       if (nLi.length >= 3) {
            for (var i = 0; i < 3; i++) {
                $(nLi[i]).addClass("top");
            }
        }
}

