﻿//图集
//WIND
//20100209
var efu = {
	$ : function(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}},
	isIE : navigator.appVersion.indexOf("MSIE")!=-1?true:false,
	
	//Event
	addEvent : function(obj,eventType,func){if(obj.attachEvent){obj.attachEvent("on" + eventType,func);}else{obj.addEventListener(eventType,func,false)}},
	delEvent : function(obj,eventType,func){
		if(obj.detachEvent){obj.detachEvent("on" + eventType,func)}else{obj.removeEventListener(eventType,func,false)}
	},
	//Cookie
	readCookie : function(l){var i="",I=l+"=";if(document.cookie.length>0){var offset=document.cookie.indexOf(I);if(offset!=-1){offset+=I.length;var end=document.cookie.indexOf(";",offset);if(end==-1)end=document.cookie.length;i=document.cookie.substring(offset,end)}};return i}
	};

var epidiascope = {
	picArrLeftId : "efpLeftArea",
	picArrRightId : "efpRightArea",
	picListId : "efpPicListCont",
	mainBoxId : "efpBigPic",
	selectedIndex: -1,
	filmstrips : [],
	repetition : false, //循环播放
	add : function(s){
		this.filmstrips.push(s);
	},
    init : function(){
	   var tempThis = this;
	   var tempWidth = 0;
	   if(this.filmstrips.length * 105 < efu.$(this.picListId).offsetWidth){
			tempWidth = Math.round(efu.$(this.picListId).offsetWidth / 2 - this.filmstrips.length * 105/2);	
	   };
	   var commKey = "";
	   var tempHTML = '<div style="width:32760px;padding-left:' + tempWidth + 'px;">',i;
	   for(i=0;i<this.filmstrips.length;i++){
		   //子列表
		   tempHTML += '<div class="pic" id="slide_' + i + '"><table cellspacing="0"><tr><td class="picCont"><table cellspacing="0"<tr><td><a href="javascript:epidiascope.select01(' + i + ','+ 0 +');" onclick="this.blur();"><img src="' + this.filmstrips[i].smallpic + '" alt="' + this.filmstrips[i].altt + '"  oncontextmenu="event.returnValue=false;return false;" /></a></td></tr></table></td></tr></table></div>';
	   }
	   efu.$(this.picListId).innerHTML = tempHTML + "</div>";
       var page = window.location.search.match(/id=(\d+)/i);
	   var url
			if(page){
			page = page[1];
			url = page;
            for(i=0;i<this.filmstrips.length;i++){
				if(page ==  this.filmstrips[i].urlid){
					page = i;
					break;
				}
			};
			
			if(page == url){
				page = 0;
				}
		}else{
			page = 0;
			};
	   efu.$(this.picArrLeftId).onclick = function(){epidiascope.previous(page)};
	   efu.$(this.picArrRightId).onclick = function(){epidiascope.next(page)};
	   this.select01(page,1);
	},
	select01 : function(numa,numb){
		if(numb == 0){
		this.select(numa);
		};
		if(numb == 1){
	    if(this.onstart){this.onstart()};
		//if(efu.$("slide_" + this.selectedIndex)){efu.$("slide_" + this.selectedIndex).className = "pic"};
		efu.$("slide_" + numa).className = "picOn";
		this.picList.foucsTo(numa + 1); //滚动		 
			}
		},
	select : function(num,type){
		var tempThis = this;
		if(this.endSelect.status == 1){
			this.endSelect.close();
		};
		if(num == this.selectedIndex){return};
		var i;
		if(num >= this.filmstrips.length || num < 0){return};
		this.selectedIndex = num;
		this.PVCount(); //PV统计
	},
	PVCount : function(){
		this.setPageInfo(this.selectedIndex);
	},
	setPageInfo : function(num){	
		window.location.href = "http://www.efu.com.cn/product/page.aspx?id="+this.filmstrips[num].urlid; 
	},
	next : function(num,type){
		var tempNum = num + 1;
		if(tempNum >= this.filmstrips.length){
			if(this.repetition){ //循环播放
				tempNum = 0;
			}else{
				this.endSelect.open(); //选择
				return;
			};
		};
		this.select(tempNum,type);
	},
	previous : function(num){
		var tempNum = num - 1;
		if(tempNum < 0){ //循环播放
			if(this.repetition){
				tempNum = this.filmstrips.length - 1
			}else{
				return;
			};
		};
		this.select(tempNum);
	},	
	rePlay : function(){ //重新播放
		if(this.endSelect.status == 1){this.endSelect.close()};
		this.autoPlay = true;
		this.select(0);
	}
};

