
var Tweener = {
    easeNone: function(t, b, c, d) {
        return c*t/d + b;
    },
	easein: function(t, b, c, d) {
		return c*(t/=d)*t + b; 
	},
	easeinout: function(t, b, c, d) {
		if (t < d/2) return 2*c*t*t/(d*d) + b;
		var ts = t - d/2;
		return -2*c*ts*ts/(d*d) + 2*c*ts/d + c/2 + b;	
	}
};
 
function $( id ){
  return document.getElementById(id);
}
var list = $('imgList');
//var imgs = list.getElementsByTagName('img');
//var px = list.clientHeight/imgs.length;
//var PLHeight = px*4;
var imgs ;
var px;
var PLHeight ;
var index = 3;   
var selected = 2;//定位
var run;
//图d片数组
function getphoto(photosrcsmall,photosrcbig,title_info,title_fine)
{ 
	photoLists=[];
	photoid=[];
	photobig=[];
	title_name = [];
	title_name = new Array();
	photobig = new Array();
	photoid = new Array();
	photoarray = new Array();
	photoarraybg=photosrcbig.split("&&");
	photosid=title_info.split("&&");
	photobig=photosrcbig.split("&&");
	title2_name = title_fine.split("&&");
	var i=0;
	for(i=0;i<photoarraybg.length-1;i++)
	{
		photoLists[i] = { smallimg: photoarraybg[i], bigimg:photobig[i], title: photosid[i] , title3_name:title2_name[i]};
	}
}

//初始化
function init()
{
list.innerHTML="";
var j=10;
if (photoLists.length<j){j=photoLists.length;}
for(i=1;i<j;i++){
if(i==index)
{
list.innerHTML+="<div id=\"pn_"+ i +"\" class=\"select\">			<table cellspacing=\"0\">			  <tbody><tr><td valign=\"middle\" align=\"center\" ><img style=\"display: inline; width: 80px; height: 100px;\" id=\""+photoLists[i-1].title+"\"  name=\""+ i+"\" title=\"第"+ i+"张\" src=\""+ photoLists[i-1].smallimg+"\" rel=\""+  photoLists[i-1].bigimg+"\" alt=\""+ photoLists[i-1].title3_name +"\" ></td></tr></tbody></table>			</div>";
}
else
{
list.innerHTML+="<div id=\"pn_"+ i +"\" class=\"noselect\">			<table cellspacing=\"0\">			  <tbody><tr><td valign=\"middle\" align=\"center\"><img style=\"display: inline; width: 80px; height: 100px;\" id=\""+photoLists[i-1].title+"\" name=\""+ i+"\" title=\"第"+ i+"张\" src=\""+ photoLists[i-1].smallimg+"\" rel=\""+  photoLists[i-1].bigimg+"\" alt=\""+ photoLists[i-1].title3_name +"\" ></td></tr></tbody></table>			</div>";
}
}
//alert(list.innerHTML);
imgs = list.getElementsByTagName('img');
 px = list.clientHeight/imgs.length;
 PLHeight = px*4;
 imgsEvent();
}
//增加一个图片
function addimg()
{
if (imgs.length<photoLists.length)
{
var j=imgs.length+1
list.innerHTML+="<div id=\"pn_"+ j +"\" class=\"noselect\">			<table cellspacing=\"0\">			  <tbody><tr><td valign=\"middle\" align=\"center\"><img  style=\"display: inline; width: 80px; height: 100px;\" name=\""+ j +"\" id=\""+photoLists[imgs.length].title+"\" title=\"第"+ j +"张\" src=\""+ photoLists[imgs.length].smallimg+"\" rel=\""+  photoLists[imgs.length].bigimg+"\" alt=\""+ photoLists[imgs.length].title3_name +"\" ></td></tr></tbody></table>			</div>";
}
 
imgsEvent();
}
 
 
 
 
var movedown;
$('slideNext').onmousedown = function (){
 
Nrun();
 movedown=setInterval("Nrun()",50);
};
$('slideNext').onmouseup = function (){
 	clearInterval(movedown);
};
 
 
 
$('slideNext').onmouseover = function (){
  this.className = 'nextHover';
}
$('slideNext').onmouseout = function (){
  this.className = 'nextNormal';
}
 
