﻿// JScript 文件
var theTimer;
var ver=2; //兼容浏览器版本 默认2 为非ie
var firstTime=true;
var _timeOut_=3000;
var imgUrl = new Array();
var imgText = new Array();
var imgLink = new Array();
var imgDesc = new Array();
var imgDate = new Array();
var imgAuthor = new Array();
var now=0;
var count=0;
var imgWidth=312;
var imgHeight = 278;
var imgTopH = 0;
var target="_blank";   //打开方式
//调用方法slide(imgSrc, imgText, imgLink, imgDesc, isShow, width, height)
function slide(imgSrc, text, link, desc, date, author, width, height)
{
//    imgWidth = width;
//    imgHeight = height;
    var timeOut=_timeOut_;
    var timeOut2=_timeOut_/2; //onmouseout img后需要切换的时间

    try{  //ie版本
      new ActiveXObject("DXImageTransform.Microsoft.revealTrans");
      ver=1; 
      }
    catch (e){ver=2;}
    
    var imgSrcItem = imgSrc.split('|');
    var imgTextItem = text.split('|');
    var imgLinkItem = link.split('|');
    var imgDescItem = desc.split('|');
    var imgDateItem = date.split('|');
    var imgAuthorItem = author.split('|');
    for(var i = 0; i < imgSrcItem.length; i++)
    {
        imgUrl[i]=imgSrcItem[i];
        imgText[i]=imgTextItem[i];
        imgLink[i]=imgLinkItem[i];
        imgDescItem[i] = imgDescItem[i].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;nbsp;/g,"");
        imgDesc[i] = imgDescItem[i].replace(/<.*?>/g,"");
        imgDate[i] = imgDateItem[i];
        imgAuthor[i] = imgAuthorItem[i];
        count++;
    }
    //表现层 start
    with(document){
    write('<table width="'+imgWidth+'px" border="0" cellspacing="0" cellpadding="0">');
    write('<tr>');
        write('<td align="center" valign="top" id="cctb1">');
            write('<div id="f_div" style="width:' + imgWidth + 'px; height:' + imgHeight + 'px; ">');
            
                    write('<div id="f_imgDiv">');
                    write('<a id="f_imgLink" target=' + target + ' href="' + imgLink[now] + '">');
	                    write('<img id="f_img" src="'+imgUrl[now]+'" onload="DrawImage(this, '+imgWidth+','+imgHeight+');" alt="">');
	                    write('</a>');
	                write('</div>');
	                
	                
	                
                write('<div id="f_buttonDiv">');
                    write('<div id="button_bg">');		
                    for (var i=count;i>0;i--){		 
                        if(i==now+1){write('<a id="b'+(i-1)+'" class="on" href="javascript:b_change('+(i-1)+')" onfocus="blur()" title="">'+i+'</a>');}
	                    else{write('<a id="b'+(i-1)+'" href="javascript:b_change('+(i-1)+')" onfocus="blur()"  title="">'+i+'</a>');}
                    }
                    write('</div>');
	                if (ver==1)write('<div id="f_line"></div>');
	                write('</div>');
	                write('<div id="f_text">');
	                write('<a href="' + imgLink[now] + '" target="' + target + '">');
	                write(imgText[now]);
	                write('</a>');
	                write('</div>');
            write('</div>');
        write('</td>');
    write('</tr>');
    write('</table>');


    }
    //表现层 end 
    document.getElementById('f_img').onmouseover=function(){window.clearInterval(theTimer);}
    document.getElementById('f_img').onmouseout=function(){theTimer=setTimeout("change()", timeOut2);}
    theTimer = setTimeout("change()", _timeOut_/2);
}


function change()
{
    if (ver==1){
        with(document.getElementById('f_img').filters.revealTrans){
	        Transition=Math.random() * 22;
	        apply();
	        play(); 
        }
    }
    if (firstTime){ firstTime=false;timeOut=_timeOut_/2;}
    else{	 
         document.getElementById('f_img').src=imgUrl[now];
         document.getElementById('f_imgLink').href=imgLink[now];
         document.getElementById('f_text').innerHTML='<a href="'+imgLink[now]+'" target="'+target+'">' + imgText[now] + '</a>';
         //document.getElementById('f_content').innerHTML = imgDesc[now];
         //document.getElementById('f_t').innerHTML = imgText[now].substr(0,10);
         //document.getElementById('f_date').innerHTML = imgDate[now];
         //document.getElementById('f_author').innerHTML = imgAuthor[now];
         for (var i=0;i<count;i++) {document.getElementById('b'+i).className="button";}
         document.getElementById('b'+now).className="on";		 
         now=(now>=imgUrl.length-1)?0:now+1;
         timeOut=_timeOut_;		 
    }
    theTimer=setTimeout("change()", timeOut);
}
    
function b_change(num)
{
    window.clearInterval(theTimer);
    now=num;
    firstTime=false;
    change();
}

function DrawImage(imgObj,iwidth,iheight)
{
    var image=new Image(); 
    image.src=imgObj.src; 
    if(image.width>0 && image.height>0) {  
                imgObj.width=iwidth;
                imgObj.height = (image.height * iwidth) / image.width;
                if (imgObj.height < iheight) {
                    imgTopH = (iheight - imgObj.height-27) / 2;
                    
                }
                else {
                    imgTopH = 0;
                }
                imgObj.style.marginTop = imgTopH+'px';

                imgObj.alt=image.width+"×"+image.height; 


    } 
}
