var scrollNewsCt=0;
var pauseTime=2*1000;
var timer1;
var http_request=false;
var scrollNews=0;

function setOptionSelected(select,value,selected){
		for(i=0;i<select.length;i++){
			if(select.options[i].value==value){
				select.options[i].selected=selected;
				return;
			}
		}
	}
function setpauseTime(){
pauseTime=form1.timeofpause.value;
return true;
}

function hideAllClips(n) {
	for (i=0;i<n;i++){
		var allClips="photo_"+i;
		document.getElementById(allClips).style.display="none";
		}
	}
	
function clip_Switch(n) {
	var curClip="photo_"+n;
	hideAllClips(n);
	document.getElementById(curClip).style.display="block";
	scrollNewsCt=n; 
	}
	
function fwdScroll(n) {
  hideAllClips(n);
   stopScroll();
   clip_Switch(scrollNewsCt);
	scrollNewsCt+=1;
	if (scrollNewsCt==n) {
		scrollNewsCt=0;
		}
		timer1=setTimeout("fwdScroll("+n+")",pauseTime);
	}
	
function fwdScrol(n) {
    hideAllClips(n);
   stopScroll();
   clip_Switch(scrollNews);
	scrollNews+=1;
	if (scrollNews==n) {
		scrollNews=0;
		}
		timer1=setTimeout("fwdScrol("+n+")",pauseTime);
	}
function stopScroll() {
	clearTimeout(timer1);
	}

function bwdScrol(n) {
  hideAllClips(n);
   stopScroll();
	scrollNews-=1;
		if (scrollNews==-1) {
		scrollNews=n-1;
		}
	clip_Switch(scrollNews);
		timer1=setTimeout("bwdScrol("+n+")",pauseTime);
	}
function bwdScroll(n) {
  hideAllClips(n);
   stopScroll();
	scrollNewsCt-=1;
		if (scrollNewsCt==-1) {
		scrollNewsCt=n-1;
		}
	clip_Switch(scrollNewsCt);
		timer1=setTimeout("bwdScroll("+n+")",pauseTime);
	}

function photolist(blogid,albumid){
      send_photourl('/PhotosShowServlet?blogid='+blogid+'&albumid='+albumid);
 		return true;
      } 

 function send_photourl(url) {//初始化、指定处理函数、发送请求的函数
 //开始初始化XMLHttpRequest对象
      if(window.XMLHttpRequest) { //Mozilla 浏览器
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {//设置MiME类别
				http_request.overrideMimeType("text/xml");
			}
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) { // 异常，创建对象实例失败
			window.alert("不能创建XMLHttpRequest对象实例.");
			return false;
		}
		http_request.onreadystatechange = processRe;
		// 确定发送请求的方式和URL以及是否同步执行下段代码
		http_request.open("GET", url, true);
		http_request.send(null);
	}
	// 处理返回信息的函数
    function processRe() {
        if (http_request.readyState == 4) { // 判断对象状态
            if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
               processphoto();
            }else{ //页面不正常
                alert("您所请求的页面有异常。");
            }
        }
        }

   function processphoto(){
    var xmlobj=http_request.responseXML;
    var albumElement=xmlobj.getElementsByTagName("album");
    var photoElement=xmlobj.getElementsByTagName("photo");
    var albumids;
    var len=photoElement.length;
    var message=getCookie("state");
     if("blognull"==message){
     alert("错误");
     }else{
      var mdiv=document.getElementById("blog_body");
      var feedbackStr="<div class=\"album\"><div class=\"class_title\">我的相册</div>";
	    feedbackStr+="<div class=\"cat\"><form id=\"form1\" name=\"form1\" method=\"post\" action=\"javascript:;\">";
	    feedbackStr+="<select name=\"select\" onchange=\"selectAlbum("+albumElement[0].getElementsByTagName("blogid")[0].firstChild.data+")\">";
	    feedbackStr+="<option value=\"0\">请选择</option>";
	    for(var i=0;i<albumElement.length;i++) { 
	    albumname=albumElement[i].getElementsByTagName("albumname")[0].firstChild.data;
	    albumid=albumElement[i].getElementsByTagName("albumid")[0].firstChild.data;
	    blogid=albumElement[i].getElementsByTagName("blogid")[0].firstChild.data;
	     feedbackStr+="<option value=\""+albumid+"\">";
	    feedbackStr+=albumname;
	    feedbackStr+="</option>";
	    }
	    feedbackStr+="</select>"
	    feedbackStr+="<select name=\"timeofpause\" onchange=\"setpauseTime()\">"
	    feedbackStr+="<option value=\"1000\">1秒</option>";
	    feedbackStr+="<option value=\"2000\">2秒</option>";
	    feedbackStr+="<option value=\"3000\">3秒</option>";
	    feedbackStr+="<option value=\"5000\">5秒</option>";
	    feedbackStr+="<option value=\"7000\">7秒</option>";
	    feedbackStr+="<option value=\"10000\">10秒</option>";
	     feedbackStr+="</select>"
	    feedbackStr+="</form></div>";
	    feedbackStr+="<div class=\"photo\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	   if(len>0){
	   for(var i=0;i<photoElement.length;i++) {
	   albumids=photoElement[i].getElementsByTagName("albumid")[0].firstChild.data;
	   var url=photoElement[i].getElementsByTagName("url")[0].firstChild.data;
	   var photoname=photoElement[i].getElementsByTagName("photoname")[0].firstChild.data;
	   
	   feedbackStr+="<tbody id=\"photo_"+i+"\">";
	   feedbackStr+=" <tr><td class=\"picbox\"><img border=\"0\" src=\""+url+"\" width=\"480\"></img></td></tr>" ;
	   feedbackStr+="<tr><td class=\"txt\">"+photoname+"</td></tr></tbody>";
        }
      feedbackStr+="</table></div>";
      feedbackStr+="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"player\">";
	  feedbackStr+="<tr><td width=\"29\" align=\"center\">";
	  feedbackStr+="<a href=\"javascript:;\" onclick=\"bwdScrol("+len+"); return false;\"><img src=\"http://blog.china.com/images/album_last.gif\" alt=\"前一张\" width=\"25\" height=\"25\" />";
	  feedbackStr+="</a></td><td width=\"24\" align=\"center\">";
	  feedbackStr+="<a href=\"javascript:;\" onclick=\stopScroll("+len+"); return false;\"><img src=\"http://blog.china.com/images/album_pause.gif\" alt=\"暂停\" width=\"24\" height=\"25\" />";
	  feedbackStr+=" </a></td><td width=\"29\" align=\"center\">";
	  feedbackStr+="<a href=\"javascript:;\" onclick=\"fwdScrol("+len+"); return false;\"><img src=\"http://blog.china.com/images/album_next.gif\" alt=\"后一张\" width=\"25\" height=\"25\" />";
	  feedbackStr+="</a></td></tr></table>";
	    }
	    feedbackStr+="</div>";
	    mdiv.innerHTML=feedbackStr;
     }
     
      fwdScrol(len);
      setOptionSelected(form1.select,albumids,true);
}

function getCookie(str){
 var tmp,reg=new RegExp("(^| )"+str+"=([^;]*)(;|$)","gi");
 if(tmp=reg.exec(document.cookie))return(tmp[2]);
 return null;
 }
 
function selectAlbum(blogid){
if(form1.select.value=="0"){
alert("请选择图片类型!");
return false;
 }
 photolist(blogid,form1.select.value);
 }
