// Copyright (c) Admeta AB 2008-2010
// Version 1.26

var Admeta;
if (!Admeta) Admeta={};

Admeta.version="1.26";
Admeta.textVersion="2.6";
if(!Admeta.base) Admeta.base="http://atemda.com/";
if(!Admeta.textAdsJS) Admeta.textAdsJS="http://s.atemda.com/script/TextAds.js?{sv}";
Admeta.singleImpression="JSAdservingSP.ashx?wId={wId}&pId={pId}&rank={rank}&gid={gid}&clk={clk}&di=1&exm={exm}&jsv={jsv}&tsv={tsv}&cb={cb}";
Admeta.singleImpressionNamed="JSAdservingSP.ashx?pbId={pbId}&wsName={wsName}&wName={wName}&rank={rank}&bfDim={width}x{height}&clk={clk}&di=1&exm={exm}&jsv={jsv}&tsv={tsv}&cb={cb}";
Admeta.pageImpression="JSAdservingMP.ashx?pc={pc}&pbId={pbId}&clk={clk}&exm={exm}&jsv={jsv}&tsv={tsv}&cb={cb}&arp={arp}";
Admeta.pageRepeatParam="&pId{o}={pId}&rank{o}={rank}&gid{o}={gid}";
Admeta.pageRepeatParamNamed="&wsName{o}={wsName}&wName{o}={wName}&rank{o}={rank}&bfDim{o}={width}x{height}&gid{o}={gid}";
if(!Admeta.focus) Admeta.focus=1;

Admeta.init = function (vtUrl)
{
    if(Admeta.initialized) return;

	Admeta.SIV.init(vtUrl);
	
	if (window.addEventListener) {
		window.addEventListener("focus",Admeta.onFocus,false);
		window.addEventListener("blur",Admeta.onBlur,false);
	}
	else if (window.attachEvent) {
		window.attachEvent("onfocus",Admeta.onFocus);
		window.attachEvent("onblur",Admeta.onBlur);
	}

    Admeta.initialized=true;
};

Admeta.onFocus = function()
{
	Admeta.focus=1;
}

Admeta.onBlur = function()
{
	Admeta.focus=0;
}

