// JavaScript Document

// 实现flash效果的可选的百叶窗图片链接

/*
* 一般的调用方法有两种：
*   (1) 控制某个元素（如div，其id为"divId"）的内部HTML实现方法的调用方式：
*          MyImg.disp(img, imglink, imgalt, w, h, time, 'divId');
*   (2) 直接在需要显示的区域中调用的方式：
*          MyImg.disp(img, imglink, imgalt, w, h, time);
* 参数说明：
*   img :     图像路径 数组，如：['images/1.jpg','images/2.jpg','images/3.jpg']
*   imglink : 目标链接 数组，如：['http://www.baidu.com','index.html','images/3.jpg']
*   imgalt : 图像说明 数组，如：['百度一下，你就知道','首页','大图']
*   w :       该图像区域的宽，单位：像素，如：400 （默认值：400）
*   h :       该图像区域的高，单位：像素，如：300 （默认值：300）
*   time :    图像切换的时间间隔，单位：毫秒，如：5000 （默认值：5000，即5秒）
*
* ********************
* ** Author : lzf **
* ********************
*/
var MyImg = {

img : [],
imglink : [],
imgalt : [],

num : -1,
time : 5000,

$ : function(id) {
   return document.getElementById(id);
},
init : function(img, imglink, imgalt, time) {
   this.img = img;
   this.imglink = imglink;
   this.imgalt = imgalt;
   if(time && time != 0 && time != '0') this.time = time;
},
show : function(idx) {
   if(document.all) {
    aspnetForm.myimgRotator.filters.revealTrans.Transition = Math.floor(Math.random() * 20);
    aspnetForm.myimgRotator.filters.revealTrans.apply();
   }
   document.images.myimgRotator.src = this.img[idx];
   document.images.myimgRotator.alt = this.imgalt[idx];
   if(document.all) aspnetForm.myimgRotator.filters.revealTrans.play();
   for(var i=0;i<this.img.length;i++) {
    var o = this.$('myimg_a_' + i);
    if(i == idx) {
     o.style.backgroundColor = 'red';
     o.innerHTML = '&nbsp;<font color=#ffffff>' + (i+1) + '</font>&nbsp;';
    } else {
     o.style.backgroundColor = '';
     o.innerHTML = '&nbsp;' + (i+1) + '&nbsp;';
    }
   }
   this.$('myimgalt').innerHTML = '&nbsp;<a onclick="MyImg.linkURL();" style="color:blue;cursor:hand;">' + (this.imgalt && this.imgalt[idx] ? this.imgalt[idx] : '') + '</a>';
},
next : function() {
   this.num++;
   if(this.num >= this.img.length) this.num = 0;
   this.show(this.num);
   setTimeout("MyImg.next()", this.time);
},
slct : function(idx) {
   this.num = idx - 1;
   var tmp = this.time;
   this.time = 1000000;
   this.show(idx);
   this.time = tmp;
},
linkURL : function() {
   var url = (this.imglink && this.imglink[this.num]) ? this.imglink[this.num] : this.img[this.num];
   window.open(url);
},
getHTML : function(img, imglink, imgalt, w, h, time) {
   this.init(img, imglink, imgalt, time);
   w = (w) ? w : 400;
   h = (h) ? h : 300;
   var aa = '';
   for(var i=0;i<this.img.length;i++) {
    aa += '<a id=myimg_a_' + i + ' onclick="MyImg.slct(' + i + ');" style="cursor:hand;" title="' + this.imgalt[i] + '">&nbsp;' + (i+1) + '&nbsp;</a>';
   }
   return '<table boder=0 width=' + w + ' height=' + h + '><tr><td><a href="javascript:MyImg.linkURL();"><img style="FILTER:revealTrans(duration=2,transition=20,border:1px solid #000000" src="javascript:MyImg.next();" width=' + w + ' height=' + h + ' border=0 name="myimgRotator" alt=""></a><div align=right style="font-size:13px;margin-top:-20px;"><table border=0 width=' + w + ' bgcolor="#FFFFFF" style="filter:alpha(opacity=80);"><tr><td><div id=myimgalt align=left></div></td><td>' + aa + '</td></tr></table></div></td></tr></table>';
},
// 通用调用函数
disp : function(img, imglink, imgalt, w, h, time, id) {
   var html = this.getHTML(img, imglink, imgalt, w, h, time);
   if(id) this.$(id).innerHTML = html;
   else document.write(html);
   MyImg.next();
}
};