$('slidePre').onmousedown = function (){
Prun();
 movedown=setInterval("Prun()",50);
};
$('slidePre').onmouseup = function (){
 	clearInterval(movedown);
};
$('slidePre').onmouseover = function (){
  this.className = 'preHover';
}
$('slidePre').onmouseout = function (){
  this.className = 'preNormal';
}
//-------------
function getMousePosition()
{
    var e = e||window.event;
    
    var objSrc = e.srcElement;//event source element
    
    
    var left = 0;
    var top  = 0;
 
    while (objSrc.offsetParent){
        left += objSrc.offsetLeft;
        top  += objSrc.offsetTop;
        objSrc     = objSrc.offsetParent;
    }
 
    left += objSrc.offsetLeft;//source element's offsetTop
    top  += objSrc.offsetTop;//source element's offsetLeft
    
    //alert(e.offsetX);
    mouseOffsetX = left + e.offsetX;
    mouseOffsetY = top + e.offsetY;
    return mouseOffsetX;
 
}
function getObjPosition()
{
    var e = e||window.event;
    
    var objSrc = e.srcElement;//event source element
    
    
    var left = 0;
    var top  = 0;
 
    while (objSrc.offsetParent){
        left += objSrc.offsetLeft;
        top  += objSrc.offsetTop;
        objSrc     = objSrc.offsetParent;
    }
 
    left += objSrc.offsetLeft;//source element's offsetTop
    top  += objSrc.offsetTop;//source element's offsetLeft
    
  
    return left;
 
}
 
 
$('picWrap').onmousemove  = function ()
{
	SwitchEvent();
}

function getpicP(){
	
	$('srcPic').src = imgs[index-1].getAttribute('rel');
	for(k=1;k<imgs.length+1;k++){
	  if(k==parseInt(index)){
	    $('pn_'+k).className = 'select';
	  }else{
	    $('pn_'+k).className = 'noselect';
	  }
	}
	
}
 
function getpicN(){
 
	$('srcPic').src = imgs[index].getAttribute('rel');
	for(k=1;k<imgs.length+1;k++){
	if($('pn_'+k)!=null){
	  if(k==parseInt(index)+1){
	    $('pn_'+k).className = 'select';
	  }else{
	    $('pn_'+k).className = 'noselect';
	  }
	}
	}
	index++;
}
function imgsEvent()
{
for(i=0;i<imgs.length;i++){
  imgs[i].onclick = function (){
    $('srcPic').src = this.getAttribute('rel');
    document.getElementById("kehusrc").href="/photo.php?id="+this.getAttribute('id');
    document.getElementById("kehusrc2").href="/photo.php?id="+this.getAttribute('id');
    document.getElementById("title_font").innerText=this.alt;
	for(k=1;k<imgs.length+1;k++){
	  if(k==this.name){
	    $('pn_'+k).className = 'select';
	  }else{
	    $('pn_'+k).className = 'noselect';
	  }
	}
	var b = list.style.marginTop ? parseInt(list.style.marginTop) : 0;
	
	var runc = (this.name-selected)*px + b;//需要滚动像素
	
	index = this.name;
	if(index>selected){
	   Nrun( runc );
	}
	if(runc<0){
	  Prun( Math.abs(runc) );
	}
  }
}
}
//上
	function Prun( runc ){
	
		var b = list.style.marginTop ? parseInt(list.style.marginTop) : 0;
		var c = typeof runc == 'number' ? runc : px ;
		var t=0,ttl=10,d =5;
		clearInterval(run);
		if(b)run = setInterval(function (){
					var top = Tweener.easeinout(t,b,c,d);
					if(top>=0){
					  list.style.marginTop  = '0px';
					  clearInterval(run);
					  return;
					}
					list.style.marginTop  = top+'px';
					if(t<d){
					  t++; 
					}else{
					  clearInterval(run);
					}
				},ttl)
	};
//下
	function Nrun( runc ){
	addimg();
		var b = list.style.marginTop ? -parseInt(list.style.marginTop) : 0;
		var c = typeof runc == 'number' ? runc : px ;
		var d = 5;
		var t=0,ttl=10;
		clearInterval(run);
		run = setInterval(function (){
					var top = Tweener.easeinout(t,b,c,d);
					if(top>=list.clientHeight-PLHeight){
					  list.style.marginTop  = -list.clientHeight+PLHeight+'px';
					  clearInterval(run);
					  return;
					}
					list.style.marginTop  = -top+'px';
					if(t<d){
					  t++; 
					}else{
					  clearInterval(run);
					}
				},ttl)
};
 
init();