if (!Admeta.MatC) Admeta.MatC = {
	pList: [],
	setup: function (pid,o,adId,gid,mt,SIV,RF,eff,w,h)
	{
		return pInfo=this.addPlacementInfo(pid,o,adId,gid,mt,SIV,RF,eff,w,h);
	},
	addPlacementInfo: function (pid,o,adId,gid,mt,SIV,RF,eff,w,h)
	{
		var pInfo=this.getExisting(gid);
		if(pInfo)
		{
			pInfo.adId=adId;
			pInfo.mt=mt;
			pInfo.SIV=SIV;
			if(RF!==undefined) pInfo.RF=RF;
			if(eff!=undefined) pInfo.eff=eff;
			pInfo.w=w;
			pInfo.h=h;
		}
		else
		{
			pInfo=this.Placement(pid,o,adId,gid,mt,SIV,RF,eff,w,h);
			this.pList[this.pList.length]=pInfo;
		}
		return pInfo;
	},
	getExisting: function(gid)
	{
		for (var i=0;i<Admeta.MatC.pList.length;i++) {
			var pInfo=Admeta.MatC.pList[i];
			if(pInfo.gid==gid) return pInfo;
		}
		return undefined;
	},
	generateId: function ()
	{
		return (((1+Math.random())*0x1000000)|0).toString(16).substring(1);
	},
	setInnerIds: function(mat)
	{
		var gid=mat.gid;
		mat.innerId=(gid!==undefined&&gid.length>2&&gid.substr(0,2)=="AM"?gid:"AM"+mat.pid+"_"+mat.o+"_"+this.generateId())+"_SIV";
		mat.innermostId=mat.innerId+"_im";
	},
	Placement: function (pid,o,adId,gid,mt,SIV,RF,eff,w,h)
	{
		var mat={pid:pid,o:o,gid:gid,adId:adId,mt:mt,elemVisible:false,innerId:gid,innermostId:gid,SIV:SIV,RF:RF,active:0,eff:eff,w:w,h:h,arp:0};
		return mat;
	},
	checkElemVisible: function (id)
	{
		var isOpera=navigator.userAgent.indexOf('Opera')!=-1;
		var isStandard=document.compatMode=='CSS1Compat';
		var vpH=isOpera?self.innerHeight:isStandard?document.documentElement.clientHeight:document.body.clientHeight;
		var top=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
		var vpW=isOpera?self.innerWidth:isStandard?document.documentElement.clientWidth:document.body.clientWidth;
		var left=document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;
		var el=document.getElementById(id);

		var pos=Admeta.MatC.getPos(el);
		var width=el.offsetWidth;
		var height=el.offsetHeight;

		if (pos[1]+width>vpW+left) width-=pos[1]+width-vpW-left;
		if (pos[1]<left) width-=left-pos[1];
		if (pos[0]+height> vpH+top) height-=pos[0]+height-vpH-top;
		if (pos[0]<top) height-=top-pos[0];

		if(width<0 ) width=0; if( height<0 ) height=0;
		var coverage=(width*height)/(el.offsetWidth*el.offsetHeight);

		return coverage>0.8;
	},
	stopMeasure: function(o)
	{
		if(!o.offsetParent) return true;
		if(o.currentStyle&&o.currentStyle=="relative") return true;
		if(window.getComputedStyle&&document.defaultView.getComputedStyle(o,null).getPropertyValue("position")=="relative") return true;
		return false;
	},
	getPos: function (o)
	{
		var curtop=0;
		var curleft=0;

		if (o.offsetParent) {
			do {
				if(Admeta.MatC.stopMeasure(o)) break;
				curtop+=o.offsetTop;
				curleft+=o.offsetLeft;
			} while (o=o.offsetParent);
		}
		return [curtop,curleft];
	}

};

if (!Admeta.SIV) Admeta.SIV = {
    eventHandlersInitialized: false,
	busy: false,
	evInit: false,
	init: function(vtUrl)
	{
		Admeta.SIV.vtUrl=vtUrl;
	},
	setupEventHandlers: function ()
	{
		if (this.eventHandlersInitialized) return;

		this.eventHandlersInitialized=true;
		
		Admeta.SIV.parentOnLoad=(window.onload)?window.onload:function () {};
		Admeta.SIV.parentOnScroll=(window.onscroll)?window.onscroll:function () {};
		Admeta.SIV.parentOnResize=(window.onresize)?window.onresize:function () {};

		if (window.addEventListener) {
			window.addEventListener("load",this.evHandler,false);
			window.addEventListener("scroll",this.evHandler,false);
			window.addEventListener("resize",this.evHandler,false);
		}
		else if (window.attachEvent) {
			document.attachEvent("onreadystatechange",function(){
				if (document.readyState=="complete") {
					document.detachEvent( "onreadystatechange",arguments.callee );

					Admeta.SIV.evInit=true;
					Admeta.SIV.evHandler();
				}
			});

			if (document.documentElement.doScroll && typeof window.frameElement==="undefined" ) (function(){
				if (Admeta.SIV.evInit) return;

				try {
					document.documentElement.doScroll("left");
				} catch (error) {
					setTimeout (arguments.callee,0);
					return;
				}

				Admeta.SIV.evInit=true;
				Admeta.SIV.evHandler();
			})();

			window.attachEvent("onscroll",Admeta.SIV.evHandler);
			window.attachEvent("onresize",Admeta.SIV.evHandler);
		}
		else
		{
			window.onload = function () {
				Admeta.SIV.parentOnLoad();
				Admeta.SIV.evHandler();
			};

			window.onscroll = function () {
				Admeta.SIV.parentOnScroll();
				Admeta.SIV.evHandler();
			};

			window.onresize = function () {
				Admeta.SIV.parentOnResize();
				Admeta.SIV.evHandler();
			};
		}
	},
	setup: function (mat)
	{
		if (mat&&mat.SIV) this.setupEventHandlers();
	},
	evHandler: function (ev)
	{
		if (Admeta.SIV.busy) return;
		Admeta.SIV.busy=true;
		var mc=Admeta.MatC;

		vList=[];

		for (var i=0;i<mc.pList.length;i++) {
			var mat=mc.pList[i];
			if (mat&&mat.SIV&&!mat.ElemVisible)
			{
				if (mc.checkElemVisible(mat.innerId))
				{
					mat.ElemVisible=true;
					vList[vList.length]=mat;
				}
			}
		}

		if (vList.length>0)
		{
			var matList="?mc="+vList.length+"&";
			var el;
			var m=0;

			for (var i=0;i<vList.length;i++)
			{
				var mat=vList[i];
				el=document.getElementById(mat.innerId);

                var ids = (""+mat.adId).split(",");
                
                for(var n=0;n<ids.length;n++)
				    matList+="pId"+i+"="+mat.pid+"&mId"+i+"="+ids[n]+"&";
			}

			img=document.createElement("img");
			img.setAttribute("id","AmImg"+vList[0].adId );
			img.setAttribute("width","1px" );
			img.setAttribute("height","1px" );
			el.rows[0].cells[0].appendChild(img);
			img.setAttribute("src",Admeta.SIV.vtUrl+matList+"rnd="+new Date().getTime() );
		}

		Admeta.SIV.busy=false;
	}
};


