function PubLnk(link, over, linkTxt)
{
	this.link = link;
	this.over = over;
	this.linkTxt = linkTxt;
}

function PubImgs(pre_imgs, imgs)
{
	this.pre_imgs = pre_imgs;
	this.imgs = imgs;
}

function PubCollection(publnk, pubimgdt, weights)
{
	this.lnk = publnk;
	this.imgdt = pubimgdt;
	this.weights = weights;
}

function get_rnd_idx(arr, w_arr, h, s, cw)
{
  total_w = 0;

  vsel_col = ((h % arr.length) + (s % cw)) % arr.length;

  if(w_arr == null)
  {
	return vsel_col;
  }
  else
  {
	for(i = 0; i < w_arr.length; i++)
		total_w += w_arr[i];

	sel_w = vsel_col / arr.length * total_w;

	acc_w = w_arr[0];

	for(c_col = 0; acc_w <= sel_w; c_col++)
		acc_w += w_arr[c_col + 1];
 
//	alert('sw: ' + total_w + ' sel_w: ' + sel_w + ' c_col: ' + c_col);
	return c_col;
  }
}

function RenderPub(pubcol, nested_col_ws, offset, h_offset, choice_width, txt, target)
{
	today = new Date();
	secs = today.getSeconds() + offset;
	hour = today.getHours() + today.getDay() + h_offset;

	if (txt == undefined)
		txt = null;
	if (target == undefined)
		target = null;
	
	if(nested_col_ws != null)
	{
		pubcol = pubcol[get_rnd_idx(pubcol, nested_col_ws, hour, secs, choice_width)];
	}

	if(choice_width > pubcol.imgdt.imgs.length)
		choice_width = pubcol.imgdt.imgs.length;

	if(pubcol.lnk.link != null)
	{
		document.write('<a href="' + pubcol.lnk.link + '" '+(pubcol.lnk.over != null ? 'onmouseover="window.status=\''+pubcol.lnk.over+'\'; return true" onMouseOut="window.status=\'\'; return true;" ' : '')+'target="'+ (target == null ? '_top' : target) + '">');
	}

	if(pubcol.imgdt != null)
	{
		col = get_rnd_idx(pubcol.imgdt.imgs, pubcol.weights, hour, secs, choice_width);
		document.write('<img src="' + pubcol.imgdt.pre_imgs + pubcol.imgdt.imgs[col]+ '" border=0>');
	}

	if(txt != null && pubcol.lnk.linkTxt != null)
	{
		document.write(txt + pubcol.lnk.linkTxt);
	}

	if(pubcol.lnk.link != null)
	{
		document.write('</a>');
	}
}
