/*
 +---------------------------------------------------------+
 | Ad Simple                 Copyright www.cmatus.com   |
 +---------------------------------------------------------+
 | This program may be used and hosted free of charge by   |
 |anyone for personal purpose as long as this copyright    |
 |notice remains intact.                                   |
 +---------------------------------------------------------+
*/

var img_title = "Click Here";

var ad=new Array();
//The images array
ad[0] = new Image(120,41);
ad[0].src='/images/Banners2/El Fantasma de Elena.jpg';
ad[1] = new Image(120,41);
ad[1].src='/images/Banners2/India.jpg';




var links=new Array()
//The links array;
links[0]='http://www.canal2.com.ni/Programas/El_Fantasma_de_Elena.html';
links[1]='http://www.canal2.com.ni/Programas/India.html';

//La posicion 23 es el banner '13.jpg' que es de Alertas SMS y no tiene pagina;



var wdth = new Array()
wdth[0]=175;
wdth[1]=175;


var hght = new Array()
hght[0]=511;
hght[1]=511;


var st = new Array();
st[0]=7000;
st[1]=7000;


var porc=new Array();
var i=0;
//By default each banner is set to one time
for (i=0;i<ad.length;i++)
{
	porc[i]=1;
}

//Setting the times of times each banner will be played in the loop cicle
//porc[5]=2;

var n=0;
//Extracting the length of the loop cicle
for(i=0;i<porc.length;i++)
{
	n+=porc[i];
}

var images=new Array(n);
var nlinks=new Array(n);
var width=new Array(n); 
var height=new Array(n); 
var nst=new Array(n); 
var flag=0;
var j=0;
var k=0;
var prio=5;
//This loop does the magic
do{
	flag=0;
	for(i=0;i<ad.length;i++){
		//Picking a banner
		if(i<(ad.length/2)){
			do{
				//j = Math.floor(Math.random() * n);
				j = i;
			}while(images[j] != null);
		}else{
			//Speeding the pick 
			for(k=0;k<n;k++){
				if(images[k] == null){
					j=k;
					break;
				}
			}
		}
		if(porc[i]!=0){
			//document.write(i + " " + j + " " + cont + " " + porc[i]);
			//document.write("<br />");
			//Placing the banner picked into the images array
			images[j] = new Image(120,41);
			images[j].src=ad[i].src;
			nlinks[j]=links[i];
			width[j]=wdth[i];
			height[j]=hght[i];
			nst[j]=st[i];
			porc[i]-=1;
			if(porc[i]!=0){
					flag=1;
			}
			if(prio==i){
				prio=j;
			}
		}
	}
}while(flag!=0);

//Set a random initial banner
//contador = Math.floor(Math.random() * images.length);
//contador = prio;
contador = 0;

//Function to call the banner array
function alternar_banner(){
    window.document["banner"].src = images[contador].src;
    window.document.links[0].href = nlinks[contador];
    window.document["banner"].width = width[contador];
    window.document["banner"].height = height[contador];
    var sleep_time=nst[contador];
    contador ++;
    contador = contador % images.length;
    setTimeout("alternar_banner()",sleep_time);
} 


