var now_pro;
var old_pro = 0;
var now_imgnum = 1;
var old_imgnum = "nan";
var page = 0;
var step = 5;
var zt = 0;
var img_val;
var s_img_p;
function load_fx(){
	//pro_bh(now_pro);
	s_img_p = "";
	for(var i=0; i<small_img.length-1; i++){
		s_img_p =s_img_p+"<a href='javascript:img_motion_ft("+i+")'><img src='../"+small_img[i]+"' id='small_img_"+i+"' /></a>"
	}
	document.getElementById("img_pc").innerHTML = s_img_p;
	var img_p = document.createElement("img");
	img_p.setAttribute("src",pt_img);
	document.getElementById("img_area").appendChild(img_p);
	var tempimg = document.createElement("img");
	tempimg.style.display = "none";
	tempimg.setAttribute("src",big_img[0]);
	tempimg.setAttribute("id","tempdv");
	document.body.appendChild(tempimg);

	dv_pro = document.getElementById("img_pc");
	dv_pro_num = dv_pro.getElementsByTagName("a").length;
	page_num = parseInt(dv_pro_num)-3;
	
	img_val=setInterval("img_motion_ft(0)",5000);
}

function goleft_motion(){
	if(zt == 1){return;}
	if(page == 0){return;}
	zt = 1;
	page--;
	h = document.getElementById("img_pc").offsetLeft;
	val=setInterval("left_motion()",30);
}

function goright_motion(){
	if(zt == 1){return;}
	if(page == page_num){return;}
	zt = 1;
	page++;
	h = document.getElementById("img_pc").offsetLeft;
	val=setInterval("right_motion()",30);
}

function left_motion(){
	document.getElementById("img_pc").style.left = (parseInt(document.getElementById("img_pc").offsetLeft)+step)+"px";
	if((h+109) < parseInt(document.getElementById("img_pc").offsetLeft)){
		document.getElementById("img_pc").style.left = h+109;
		clearInterval(val);
		zt = 0;
	}
}

function right_motion(){
	document.getElementById("img_pc").style.left = (parseInt(document.getElementById("img_pc").offsetLeft)-step)+"px";
	if((h-109) > parseInt(document.getElementById("img_pc").offsetLeft)){
		document.getElementById("img_pc").style.left = h-109;
		clearInterval(val);
		zt = 0;
	}
}

function pro_bh(now_num){
	if(old_pro != 0){
		document.getElementById("tlt_img_"+old_pro).removeAttribute("class");
		document.getElementById("tlt_img_"+old_pro).removeAttribute("className");
		document.getElementById("pro"+old_pro).style.display = "none";
	}
	document.getElementById("pro"+now_num).style.display = "block";
	document.getElementById("tlt_img_"+now_num).setAttribute("class","on");
	document.getElementById("tlt_img_"+now_num).setAttribute("className","on");
	old_pro = now_num;
}


function img_motion_ft(img_now_num){
	var img_node = document.getElementById("img_area").childNodes;
	document.getElementById("img_area").removeChild(img_node[0]);
	clearInterval(img_val);
	if(img_now_num == big_img.length-1){img_now_num = 0;}
	//alert(old_imgnum);
	if(old_imgnum != "nan"){
		document.getElementById("small_img_"+old_imgnum).removeAttribute("class");
		document.getElementById("small_img_"+old_imgnum).removeAttribute("className");
	}
	var imgtemp = document.getElementById("tempdv");
	imgtemp.setAttribute("src",big_img[img_now_num+1]);
	document.getElementById("small_img_"+img_now_num).setAttribute("class","on");
	document.getElementById("small_img_"+img_now_num).setAttribute("className","on");
	var img_p = document.createElement("img");
	img_p.setAttribute("src",big_img[img_now_num]);
	var img_url_p = document.createElement("a");
	var array_link_p = new Array;
	array_link_p = split(img_link[img_now_num],'#');
	//alert(array_link_p[0]);
	img_url_p.setAttribute("href",array_link_p[0]);
	img_url_p.setAttribute("target","_blank");
	img_url_p.appendChild(img_p);
	document.getElementById("img_area").appendChild(img_url_p);
	old_imgnum = img_now_num;
	img_val=setInterval("img_motion_ft(old_imgnum+1)",5000);
}

function split(original,regex){
	var startIndex = 0;
	var tempArray = new Array();
	var index = 0;
	startIndex = original.indexOf(regex);
	while(startIndex < original.length && startIndex != -1){
		temp = original.substring(index,startIndex);
		tempArray.push(temp)
		index = startIndex + regex.length;
		startIndex = original.indexOf(regex,startIndex + regex.length);
	}
	tempArray.push(original.substring(index + 1 - regex.length));
	return tempArray;
}

var proArray = new Array;
function send_request(url) {
	http_request = false;
	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) { // 无法识别
		alert("无法识别,错误");
		return false;
	}
	http_request.onreadystatechange = processRequest;
	http_request.open("GET", url, true);
	http_request.send(null);
}
function processRequest() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			alter();
		}
	}
}
function alter(){
	var xmldoc,product_dv,item_dv,tiem_data,old_data,id,finid;
	xmldoc = http_request.responseXML;
	product_dv = xmldoc.getElementsByTagName("productype");
	for(var i=0; i<product_dv.length; i++){
		id = product_dv[i].getAttribute("id");
		item_dv = product_dv[i].getElementsByTagName("productitem");
		for(var n=0; n<item_dv.length; n++){
			tiem_data = item_dv[n].getAttribute("daynum");
			if(!old_data){
				old_data = tiem_data;
				finid = id;
			}else{
				if(tiem_data > old_data){
					old_data = tiem_data;
					finid = id;
				}
			}
		}
	}
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	vMon = vMon<10 ? "0" + vMon : vMon;
	var vDay = d.getDate();
	vDay = vDay<10 ?  "0"+ vDay : vDay;
	var nowdata = new Date(vMon+"-"+vDay+"-"+vYear);
	var oldday = old_data.split(" ");
	var ol = oldday[0].split("-");
	old = new Date(ol[1]+"-"+ol[2]+"-"+ol[0]);
	iDays  =  parseInt(Math.abs(nowdata - old)/1000/60/60/24);
	if(iDays>=30){
		finid = 2;
	}
	pro_bh(finid);
}