if (!Admeta.Text) Admeta.Text = {
    AdGroup: [],
	init: function ()
	{
	    this.AdGroup.push({initArgs:arguments,Ads:[],xRenderF:undefined});
	},
	create: function ()
	{
		this.AdGroup[this.AdGroup.length-1].Ads.push(arguments);
	},
	insert: function ()
	{
		this.process(0,arguments);
	},
	write: function ()
	{
		this.process(1,arguments);
	},
	process: function(op,args)
	{
		var p=this.AdGroup.length-1;
		this.AdGroup[p].Operation=op;
		this.AdGroup[p].placementDetails=args;
		this.AdGroup[p].xRenderF=Admeta.Text.getRenderer(op,args.length>=5?args[4]:undefined,args[0]);
		
		if (Admeta.Text.ProcessTextAds===undefined) {
		    if(!Admeta.Text.ScriptLoading) {
		        Admeta.Text.ScriptLoading=true;
			    Admeta.Script.load(Admeta.versionFile(Admeta.textAdsJS,Admeta.textVersion),Admeta.defLoad,undefined,0);
			}
	    }
		else
			Admeta.Text.ProcessTextAds();
	},
	getRenderer: function(op,gid,pid)
	{
		var xf=Admeta.xRenderF;
		if(!xf) return xf;
		var rf=xf[pid];
		xf[pid]=undefined;
		if(gid&&xf[gid]) return xf[gid];
		return rf;
	}
};

