﻿String.prototype.endWith = function(oString) {
    var reg = new RegExp(oString + "$");
    return reg.test(this);
}
$("body").ready(function() {
    $("[id^=ad_element]").each(function(i) {
        var _eid = $(this).attr("id");
        var _epath = $(this).attr("src");
        var _ewidth = $(this).css("width");
        var _eheight = $(this).css("height");

        if (_ewidth == "auto") {
            _ewidth = $(this).parent().parent().css("width");
        }
        if (_eheight == "auto") {
            var _pheight = $(this).parent().parent().css("height");
            _eheight = (_pheight == "") ? "auto" : _pheight;
        }
        if (_epath.toLowerCase().endWith(".swf")) {
            _epath = _epath.replace("../", "/");
            var adplayer = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
            adplayer += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
            adplayer += 'width="' + _ewidth + '" height="'+_eheight +'" id="' + _eid + '" align="middle">';
            adplayer += '<param name="allowScriptAccess" value="sameDomain" />';
            adplayer += '<param name="movie" value="' + _epath + '" />';
            adplayer += '<param name="quality" value="high" />';
            adplayer += '<param name="wmode" value="transparent">';
            adplayer += '<embed wmode="transparent" src="' + _epath + '" quality="high" width="' + _ewidth + '" height="' + _eheight + '" name="' + _eid + '" align="middle" ';
            adplayer += ' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>';
            $(this).parent().parent().empty().append(adplayer);
        }
    });
});
