/*
 * jQuery OpenX ad tags plugin
 *
 * Tested with OpenX Community Edition 2.8.8-rc6
 *
 * @version 1.1
 * @date Wed Aug 3 00:21:14 2011 +0400
 * @requires jQuery
 * @url http://plugins.jquery.com/project/openxtag
 *
 * @author Nikolay Morev <kolia@denivip.ru>
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 *
 */(function($){function loadFlashObjectOnce(a,b){if(typeof window.org!="undefined"&&typeof window.org.openx!="undefined"&&typeof window.org.openx.SWFObject!="undefined")b();else{var c=(location.protocol=="https:"?a.deliverySSL:a.delivery)+"/"+a.swfObjectJS;$.getScript(c,b)}}function _buildStandardRequestParameters(a){var b={charset:a.charset,target:a.target,source:a.source,loc:window.location.href};typeof a.extra!="undefined"&&(b=$.extend(b,a.extra)),typeof a.block!="undefined"&&(b.block=a.block?1:0),typeof a.blockcampaign!="undefined"&&(b.blockcampaign=a.blockcampaign?1:0),document.referrer&&(b.referer=document.referrer);for(var c in b)typeof b[c]=="undefined"&&delete b[c];return b}function _validateSettings(a){location.protocol=="https:"?typeof a.deliverySSL!="string"&&$.error('please set "deliverySSL" option for openxtag'):typeof a.delivery!="string"&&$.error('please set "delivery" option for openxtag')}function _genericZoneCall(a,b,c,d){if(typeof b=="object"||typeof b=="function")d=c,c=b,b=null;typeof c=="function"&&(d=c,c=null);var e=$.extend(defaults,c);b!=null&&(e.zoneID=b);return a.apply(this,[b,e,d])}function _documentWriteSafeAppend(a,b){var c=0;(function(a){if(a.match(/document\.write|<script/)){var d=document.write,e="";document.write=function(a){e+=a},b.append(a),document.write=d,c++,c>_loopIterations&&$.error("openxtag: document.write loop stopped after "+_loopIterations+" iterations"),arguments.callee(e)}else b.append(a),typeof success=="function"&&setTimeout(success,0)})(a)}var _loopIterations=10,defaults={jsPrefix:"OA_",swfObjectJS:"fl.js",delivery:null,deliverySSL:null,jsTagScript:"ajs.php",spcTagScript:"spc.php",iframeTagScript:"afr.php",adViewScript:"avw.php",clickScript:"ck.php",charset:"UTF-8",zoneID:null,target:undefined,source:undefined,blockcampaign:undefined,block:undefined,forceAsync:!1,refresh:undefined,resize:undefined,allowtransparent:undefined,width:undefined,height:undefined,extra:undefined},init=function(a){defaults=$.extend(defaults,a)},jsZone=function(a,b,c){return this.each(function(){var a=$(this),c=$.extend({},b);typeof $.metadata!="undefined"&&(c=$.extend(c,a.metadata())),_validateSettings(c);var d=c.zoneID;d==null&&$.error('please set "zoneID" option for openxtag jsZone');var e=_buildStandardRequestParameters(c);e.zoneid=d,e.cb=Math.floor(Math.random()*99999999999),document.MAX_used||(document.MAX_used=","),document.MAX_used!=","&&(e.exclude=document.MAX_used),document.context&&(e.context=document.context),document.mmm_fo&&(e.mmm_fo=1);var f=(location.protocol=="https:"?c.deliverySSL:c.delivery)+"/"+c.jsTagScript;$.ajax({url:f,data:e,dataType:"html",async:c.forceAsync,success:function(b){_documentWriteSafeAppend('<script type="text/javascript">'+b+"</script>",a)}})})},iFrameZone=function(a,b,c){return this.each(function(){var a=$(this),c=$.extend({},b);typeof $.metadata!="undefined"&&(c=$.extend(c,a.metadata())),_validateSettings(c);var d=c.zoneID;d==null&&$.error('please set "zoneID" option for openxtag iframe');var e=_buildStandardRequestParameters(c);e.zoneid=d,e.cb=Math.floor(Math.random()*99999999999),typeof c.refresh!="undefined"&&(e.refresh=c.refresh),typeof c.resize!="undefined"&&(e.resize=c.resize?1:0),typeof c.width=="undefined"&&$.error("openxtag: width parameter is required for iframe tag");var f=c.width;typeof c.height=="undefined"&&$.error("openxtag: height parameter is required for iframe tag");var g=c.height,h="";typeof c.allowtransparent!="allowtransparent"&&c.allowtransparent&&(h=' allowtransparency="true" ');var i="a"+Math.floor(Math.random()*999999),j=typeof c.target=="undefined"?"_blank":c.target,k=location.protocol=="https:"?c.deliverySSL:c.delivery,l=k+"/"+c.iframeTagScript,m=k+"/"+c.clickScript,n=k+"/"+c.adViewScript;a.append("<iframe id='"+i+"' name='"+i+"' src='"+l+"?"+$.param(e)+"' frameborder='0' scrolling='no' width='"+f+"' height='"+g+"'"+h+"><a href='"+m+"?n="+i+"&amp;cb="+e.cb+"' target='"+j+"'><img src='"+n+"?zoneid="+d+"&amp;cb="+e.cb+"&amp;n="+i+"' border='0' alt='' /></a></iframe>")})},spcTag=function(zoneID,settings,success){var zones={},i=0,chainObj=this.each(function(){var a=$(this),b=$.extend({},settings);typeof $.metadata!="undefined"&&(b=$.extend(b,a.metadata()));var c=b.zoneID;c==null&&$.error('please set "zoneID" option for openxtag jsZone');var d="z"+i;zones[d]=c,a.data("openxtag",{zn:d}),i++}),thesettings=$.extend({},settings);_validateSettings(thesettings);var data=_buildStandardRequestParameters(thesettings);data.zones=$.map(zones,function(a,b){return b+"="+a}).join("|"),data.nz=1;var scriptURL=(location.protocol=="https:"?thesettings.deliverySSL:thesettings.delivery)+"/"+thesettings.spcTagScript,that=this;$.ajax({url:scriptURL,data:data,dataType:"script",success:function(data){loadFlashObjectOnce(thesettings,function(){var output=eval("(function () {"+data+";return "+thesettings.jsPrefix+"output;})()");that.each(function(){var a=$(this);_documentWriteSafeAppend(output[a.data("openxtag").zn],a)})})}});return chainObj},fnMethods={zone:jsZone,jsZone:jsZone,spc:spcTag,iframe:iFrameZone};$.fn.extend({openxtag:function(a){if(fnMethods[a])return _genericZoneCall.apply(this,[fnMethods[a]].concat(Array.prototype.slice.call(arguments,1)));$.error("Method "+a+" does not exist on jQuery.openxtag")}});var methods={init:init};$.extend({openxtag:function(a){if(methods[a])return methods[a].apply(this,Array.prototype.slice.call(arguments,1));if(typeof a=="object"||!a)return methods.init.apply(this,arguments);$.error("Method "+a+" does not exist on jQuery.openxtag")}})})(jQuery)