Admeta.Flash = {
	get: function (mUrl,w,h,gf,ct,urldct)
	{
		var bannerContent="";

		var cv=5;
		var plugin=(navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'])?
		                                     navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin:0;
		var MM_FlashCanPlay=false;

		if (plugin)
		{
			var words=navigator.plugins['Shockwave Flash'].description.split(" ");
			var MM_PluginVersion=0;

			for (i=0;i<words.length;++i)
			{
				if (isNaN(parseInt(words[i])))
					continue;
				MM_PluginVersion=words[i];
			}
			MM_FlashCanPlay=MM_PluginVersion >= cv;
		}
		else if (navigator.userAgent && navigator.userAgent.indexOf('MSIE')>=0 && (navigator.appVersion.indexOf('Win')!=-1))
		{
			var flashVersion=0;
			for (i=10;i>0;i--)
			{
				try
				{
					var flash=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+i);
					flashVersion=i;
					break;
				}
				catch(e)
				{}
			}
			if (flashVersion>0 )
				MM_FlashCanPlay=true;
		}
		if (MM_FlashCanPlay)
		{

			bannerContent='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="vfmov" width="'+w+'" height="'+h+'" align="middle">\n';
			bannerContent+='   <param name="allowScriptAccess" value="always">\n';
			bannerContent+='   <param name="movie" value="'+mUrl+'?'+ct+'='+urldct+'">\n';
			bannerContent+='   <param name="quality" value="high">\n';
			bannerContent+='   <param name="wmode" value="opaque">\n';
			bannerContent+='   <embed src="'+mUrl+'?'+ct+'='+urldct+'" width="'+w+'" height="'+h+'" quality=high name="vfmov" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque" outline="none"></embed>\n';
			bannerContent+='</object>';
		}
		else
		{
			bannerContent='<a href="'+unescape(urldct)+'" target="_blank"><img src="'+gf+'" width="'+w+'" height="'+h+'" border="0"></a>';
		}

		return bannerContent;
	},
	insert: function (pid,o,adId,mUrl,w,h,gf,ct,urldct,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,1,w,h);
		
		var bannerContent=this.get(mUrl,w,h,gf,ct,urldct);

		Admeta.insertMaterial(pid,o,gid,mat,w,h,bannerContent,1);
	},
	write: function (pid,o,adId,mUrl,w,h,gf,ct,urldct,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,1,w,h);

		Admeta.writeMaterial(pid,gid,mat,w,h,this.get(mUrl,w,h,gf,ct,urldct),1);
	}
};

Admeta.Image = {
	get: function (mUrl,w,h,urldct,pid,o)
	{
		return '<a href="'+urldct+'" target="_blank"><img id="AM'+pid+"_"+o+'" src="'+mUrl+'" width="'+w+'" height="'+h+'" border="0"></a>';
	},
	insert: function (pid,o,adId,mUrl,w,h,urldct,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,0,w,h);

		Admeta.insertMaterial(pid,o,gid,mat,w,h,this.get(mUrl,w,h,urldct,pid,o),0);
	},
	write: function (pid,o,adId,mUrl,w,h,urldct,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,0,w,h);

		Admeta.writeMaterial(pid,gid,mat,w,h,this.get(mUrl,w,h,urldct,pid,o),0);
	}
};

Admeta.JS = {
	getIframe: function (w,h,id)
	{
		return '<iframe id="'+id+'" scrolling="no" frameborder="0" hidefocus="true" style="border-style:none;margin:0px;width:'+w+'px;height:'+h+'px"></iframe>';
	},
	generateIfrId: function (pid,o,adId)
	{
		return "AMIfr_"+pid+"_"+o+"_"+adId;
	},
	updateIfrSrc: function (id,ifrUrl,adId)
	{
		document.getElementById(id).src=ifrUrl;
	},
	insert: function (pid,o,adId,ifrUrl,w,h,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,3,w,h);

		var ifrId=this.generateIfrId(pid,o,adId);

		Admeta.insertMaterial(pid,o,gid,mat,w,h,this.getIframe(w,h,ifrId),3);

		this.updateIfrSrc(ifrId,ifrUrl);
	},
	write: function (pid,o,adId,ifrUrl,w,h,SIV,gid,RF,eff)
	{
		mat = Admeta.setupMaterial(pid,o,adId,gid,SIV,RF,eff,3,w,h);

		var ifrId=this.generateIfrId(pid,o,adId);

		Admeta.writeMaterial(pid,gid,mat,w,h,this.getIframe(w,h,ifrId),3);

		this.updateIfrSrc(ifrId,ifrUrl);
	},
    replaceStr: function(str,fnd,rep)
    {
        while( str.indexOf(fnd) != -1 )
            str = str.replace(fnd,rep);
        
        return str;
    },
	prepareCode: function(code,ct)
	{
		code = unescape(code);
		code = this.replaceStr(code,"{clickthrough0}",unescape(ct));
		code = this.replaceStr(code,"{clickthrough1}",ct);
		code = this.replaceStr(code,"{clickthrough2}",escape(ct));
		code = this.replaceStr(code,"{clickthrough}",unescape(ct));
		return this.replaceStr(code,"{random}",Math.floor(Math.random()*10001));
	},
	insertC: function (pid,o,adId,url,code,ct,w,h,SIV,gid)
	{
		this.insert(pid,o,adId,url,w,h,SIV,gid);
	},
	writeC: function (pid,o,adId,url,code,ct,w,h,SIV,gid)
	{
		Admeta.storeMaterial(adId);

		document.write(this.prepareCode(code,ct));
	}
};

