//this script use [img] variable from display.js

var adArrImgs = new Array();
var adIdx=-1, iLoaded=0;
var adImg=null;
var wCount=10, aCount3r=0;

function AdImage(src, el, w, h, l){
	this.imgSource=new String(src).replace(/ /g,"%20");
	this.element=el;
	this.width=w;
	this.height=h;
	this.fullLink=l; /*full <a> tag*/
}

function addAdImages(imgSrc, el, w, h, l){
	var i = new AdImage(siteNam3+imgSrc, el, w, h, l);
	adArrImgs.push(i);
	i=null;
}

function showAdImages(){
	acount3r=0;
	if((iLoaded==1 || (adIdx==-1 && iLoaded==0))&& adIdx<adArrImgs.length-1 ){
		adIdx++;
		adImg = new Image();
		//alert(adArrImgs[adIdx].imgSource);
		adImg.src=adArrImgs[adIdx].imgSource;
		iLoaded=0;		
		waitAdLoaded();
	}
}

function waitAdLoaded(){
	if(adImg.complete || aCount3r==wCount){		
		var el=document.getElementById(adArrImgs[adIdx].element);
		if(el) {
			//alert(adArrImgs[adIdx].fullLink);
			el.innerHTML=(adArrImgs[adIdx].fullLink!=""?adArrImgs[adIdx].fullLink:"")
						+"<img src='"+adImg.src+"' width='"+adArrImgs[adIdx].width+"' height='"+adArrImgs[adIdx].height+"' border='0' />"
						+(adArrImgs[adIdx].fullLink!=""?"</a>":"");	
		}
		iLoaded=1;
		showAdImages();		
	}else{
		//window.status="Wait loading:"+adArrImgs[adIdx].imgSource+"::"+adImg.complete+"::"+adIdx;
		setTimeout("waitAdLoaded();",10);
		aCount3r++;
	}
}