/**
 * @copyright by AdOcean 2010
 * @author Piotr Sadowski
 */

var AdoElement=function(config){var that=this;this.loadingLib=false;this.buff=ado.placeholder;this.tmpBuff="";this.config=config;this.onLoad=config.onLoad;this.DOMElement={};this.regs={scriptBegin:/^\s*(<script\s*)(\s*(\w+)\s*=\s*(([^\s\"\'>]{1}[^\s>]*)|\"([^\"]*)\"|\'([^\']*)\'))*[^\w>]*>/i,scriptEnd:/(<\/script\b([^>\"\']|\"[^\"]*\"|\'[^\']*\')*>)/i,attr:/(\s*(\w+)\s*=\s*(([^\s\"\'>]{1}[^\s>]*)|\"([^\"]*)\"|\'([^\']*)\'))/};this.myWrite=function(t){that.tmpBuff+=t;};this.myWriteln=function(t){that.myWrite(t+"\n");};this.isMaster=function(){return this.config.master;};this.isSlave=function(){return this.config.slave;};this.initBuffor=function(){ado.busy=true;window.document.open=function(){};window.document.close=function(){};document.write=that.myWrite;document.writeln=that.myWriteln;};this.rewriteBuffor=function(){if(this.buff.indexOf(ado.placeholder)!==-1){this.buff=that.buff.replace(ado.placeholder,that.tmpBuff);}
else{this.buff=this.tmpBuff+this.buff;}
this.tmpBuff="";};this.preDispatch=function(){if(typeof this.config!=="object"){return;}
if(!this.config.id||!this.config.server){return;}
if(ado.protocol.substr(0,4)!=='http'){return;}
this.getDOMElement();this.emptyDOMElement();if(!this.isSlave()){if(this.config.preview){this.config.url=this.config.server;}
else{this.makeUrl();}}
this.appendRedirUrl();if(ado.mode==='old'||!ado.isBrowserSupport()){document.write("<scr"+"ipt type='text/javascript' src='"+that.config.url+"'></scr"+"ipt>");}
else{this.initBuffor();this.appendScript(this.config.url,null,true);}};this.postDispatch=function(){ado.busy=false;ado.start();};this.dispatch=function(){this.deleteComment();var arr=[];var that=this;if(this.regs.scriptBegin.test(this.buff)&&this.regs.scriptBegin.test(this.buff)){arr=this.regs.scriptBegin.exec(that.buff);var attr=this.processAttributes(arr[0]);if(attr.src){this.processSrcScript(arr,attr.src,attr.charset);}
else if(attr.language!=="VBScript"&&attr.type!='text/vbscript'){this.processInlineScript(arr);}
else{this.processVBScript(arr);}}
else{var rewrite=function(){if(that.DOMElement){that.addToDOMElement(that.buff.replace(ado.placeholder,""));that.buff="";}
if(typeof that.config.onLoad==="function"){that.onLoad();that.onLoad=false;}
that.postDispatch();};if(!this.regs.scriptBegin.test(that.buff)){var regexp=/<script/i;arr=regexp.exec(that.buff);if(arr){var index=that.buff.indexOf(arr[0]);that.DOMElement=ado.getById(that.config.id);if(that.DOMElement){that.addToDOMElement(this.buff.substr(0,index).replace(ado.placeholder,""));}
this.buff=this.buff.substr(index);this.dispatch();}
else{rewrite();}}}
return;};this.deleteComment=function(){var c=/\<!\s*--(.*?)(--\s*\>)/m;while(c.test(that.buff)){that.buff=that.buff.replace(c,"");}};this.processVBScript=function(arr){var scriptEnd=this.regs.scriptEnd.exec(that.buff);td_flashinstalled=2;td_browserFlashversion=8;this.buff=ado.placeholder+this.buff.substr(scriptEnd.index+scriptEnd[0].length);that.dispatch();};this.processSrcScript=function(arr,src,charset){that.buff=that.buff.substr(arr[0].length);var scriptEnd=this.regs.scriptEnd.exec(that.buff);this.buff=ado.placeholder+this.buff.substr(scriptEnd.index+scriptEnd[0].length);this.appendScript(src,charset);};this.appendScript=function(url,charset,fast,callback){var onscriptload=function(object){that.loadingLib=false;if(typeof callback==="function"){callback();}
that.rewriteBuffor();that.dispatch();};this.loadingLib=true;ado.loadScript(url,onscriptload,charset);return;};this.onServerEmission=function(){var empty=function(){if(typeof that.config.onServerEmissionEmpty==="function"){that.config.onServerEmissionEmpty();}};if(typeof adserver_emissions==="object"){var length=0;for(var i in adserver_emissions){if(typeof adserver_emissions[i]!=="function"){length++;}}
if(length>ado.adserverEmissions){ado.adserverEmissions++;if(typeof that.config.onServerEmission==="function"){that.config.onServerEmission();}}
else{empty();}}
else{empty();}};this.processInlineScript=function(arr){if(that.loadingLib){return;}
this.buff=this.buff.substr(arr[0].length);var scriptEnd=this.regs.scriptEnd.exec(that.buff);var iS=this.buff.substr(0,scriptEnd.index);this.buff=ado.placeholder+this.buff.substr(scriptEnd.index+scriptEnd[0].length);iS=iS.replace('/*<![CDATA[*/','');iS=iS.replace('<![CDATA[','');iS=iS.replace('/* <![CDATA[ */','');iS=iS.replace('/* ]]> */','');iS=iS.replace('/*]]>*/','');iS=iS.replace('<!--','');iS=iS.replace('//-->','');iS=iS.replace('//]]>-->','');iS=iS.replace(/\/\*.*\*\//g,'');try{ado.evaluate(iS);}
catch(ex){}
this.rewriteBuffor();this.dispatch();return;};this.processAttributes=function(tag){var att={};while(tag.length>0){var arr=that.regs.attr.exec(tag);if(!arr){break;}
tag=tag.substr(arr.index+arr[1].length);var value=null;if(arr[4]){value=arr[4];}
if(arr[5]){value=arr[5];}
if(arr[6]){value=arr[6];}
att[arr[2].toLowerCase()]=value;}
return att;};this.getDOMElement=function(){this.DOMElement=ado.getById(this.config.id);if(!this.DOMElement){return;}};this.emptyDOMElement=function(){if(this.DOMElement){this.DOMElement.innerHTML="";this.DOMElement.style.display="none";}};this.addToDOMElement=function(str){if(this.DOMElement&&str!==""){this.DOMElement.style.display="block";this.DOMElement.innerHTML+=str;}};this.insertToDOMElement=function(str){if(this.DOMElement&&str!==""){this.DOMElement.style.display="block";this.DOMElement.innerHTML=str;}};this.makeUrl=function(){if(this.config.preview){this.config.server=this.config.emiter;}
var ct=this.config.contentType;switch(ct){case'txt':case'xml':case'js':break;default:ct='js';break;}
this.config.url=ado.protocol+"//"+this.config.server;this.config.url+="/_"+(new Date()).getTime()+"/ad."+ct+"?id="+ado.trimAdoPrefix(this.config.orgId)+"/x="+screen.width+"/y="+screen.height;this.config.url+=ado.makeKeywords(this.config.keys)+ado.makeVars(this.config.vars)+ado.makeFlash();return;};this.appendRedirUrl=function(){if(this.config.redir&&this.config.redir!==""&&this.config.redir!="<%%REDIR%%>"){this.config.url=this.config.url+"/redir="+this.config.redir;}};};var AdoContainer=function(){var that=this;var userAgent=navigator.userAgent.toLowerCase();var tuneId=function(config){config.orgId=config.id;config.id=config.id+""+ado.iterator++;var de=ado.getById(config.orgId);if(de){de.id=config.id;}
return config;};var keywordEncode=function(s){var d="";var k=0;var c='';if(!s){return;}
for(k=0;k<s.length;k++){c=s.charCodeAt(k);if(c<0x80){d+=s.charAt(k);}
else
if(c>=0x80&&c<=0x7ff){d+=String.fromCharCode(((c>>6)&0x1f)|0xc0,(c&0x3f)|0x80);}
else{d+=String.fromCharCode((c>>12)|0xe0,((c>>6)&0x3f)|0x80,(c&0x3f)|0x80);}}
return escape(d).replace(/\//g,'%2F').replace(/\@/g,'%40').replace(/\*/g,'%2A').replace(/\+/g,'%2B').replace(/\%/g,'$');};this.elems=[];this.urlsMapping=[];this.masterSlaves=[];this.queue=[];this.iterator=0;this.busy=false;this.placeholder="__MARKER__";this.mode="old";this.characterEncoding=true;this.xml=false;this.previewUrl="";this.previewEnabled=[];this.tmp=[];this.adserverEmissions=0;this.windowLoad=false;this.protocol="";this.browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:/msie/.test(userAgent)&&!/opera/.test(userAgent),mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};this.config=function(cfg){this.mode=cfg.mode;this.xml=cfg.xml;this.characterEncoding=cfg.characterEncoding;if(cfg.protocol){this.protocol=cfg.protocol;}
else{this.protocol=location.protocol;}};this.resolvId=function(id,soft){for(var i in ado.elems){var cfg=ado.elems[i].config;if(cfg){if(soft){if(cfg.orgId===id||cfg.orgId==="ado-"+id){return i;}}
else{if((cfg.orgId===id||cfg.orgId==="ado-"+id)&&ado.elems[i].begin===false){return i;}}}}
return false;};this.addAdoPrefix=function(config){if(config.id.length===46){config.id="ado-"+config.id;}
return config;};this.trimAdoPrefix=function(orgId){if(orgId.length==46){return orgId;}
else if(orgId.indexOf('ado-')===0){return orgId.substring(4,50);}
else{return orgId;}};this.beginCreative=function(config){var tmp=this.elems[ado.resolvId(config.id,true)];if(tmp){tmp.onServerEmission();}
return tmp;};this.beginExternal=function(){};this.endExternal=function(){};this.refresh=function(id){var elem=ado.elems[ado.resolvId(id,true)];if(elem.isMaster()){ado.master(elem.config);this.masterSlaves[elem.config.orgId]=[];for(var i in ado.elems){if(typeof ado.elems[i]==="object"&&ado.elems[i].config.slave&&ado.elems[i].config.myMaster===elem.config.orgId){var config=ado.elems[i].config;ado.elems[i].emptyDOMElement();ado.slave(config.orgId,config);}}}
else{ado.placement(elem.config);ado.start();}};this.placement=function(config){if(!config.id||!config.server){return;}
if(!config.orgId){config=tuneId(config);}
var test=(ado.mode=="new"&&!ado.windowLoad&&this.isBrowserSupport());if((ado.mode=="new"&&!ado.windowLoad&&this.isBrowserSupport())||ado.busy){ado.queue.unshift(function(){ado.placement(config);});return;}
if(ado.previewEnabled['http://'+config.server]){config.preview=true;config.server=ado.previewUrl+"?id="+ado.trimAdoPrefix(config.orgId);}
this.elems[config.id]=new AdoElement(config);if(!ado.elems[config.id].DOMElement){return;}
this.elems[config.id].preDispatch();};this.master=function(config){config.master=true;if((ado.mode=="new"&&!ado.windowLoad&&this.isBrowserSupport())||ado.busy){ado.queue.unshift(function(){ado.master(config);});return;}
if(!config.orgId){config=tuneId(config);}
if(typeof this.masterSlaves[config.orgId]==="undefined"){this.masterSlaves[config.orgId]=[];}
this.elems[config.id]=new AdoElement(config);if(ado.previewEnabled['http://'+config.server]){config.preview=true;config.server=ado.previewUrl+"?id="+ado.trimAdoPrefix(config.orgId);}
this.elems[config.id].preDispatch();};this.slave=function(fnName,config){if(!fnName||typeof fnName!=="string"||fnName===""){return;}
if(!config||!config.myMaster){return;}
if(!config.id){config.id=fnName;}
config.slave=true;if((ado.mode=="new"&&!ado.windowLoad&&this.isBrowserSupport())||ado.busy){ado.queue.unshift(function(){ado.slave(fnName,config);});return;}
if(typeof this.masterSlaves[config.myMaster]!=="object"){this.masterSlaves[config.myMaster]=[];}
this.masterSlaves[config.myMaster].push(fnName);if(!config.orgId){config=tuneId(config);}
this.elems[config.id]=new AdoElement(config);this.elems[config.id].getDOMElement();this.elems[config.id].emptyDOMElement();if(ado.mode==="old"||!this.isBrowserSupport()){document.write("<scr"+"ipt type='text/javascript'>if(typeof "+config.orgId+"=='function'){"+config.orgId+"();}</scr"+"ipt>");if(typeof config.onLoad==="function"){config.onLoad();config.onLoad=false;}}
else{this.slaveStart(config);}};this.slaveStart=function(config){eval(config.orgId);this.elems[config.id].buff="<scr"+"ipt type=\"text/javascript\">"+config.orgId+"();</scr"+"ipt>";this.elems[config.id].begin=false;this.elems[config.id].initBuffor();this.elems[config.id].dispatch();};this.preview=function(config){if(config.enabled===false){return;}
config.server=config.emiter;if(config.preview!==true){config.url=ado.protocol+"//"+config.server+'/_'+(new Date()).getTime()+'/ad.js?id='+config.id;}
if(!config.orgId){config=tuneId(config);}
if(ado.mode=='new'&&!ado.windowLoad&&ado.isBrowserSupport()){ado.queue.unshift(function(){ado.preview(config);});return}
if(ado.mode=="old"){document.write('<sc'+'ript src="'+config.url+'"></scr'+'ipt>');}
else{this.elems[config.id]=new AdoElement(config);this.elems[config.id].preDispatch();}};this.turnOnPreview=function(){for(var i in ado.tmp){if(typeof ado.previewEnabled[ado.tmp[i]]!=='function'){ado.previewEnabled[ado.tmp[i]]=true;}}
ado.tmp=[];};this.turnOffPreview=function(){for(var i in ado.previewEnabled){if(typeof ado.previewEnabled[i]!=="function"){if(ado.previewEnabled[i]){ado.tmp.push(i);}
ado.previewEnabled[i]=false;}}};this.getByTag=function(n,i){if(!i){i=0;}
var objs=ado.getAllByTag(n);return objs[i];};this.getAllByTag=function(n){var objs=[];if(document.all){objs=document.all.tags(n);}
else if(document.getElementsByTagName){objs=document.getElementsByTagName(n);}
else if(document.layers){objs=document.layers[n];}
return objs;};this.bind=function(elem,eventName,fn){if(elem.addEventListener){elem.addEventListener(eventName,fn,false);}
else if(elem.attachEvent){elem.attachEvent("on"+eventName,fn);}
else if(document.getElementById){}};this.isBrowserSupport=function(){return(document.createElement&&document.appendChild&&document.getElementById)?true:false;};this.evaluate=function(code){if(window.execScript){window.execScript(code);return null;}
var result=globalScope.eval?globalScope.eval(code):eval(code);return result;};this.loadScript=function(url,callback,charset){var done=false;var script=document.createElement('script');var indexOf=url.indexOf("javascript:");if(url.indexOf("javascript:")!==-1){var fn=url.substr(indexOf);ado.evaluate(fn);callback(this);return;}
script.src=url;if(typeof charset!=="undefined"&&charset!==null){script.charset=charset;}
script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;callback(this);}};if(ado.browser.msie&&ado.loadingPreviewSettings){ado.onDOMReady(function(){ado.head.appendChild(script);});}
else{ado.head.appendChild(script);}};this.makeKeywords=function(keys){var addNuggaddKey=function(keys){if(typeof na_prof==='string'){if(keys===''){keys='/key=';}
else{keys+=',';}
keys+=na_prof;}
return keys;}
if(typeof keys==='string'){keys=keys.split(',');}
var k='';if(typeof keys==='object'&&keys.length>0){for(var key in keys){if(typeof keys[key]==="string"){if(ado.characterEncoding){k+=","+keywordEncode(keys[key].toLowerCase());}
else{k+=","+keys[key].toLowerCase();}}}
k="/key="+k.slice(1);}
k=addNuggaddKey(k);return k;};this.makeVars=function(vars){var v='';if(typeof vars==='object'){for(var key in vars){if(typeof vars[key]==="string"||typeof vars[key]==='number'){v+="/"+key+"="+vars[key];}}}
else if(typeof vars==='string'){if(vars.charAt(0)!=="&"){vars="&"+vars;}
if(vars.charAt(vars.length-1)==="&"){vars=vars.substr(0,vars.length-1);}
vars=vars.replace("&","/");while(vars.indexOf('&')!==-1){vars=vars.replace("&","/");}
v=vars;}
return v;};this.makeFlash=function(){var fv='-';var fo=null;eval('try { f=(d==top.document)?1:2; if (typeof top.document.referrer=="string") { ref=top.document.referrer } } catch(e) {f=3;}');eval('try { fv=navigator.plugins["Shockwave Flash"].description; } catch (e) {}');eval('if (typeof ActiveXObject!="undefined") { try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); } catch(e) { try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); fv="X"; fo.AllowScriptAccess="always"; } catch(e) { if (fv=="X") { fv="WIN 6,0,20,0"; }} try { fo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); } catch(e) {} } if ((fv=="-" || fv=="X") && fo) { fv=fo.GetVariable("$version"); }}');return'/fv='+escape(fv);};this.getById=function(id){return document.getElementById(id);};this.onDOMReady=function(readyFn){var countStyleSheets=function(){var style=ado.getAllByTag('style');var links=ado.getAllByTag('link');var j=0;for(var i in links){if(links[i].rel==="stylesheet"){j++;}}
return style.length+j;};function bindReady(){if(document.addEventListener&&!ado.browser.opera){document.addEventListener("DOMContentLoaded",readyFn,false);ado.windowLoad=true;return;}
else if(ado.browser.msie&&window==top){(function(){if(ado.windowLoad){return;}
try{document.documentElement.doScroll("left");}catch(error){setTimeout(arguments.callee,1);return;}
readyFn();ado.windowLoad=true;return;})();}
else if(ado.browser.opera){document.addEventListener("DOMContentLoaded",function(){if(ado.windowLoad){return;}
for(var i=0;i<document.styleSheets.length;i++){if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return;}}
readyFn();ado.windowLoad=true;return;},false);}
else if(ado.browser.safari){var numStyles;(function(){if(ado.windowLoad){return;}
if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return;}
if(numStyles===undefined){numStyles=countStyleSheets();}
if(document.styleSheets.length!=numStyles){setTimeout(arguments.callee,0);return;}
readyFn();ado.windowLoad=true;return;})();}
else{window.onload=readyFn;ado.windowLoad=true;return;}}
bindReady();};this.closeLivePreview=function(){window.location=ado.previewDisableUrl+"?url="+encodeURIComponent(encodeURIComponent(window.location.href));};this.start=function(){if(ado.queue.length>0){var fn=ado.queue.pop();if(typeof fn==="function"){fn();}}}};if(typeof ado==="undefined"){ado=new AdoContainer();if(typeof ado.head==="undefined"){ado.head=ado.getByTag("head",0);}
var go=function(){ado.windowLoad=true;ado.start();}
if(window.addEventListener){window.addEventListener("load",go,true);}
else if(window.attachEvent){window.attachEvent("onload",go);}
else if(document.getElementById){window.onload=go;}}
var globalScope=this;