Admeta.Refresh = {
	setup: function (pInfo)
	{
		if(!pInfo) return;	
		if (pInfo.RF&&pInfo.RF>0) this.setupTimer(pInfo);
		return pInfo;
	},
	active: function(gid,active,id)
	{
		var pInfo=Admeta.MatC.getExisting(gid);
		if(!pInfo) return;
		pInfo.active=active;
	},
	attachEv: function(el,gid)
	{
		el.onmouseover=function(){Admeta.Refresh.active(gid,1,el.id);};
		el.onmouseout=function(){Admeta.Refresh.active(gid,0,el.id);};
	},
	setupTimer: function(pInfo)
	{
		var a="Admeta.Refresh.tmHandler('"+pInfo.gid+"')";
		setTimeout(a,pInfo.RF*1000);
	},
	attMaterial: function(pInfo)
	{
		this.attachEv(document.getElementById(pInfo.innerId),pInfo.gid);
		pInfo.arp++;
	},
	tmHandler: function(gid)
	{
		var pInfo=Admeta.MatC.getExisting(gid);
		if (Admeta.focus&&!pInfo.active&&Admeta.MatC.checkElemVisible(pInfo.innermostId))
		{
			var fc=Admeta.base+Admeta.pageImpression;
			fc=Admeta.setParam(fc,"pc",1);
			fc=Admeta.setParam(fc,"arp",pInfo.arp);
			fc=Admeta.setCommonParams(fc);

			var item=Admeta.setParam(Admeta.pageRepeatParam,"o",0);
			item=Admeta.setParam(item,"pId",pInfo.pid);
			item=Admeta.setParam(item,"rank",pInfo.o);
			fc+=Admeta.setParam(item,"gid",gid);
			
			Admeta.Script.load(fc,true,pInfo.innermostId+"_scr",1);
		}
		else
			Admeta.Refresh.setupTimer(pInfo);
	}
};

if(!Admeta.Script) Admeta.Script = {
	scriptList:[],
	executing:0,
	loaded: function()
	{
		Admeta.Script.executing--;
		if(Admeta.Script.executing==0&&Admeta.Script.scriptList.length>0)
		{
			var scr=Admeta.Script.scriptList.pop();
			Admeta.Script.load(scr.url,true,scr.id,1);
		}
	},
	load: function(url,def,id,q)
	{
		if(q&&def&&Admeta.Script.executing>0)
		{
			Admeta.Script.scriptList.push({url:url,id:id});
			return;
		}
		try {
			if(q) Admeta.Script.executing++;
			url=Admeta.setParam(url,"exm",Admeta.adsServed!==undefined?Admeta.adsServed.join(","):"");
			if(def)
			{
				var head=document.getElementsByTagName("head")[0];
				if(id)
				{
					var src=document.getElementById(id);
					if(src) head.removeChild(src);
				}
				scr=document.createElement('script');
				scr.type = 'text/javascript';
				if(id) scr.id=id;
				scr.src=url;
				head.appendChild(scr);
			}
			else
			{
				document.write("<"+"script"+" charset='utf-8' type='text/javascript' src='"+url+"'></"+"script"+">");
			}
		} catch(e) {
			if(q) Admeta.Script.executing--;
		}
	}
};

