﻿// JScript 文件



                var readerID = '1';
				var adImg = new Array();
				var adLink = new Array();
				var aTitle = new Array();
				var cID = 0;
				var pictureNum = 0;
								
				var data;
//				 = AjaxClass.GetPictureNews_Pre();
//				pictureNum = data.value.Tables[0].Rows.length;
//				alert(pictureNum);
//				for(var i=0;i<data.value.Tables[0].Rows.length;i++)
//                {
//                    adImg[i] = "~/ManagementWeb" + data.value.Tables[0].Rows[i].imageUrl;
//                    adLink[i] = "../read/ReadInfo.aspx?id=" + data.value.Tables[0].Rows[i].id;
//                    aTitle[i] = data.value.Tables[0].Rows[i].name;
//                }
				

//				var preImgs = new Array();
//				for(i=0;i<1;i++)
//				{
//				    preImgs[i] = new Image();
//				    preImgs[i].src = adImg[i];
//				}
				
				function NextAd(id)
				{   
				    if(pictureNum != 0)
				    {
                        var index,str;
				        if(id == -1)
				        {
				            if(cID == pictureNum) cID=0;
//				            if(document.all)
//				            {
                                if(document.uniqueID)//IE浏览器
                                {
				                    document.getElementById("imgAD").filters.revealTrans.apply();				               
				                    document.getElementById("imgAD").filters.revealTrans.Transition = Math.floor(Math.random()*23);
				                    document.getElementById("imgAD").src = adImg[cID];
                                    document.getElementById("imgAD").filters.revealTrans.play();                                                                
				                    document.getElementById("imgAD").title = aTitle[cID];	
				                    document.getElementById("title1").title = aTitle[cID];		
                                }
                                else//其他浏览器
                                {
				                    document.getElementById("imgAD").setAttribute("src",adImg[cID]);
				                    document.getElementById("imgAD").setAttribute("title",aTitle[cID]);
                                 	document.getElementById("title1").title = aTitle[cID];		
                                }   

				                if(aTitle[cID].length>12)
				                {
//					                document.getElementById("title1").innerHTML = aTitle[cID].toString().substring(0,10)+"...";
                                    if(document.getElementById("title1").hasChildNodes())
                                    {
                                        var count = document.getElementById("title1").childNodes.length;
                                        for(var i=0;i<count;i++)
                                        {
                                            document.getElementById("title1").removeChild(document.getElementById("title1").childNodes[0]);
                                        }

                                    }
                                    document.getElementById("title1").appendChild(document.createTextNode(aTitle[cID].toString().substring(0,10)+"...")); 
                                }
				                else
				                {
//				                    document.getElementById("title1").innerHTML = aTitle[cID];
                                    if(document.getElementById("title1").hasChildNodes())
                                    {
                                        var count = document.getElementById("title1").childNodes.length;
                                        for(var i=0;i<count;i++)
                                        {
                                            document.getElementById("title1").removeChild(document.getElementById("title1").childNodes[0]);
                                        }

                                    } 
				                    document.getElementById("title1").appendChild(document.createTextNode(aTitle[cID]));
				                }
                            
                            //改变图片下面数字的背景颜色
                                for(var j=1;j<=pictureNum;j++)
                                {
                                    str = "label" + j;
                                    if( j == cID+1)
                                    {
                                        document.getElementById(str).style.backgroundColor = "#ff0000";
                                    }
                                    else
                                    {
                                        document.getElementById(str).style.backgroundColor = "#000000";
                                    }
                                }
        				        cID++;
				                timeoutId = setTimeout("NextAd(-1)",5000);
//				            }
				        }
				        else
				        {
				            cID=id;
//				            if(document.all)
//				            {
                                if(document.uniqueID)//IE浏览器
                                {
				                    document.getElementById("imgAD").filters.revealTrans.apply();				               
				                    document.getElementById("imgAD").filters.revealTrans.Transition = Math.floor(Math.random()*23);
				                    document.getElementById("imgAD").src = adImg[cID];
                                    document.getElementById("imgAD").filters.revealTrans.play();                                                                
				                    document.getElementById("imgAD").title = aTitle[cID];	
				                    document.getElementById("title1").title = aTitle[cID];		
                                }
                                else//其他浏览器
                                {
				                    document.getElementById("imgAD").setAttribute("src",adImg[cID]);
				                    document.getElementById("imgAD").setAttribute("title",aTitle[cID]);
                                 	document.getElementById("title1").title = aTitle[cID];		
                                }   
                                //				                document.getElementById("title1").innerHTML = aTitle[cID];
                                 if(aTitle[cID].length>12)
				                {
//					                document.getElementById("title1").innerHTML = aTitle[cID].toString().substring(0,10)+"...";
                                    if(document.getElementById("title1").hasChildNodes())
                                    {
                                        var count = document.getElementById("title1").childNodes.length;
                                        for(var i=0;i<count;i++)
                                        {
                                            document.getElementById("title1").removeChild(document.getElementById("title1").childNodes[0]);
                                        }

                                    }
                                    document.getElementById("title1").appendChild(document.createTextNode(aTitle[cID].toString().substring(0,10)+"...")); 
                                }
				                else
				                {
//				                    document.getElementById("title1").innerHTML = aTitle[cID];
                                    if(document.getElementById("title1").hasChildNodes())
                                    {
                                        var count = document.getElementById("title1").childNodes.length;
                                        for(var i=0;i<count;i++)
                                        {
                                            document.getElementById("title1").removeChild(document.getElementById("title1").childNodes[0]);
                                        }

                                    } 
				                    document.getElementById("title1").appendChild(document.createTextNode(aTitle[cID]));
				                }
			                    //改变图片下面数字的背景颜色
				                for(var j=1;j<=pictureNum;j++)
                                {
                                    str = "label" + j;
                                    if( j == cID+1)
                                    {
                                        document.getElementById(str).style.backgroundColor = "#ff0000";
                                    }
                                    else
                                    {
                                        document.getElementById(str).style.backgroundColor = "#000000";
                                    }
                                }
        				        cID++;

			                    timeoutId = setTimeout("NextAd(-1)",5000);
    				           
//				            }
				        }
				    }
				}
				function ShowLink()
				{
				    document.returnValue = true;
				}
				//打开链接页
				function Go2Url()
				{
					window.open(adLink[cID-1]);
				}
				
				function SelectNextAd(id)
				{
				    clearTimeout(timeoutId);
				    NextAd(id); 
				}
