﻿function Banner(image,url,alt)
{
   this._image=image;
   this._url=url;
   this._alt=alt;
   this._random=Math.random()*100;
}
function sortBanner(a,b)
{
   return a._random-b._random;
}
function RandomBanner(group,bannerareaid,top)
{ 
  var bannerarea=document.getElementById(bannerareaid);
  for(var i=0;i<top;i++)
  {
    var ahref=document.createElement("a");
    ahref.setAttribute("href",group[i]._url);
    ahref.setAttribute("target","_blank");
   
    var img=document.createElement("img");
    img.setAttribute("src",group[i]._image);
    img.setAttribute("alt",group[i]._alt);
    img.style.border="0";
    
    ahref.appendChild(img);
    bannerarea.appendChild(ahref);
  }
}
//Initial
var top=5;
var bannerareaid="bannerarea";
var group=new Array(0);
//Data 
group.push(new Banner("images/banner/168books.gif","http://www.168books.com.tw/",""));
group.push(new Banner("images/banner/top_logo.jpg","http://www.top945.com.tw/",""));
group.push(new Banner("images/banner/ican.gif","http://www.greenland-book.com/index.php?cat=c50_I-Can.html&refID=magv200903",""));
group.push(new Banner("images/banner/090401-HM banner.gif","http://www.happymarian.com",""));
group.push(new Banner("images/banner/banner_165X60.gif","http://superday.pixnet.net/blog",""));
group.sort(sortBanner);
//Execute
RandomBanner(group,bannerareaid,top);