Admeta.embedMaterial = function (mat,w,h,bannerContent)
{
	if(mat&&(mat.RF||mat.SIV)&&mat.innerId==mat.innermostId)
		Admeta.MatC.setInnerIds(mat);
		
	var displayType=navigator.userAgent.toLowerCase().indexOf('msie')!=-1?"inline":"inline-table";

	return mat==null||(!mat.RF&&!mat.SIV)||document.getElementById(mat.innerId)!=null?bannerContent:
		'<table id="'+mat.innerId+'" style="border-collapse:collapse;display:'+displayType+';" border="0" cellspacing="0" cellpadding="0" width="'+w+'px" height="'+h+'px">'+
		'<tr><td id="'+mat.innermostId+'">'+
		bannerContent+
		'</td></tr></table>';
};

Admeta.getContainer = function (pid,o,gid,mat)
{
	if(!mat) mat=Admeta.MatC.getExisting(gid);
	if (mat)
	{
		var elem=document.getElementById(mat.innermostId);
		if (elem) return elem;
	}
	if (gid!==undefined)
	{
		var elem=document.getElementById(gid);
		if (elem) return elem;
	}
	return document.getElementById('Admeta'+pid+'_'+o);
};

Admeta.insertMaterial = function(pid,o,gid,mat,w,h,html,mt)
{
	var c=Admeta.getContainer(pid,o,gid,mat);
	c.innerHTML=Admeta.embedMaterial(mat,w,h,html);
	Admeta.postP(mat);
}

Admeta.writeMaterial = function(pid,gid,mat,w,h,html,mt)
{
	document.write(Admeta.embedMaterial(mat,w,h,html));
	Admeta.postP(mat);
}

Admeta.postP = function(pInfo)
{
	if(pInfo&&pInfo.RF)
		Admeta.Refresh.attMaterial(pInfo);
}

Admeta.storeMaterial = function (mId)
{
	if (Admeta.adsServed===undefined)
		Admeta.adsServed=[];

    var ids = (""+mId).split(",");
    
    for(var n=0;n<ids.length;n++)
    	Admeta.adsServed.push(ids[n]);
};

Admeta.setupMaterial = function(pid,o,adId,gid,SIV,RF,eff,mt,w,h)
{
	Admeta.storeMaterial(adId);
	mat=Admeta.MatC.setup(pid,o,adId,gid,mt,SIV,RF,eff,w,h)
	Admeta.SIV.setup(mat);
	Admeta.Refresh.setup(mat);
	return mat;
}

Admeta.setParam = function (str,param,value)
{
	var pattern=new RegExp("{"+param+"}","g");
	return str.replace(pattern,value);
};

Admeta.versionFile = function(f,v)
{
	return Admeta.setParam(f,"sv",v);
}

Admeta.callUserScript = function(scr, directInsert) {
    var di = directInsert===undefined?0:directInsert;
    if (document.body&&!di) 
    {
        var div = document.createElement('div');
        div.innerHTML = scr;
        document.body.appendChild(div);
    }
    else
        document.write(scr);
};

if (!Admeta.noAdAvailable) Admeta.noAdAvailable = function() {}

if (!Admeta.unsold) Admeta.unsold = function(gid,content,di,ifrId,url)
{
	var pInfo=Admeta.MatC.getExisting(gid);

	if(di)
		document.write(content);
	else
		document.getElementById(pInfo.innermostId).innerHTML=content;
		
	document.getElementById(ifrId).src=url;
}

Admeta.encodeClickTag = function(clk)
{
    return (clk.indexOf("&")!=-1 || clk.indexOf("?")!=-1)?escape(clk):clk;
};