//图片新闻初始化
function pictureNewsInit()
{
    data = AjaxClass.GetPictureNews_Pre(readerID);
	pictureNum = data.value.Tables[0].Rows.length;
	for(var i=0;i<data.value.Tables[0].Rows.length;i++)
    {
        adImg[i] = "../../ManagementWeb" + data.value.Tables[0].Rows[i].imageUrl;
        adLink[i] = "../read/ReadInfo.aspx?id=" + data.value.Tables[0].Rows[i].id;
        aTitle[i] = data.value.Tables[0].Rows[i].title;
    }
//    alert(pictureNum);
  
    if(pictureNum != 0)
    {
//        var str = "<table width=100%><tr><td><A onmousemove='javascript:ShowLink();return document.returnValue;' href='javascript:Go2Url();'><IMG style='BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; FILTER: revealTrans(duration=2,transition=23); BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid'	height='220' alt='' hspace='0' src='javascript:NextAd(-1)' width='220' vspace='0' border='0' name='imgAD' id='imgAD'></A><TABLE id='Table1' style='WIDTH: 10px; HEIGHT: 8px' cellSpacing='0' cellPadding='0' border='0' align=right><TR>";
//        for(var k=1;k<=pictureNum;k++)
//        {
//            var a = k - 1;
//            str = str + "<td><DIV id='label" + k + "'style='WIDTH: 15px; COLOR: white; HEIGHT: 15px; cursor: hand;' onclick='javascript:SelectNextAd(" + a + ")' align='center'>" + k + "</DIV><td>";
//        }
//        str = str + "</TR></TABLE></td></tr><tr><td align=center style='background-color:#cde5f2'><div id='title1' style='font-size:small; background-image:url(../images/picnewstitle.jpg)'></div></td></tr></table>";
//        pictureNews.innerHTML = str;
        var row=null,cell=null,aLink=null,div=null,row1=null,cell1=null,table=null;
        //设置第一行，图片
        row = document.createElement("tr");
        cell = document.createElement("td");
        cell.setAttribute("align","cemter");
        if(document.uniqueID)//IE浏览器
        {
            cell.setAttribute("colSpan", '5');
        }
        else//其他浏览器
        {
            cell.setAttribute("colspan", '5');
        }     

        aLink = document.createElement("a");
        aLink.onmousemove = new Function("javascript:ShowLink();return document.returnValue;");
        aLink.setAttribute("href","javascript:Go2Url();");
        var img = document.createElement("img");
        if(document.uniqueID)
        {
            img.style.cssText = "BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; FILTER: revealTrans(duration=2,transition=23); BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid; width:227px; height:220px;";   
        }
        else
        {
            img.setAttribute("style","BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; FILTER: revealTrans(duration=2,transition=23); BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid; width:227px; height:220px;");
        }        
        img.setAttribute("id","imgAD");
        img.setAttribute("alt","");
        img.setAttribute("hspace","0");            
        img.setAttribute("vspace","0");
        img.setAttribute("border","0");
        img.setAttribute("name","imgAD");
        aLink.appendChild(img);
        cell.appendChild(aLink);
        row.appendChild(cell);
        document.getElementById("pictureNews").appendChild(row);
        //设置第二行，序号
        row = document.createElement("tr");
        cell = document.createElement("td");
        cell.setAttribute("align","right");
        if(document.uniqueID)
        {
            cell.style.cssText = "width:100%;background-image:url(../images/bl.gif);";   
        }
        else
        {
            cell.setAttribute("style","width:100%;background-image:url(../images/bl.gif);table-layout:fixed");
        }  
        for(var k=1;k<=pictureNum;k++)
        {
            var a = k - 1;
            div = document.createElement("div");
            div.setAttribute("id","label"+k);
            if(document.uniqueID)
            {
                div.style.cssText = "WIDTH: 15px; COLOR: white; HEIGHT: 15px; cursor: hand; display: inline;";   
            }
            else
            {
                div.setAttribute("style","WIDTH: 15px; COLOR: white; HEIGHT: 15px; cursor: hand; display: inline;");
            }   
            div.onclick = new Function("SelectNextAd("+a+")"); 
            div.setAttribute("align","center"); 
            div.innerHTML = "&nbsp;&nbsp;"+k+"&nbsp;&nbsp;";  
            cell.appendChild(div); 
       }            
            row.appendChild(cell);            
       document.getElementById("pictureNews").appendChild(row); 
       //设置第三行，标题
       row = document.createElement("tr");
       cell = document.createElement("td");
       if(document.uniqueID)//IE浏览器
       {
           cell.setAttribute("colSpan", '5');
       }
       else//其他浏览器
       {
           cell.setAttribute("colspan", '5');
       }     
       cell.setAttribute("align","center");
       if(document.uniqueID)
       {
           cell.style.cssText = "background-image:url(../images/blue.gif);";   
       }
       else
       {
           cell.setAttribute("style","background-image:url(../images/blue.gif);");
       }   
       div = document.createElement("DIV");
       div.setAttribute("id","title1");
       if(document.uniqueID)
       {
           div.style.cssText = "font-size:12px;HEIGHT:26px;vertical-align:middle;line-height:26px;";   
       }
       else
       {
           div.setAttribute("style","font-size:12px;HEIGHT:26px;vertical-align:middle;line-height:26px;");
       }   
       cell.appendChild(div);
       row.appendChild(cell);
       document.getElementById("pictureNews").appendChild(row);
       //改行必须放在最后，否则在FireFox浏览器中出现错误。
       //如果放在定义的img后面，程序就会执行NextAd(-1)函数，此时title1元素还没有定义，因而FireFox浏览器中导致无法找到titl1元素。但在IE浏览器中运行正常。
//       img.setAttribute("src","javascript:NextAd(-1);");
NextAd(-1);

    }
}