epidiascope.picList = { //列表滚动
	leftArrId : "efpListLeftArr",
	rightArrId : "efpListRightArr",
	picListId : "efpPicListCont",
	timeoutObj : null,
	pageWidth : 105,
	totalWidth : 0,
	offsetWidth : 0,
	lock : false,
	init : function(){
		
		efu.$(this.rightArrId).onmousedown = function(){epidiascope.picList.leftMouseDown()};
		efu.$(this.rightArrId).onmouseout = function(){epidiascope.picList.leftEnd("out");this.className='';};
		efu.$(this.rightArrId).onmouseup = function(){epidiascope.picList.leftEnd("up")};
		efu.$(this.leftArrId).onmousedown = function(){epidiascope.picList.rightMouseDown()};
		efu.$(this.leftArrId).onmouseout = function(){epidiascope.picList.rightEnd("out");this.className='';};
		efu.$(this.leftArrId).onmouseup = function(){epidiascope.picList.rightEnd("up")};
		this.totalWidth = epidiascope.filmstrips.length * this.pageWidth;
		this.offsetWidth = efu.$(this.picListId).offsetWidth;

	},
	leftMouseDown : function(){
		if(this.lock){return};
		this.lock = true;
		this.timeoutObj = setInterval("epidiascope.picList.moveLeft()",10);
	},
	rightMouseDown : function(){
		if(this.lock){return};
		this.lock = true;
		this.timeoutObj = setInterval("epidiascope.picList.moveRight()",10);
	},
	moveLeft : function(){
		if(efu.$(this.picListId).scrollLeft + 10 > this.totalWidth - this.offsetWidth){
			efu.$(this.picListId).scrollLeft = this.totalWidth - this.offsetWidth;
			this.leftEnd();
		}else{
			efu.$(this.picListId).scrollLeft += 10;
		};
	},
	moveRight : function(){
		efu.$(this.picListId).scrollLeft -= 10;
		if(efu.$(this.picListId).scrollLeft == 0){this.rightEnd()};
	},
	leftEnd : function(type){
		if(type=="out"){if(!this.lock){return}};
		clearInterval(this.timeoutObj);
		this.lock = false;
		this.move(30);
	},
	rightEnd : function(type){
		if(type=="out"){if(!this.lock){return}};
		clearInterval(this.timeoutObj);
		this.lock = false;
		this.move(-30);
	},
	foucsTo : function(num){
		if(this.lock){return};
		this.lock = true;
		if(epidiascope.filmstrips.length-num == 3)
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth + 315 ) ;
		else if(epidiascope.filmstrips.length-num == 2)
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth + 210 ) ;
		else if(epidiascope.filmstrips.length-num == 1)
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth + 105 ) ;
		else if(epidiascope.filmstrips.length-num == 0)
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth);
		else
		var _moveWidth = Math.round(num * this.pageWidth - this.offsetWidth/2);
		this.move01(_moveWidth);
	},
	move01 : function(num){
		efu.$(this.picListId).scrollLeft = num;
		},
	move : function(num){
		var thisMove = num/4;
		if(Math.abs(thisMove)<1 && thisMove!=0){
			thisMove = (thisMove>=0?1:-1)*1;
		}else{
			thisMove = Math.round(thisMove);
		};

		var temp = efu.$(this.picListId).scrollLeft + thisMove;
		if(temp <= 0){efu.$(this.picListId).scrollLeft = 0;this.lock = false;return;}
		if(temp >= this.totalWidth - this.offsetWidth){efu.$(this.picListId).scrollLeft = this.totalWidth - this.offsetWidth;this.lock = false;return;}
		efu.$(this.picListId).scrollLeft += thisMove;
		num -= thisMove;
		if(Math.abs(num) <= 1){this.lock = false;return;}else{
			setTimeout("epidiascope.picList.move(" + num + ")",10)
		}
	}
};


//结束选择
epidiascope.endSelect = {
	endSelectId : "endSelect",
	closeId : "endSelClose",
	rePlayButId : "rePlayBut",
	status : 0, //1:open  0:close
	open : function(){
		this.status = 1;
		efu.$(this.endSelectId).style.display = "block";
		efu.$(this.endSelectId).style.left = Math.round((efu.$(epidiascope.mainBoxId).offsetWidth - efu.$(this.endSelectId).offsetWidth)/2) + "px";
		efu.$(this.endSelectId).style.top = Math.round((efu.$(epidiascope.mainBoxId).offsetHeight - efu.$(this.endSelectId).offsetHeight)/2) + "px";
		efu.$(this.closeId).onclick = function(){epidiascope.endSelect.close()};
		efu.$(this.rePlayButId).onclick = function(){epidiascope.rePlay()};
	},
	close : function(){
		this.status = 0;
		//efu.$(epidiascope.playButtonId).onclick = function(){epidiascope.play()};
		efu.$(this.endSelectId).style.display = "none";
	}
};

epidiascope.onstart = function(){
	//图片列表滚动
	epidiascope.picList.init();
};

//按钮构造函数
epidiascope.Button = function(id){
	this.status = 'ok';
	this.id = id;
	this.init();
};