Admeta.getOverrides = function ()
{
	Admeta.Text.forceSize=ADM_PL.textSize;
	Admeta.Text.forceCenterImg=ADM_PL.centerImages;
	Admeta.Text.forceBaseFontSize=ADM_PL.fontSize;
	Admeta.Text.forceBaseFont=ADM_PL.font;
	ADM_PL.TextSize=undefined;
	ADM_PL.CenterImages=undefined;
	ADM_PL.fontSize=undefined;
	ADM_PL.font=undefined;
}

Admeta.setCommonParams = function(frontCall)
{
	frontCall=Admeta.setParam(frontCall,"clk",ADM_PL!==undefined&&ADM_PL.clk!==undefined?Admeta.encodeClickTag(ADM_PL.clk):escape("[]"));
	frontCall=Admeta.setParam(frontCall,"arp",0);
	frontCall=Admeta.setParam(frontCall,"jsv",Admeta.version);
	frontCall=Admeta.setParam(frontCall,"tsv",Admeta.textVersion);
	frontCall=Admeta.setParam(frontCall,"cb",new Date().getTime());
	
	return frontCall;
}

Admeta.storeRenderF = function(gid)
{
	if (Admeta.xRenderF===undefined) Admeta.xRenderF={};
	if (ADM_PL.renderF!==undefined||ADM_PL.ADM_RENDERF!==undefined) {
		var rf=ADM_PL.renderF!==undefined?ADM_PL.renderF:ADM_PL.ADM_RENDERF;
		Admeta.xRenderF[gid]=rf;
		Admeta.xRenderF[ADM_PL.pId]=rf;
	}
}

Admeta.getGid = function()
{
	return (ADM_PL.pId===undefined?ADM_PL.Page+ADM_PL.Width+ADM_PL.Height:ADM_PL.pId)+':'+(ADM_PL.rank===undefined?1:ADM_PL.rank)+':'+(((1+Math.random())*0x1000000)|0).toString(16).substring(1);
}

Admeta.callSingleImpression = function ()
{
	var gid=Admeta.getGid();
	Admeta.defLoad=ADM_PL.defLoad;
	Admeta.MatC.setup(ADM_PL.pId,ADM_PL.rank,-1,gid,-1,undefined,ADM_PL.refresh,(ADM_PL.fade?1:0)|(ADM_PL.attRefreshed?2:0),ADM_PL.width,ADM_PL.height);
	Admeta.storeRenderF(gid);

	var frontCall=Admeta.base;
	
	Admeta.getOverrides();

	if (ADM_PL.wId!==undefined) {
		frontCall+=Admeta.singleImpression;
		frontCall=Admeta.setParam(frontCall,"wId",ADM_PL.wId);
		frontCall=Admeta.setParam(frontCall,"pId",ADM_PL.pId);
		frontCall=Admeta.setParam(frontCall,"gid",gid);
		frontCall=Admeta.setParam(frontCall,"rank",ADM_PL.rank);
	}
	else if(ADM_PL.pbId!==undefined&&ADM_PL.Site!==undefined&&ADM_PL.Page!==undefined&&ADM_PL.Width!==undefined&&ADM_PL.Height!==undefined) {
		frontCall+=Admeta.singleImpressionNamed;
		frontCall=Admeta.setParam(frontCall,"pbId",ADM_PL.pbId);
		frontCall=Admeta.setParam(frontCall,"gid",gid);
		frontCall=Admeta.setParam(frontCall,"wsName",ADM_PL.Site);
		frontCall=Admeta.setParam(frontCall,"wName",ADM_PL.Page);
		frontCall=Admeta.setParam(frontCall,"rank",ADM_PL.rank===undefined?1:ADM_PL.rank);
		frontCall=Admeta.setParam(frontCall,"width",ADM_PL.Width);
		frontCall=Admeta.setParam(frontCall,"height",ADM_PL.Height);
	}
	else
		return;
		
	frontCall=Admeta.setCommonParams(frontCall);
	
	ADM_PL.wId=undefined;
	ADM_PL.wsName=undefined;
	ADM_PL.defLoad=undefined;

	Admeta.Script.load(frontCall,Admeta.defLoad,undefined,1);
};

Admeta.pushPlacement = function ()
{
	var gid=Admeta.getGid();

	document.write('<di'+'v id="'+gid+'"></di'+'v>');

	var pInfo=Admeta.MatC.setup(ADM_PL.pId,ADM_PL.rank,-1,gid,-1,undefined,ADM_PL.refresh,(ADM_PL.fade?1:0)|(ADM_PL.attRefreshed?2:0),ADM_PL.width,ADM_PL.height);
	Admeta.storeRenderF(gid,ADM_PL.pId);

	if (Admeta.pushedAds===undefined) Admeta.pushedAds=[];

	Admeta.pushedAds.push({wId:ADM_PL.wId,pid:ADM_PL.pId,rank:ADM_PL.rank===undefined?1:ADM_PL.rank,gid:gid,wsName:ADM_PL.Site,wpName:ADM_PL.Page,width:ADM_PL.Width,height:ADM_PL.Height,pbId:ADM_PL.pbId});

	ADM_PL.wId=undefined;
	ADM_PL.wsName=undefined;
};

Admeta.processFullPage = function (clickTrack)
{
	var pas=Admeta.pushedAds;
	if(pas===undefined||pas.length==0) return;

	var up=[];

	for (i=0;i<pas.length;i++)
		if(document.getElementById(pas[i].gid)) up.push(i);

	Admeta.getOverrides();

	if(up.length>0)
	{
		var frontCall=Admeta.base+Admeta.pageImpression;
		frontCall=Admeta.setParam(frontCall,"pc",up.length);
		frontCall=Admeta.setCommonParams(frontCall);

		for (i=0;i<up.length;i++)
		{
			var pa = pas[up[i]];
			if (pa.wId!==undefined)
			{
				var item=Admeta.setParam(Admeta.pageRepeatParam,"o",i);
				item=Admeta.setParam(item,"pId",pa.pid);
				item=Admeta.setParam(item,"rank",pa.rank);
				frontCall+=Admeta.setParam(item,"gid",pa.gid);
			}
			else if (pa.pbId!==undefined&&pa.wsName!==undefined&&pa.wpName!==undefined&&pa.width!==undefined&&pa.height!==undefined)
			{
				frontCall=Admeta.setParam(frontCall,"pbId",pa.pbId);
				var item=Admeta.setParam(Admeta.pageRepeatParamNamed,"o",i);
				item=Admeta.setParam(item,"wsName",pa.wsName);
				item=Admeta.setParam(item,"wName",pa.wpName);
				item=Admeta.setParam(item,"width",pa.width);
				item=Admeta.setParam(item,"height",pa.height);
				item=Admeta.setParam(item,"rank",pa.rank);
				frontCall+=Admeta.setParam(item,"gid",pa.gid);
			}
		}

		Admeta.Script.load(frontCall,ADM_PL.defLoad,undefined,1);
		
		Admeta.pushedAds=[];
	}
};

Admeta.handleClientInvoke = function ()
{
    switch (ADM_PL.tp)
    {
        case "sp" :
    		Admeta.callSingleImpression();
    		break;
        case "fp" :
    		Admeta.pushPlacement();
    		break;
        case "fpc" :
		    Admeta.processFullPage();
    		break;
    }

	ADM_PL=undefined;
};

Admeta.processImpressions = function()
{
	if (Admeta.loadList)
	{
		l=Admeta.loadList.length;
		for (i=0;i<l;i++) Admeta.loadList.pop()();
		Admeta.loadList=[];
	}
	else
	if (Admeta.ll)
	{
		l=Admeta.ll.length;
		for (i=0;i<l;i++) Admeta.ll.pop()();
		Admeta.ll=[];
	}
	else
	if (typeof(ADM_PL)!="undefined")
		Admeta.handleClientInvoke();
};

Admeta.processImpressions();
