///图片页面　－　图片列表
var listWidth = 0;
var moveSpeed = 3;//px;
var moveSpeedTime = 10;//px;
var moveDirction = "up"; // up | left
//var moveDirction = "left";

var inImgList = null;//商品图片列表的表格
var listEnd = null;
var listStart = null;
var imgListUping = false;
var imgListDowning = false;
function imgListScrollSlow()
{
	moveSpeed = 3;
}
function imgListScrollFast()
{
	moveSpeed = 8;
}
function imgListUpEnd()
{
	setTimeout("imgListUpEnd1()","500")
}
function imgListUpEnd1()
{
	imgListUping = false;
}
function imgListDownEnd()
{
	setTimeout("imgListDownEnd1()","500")
}
function imgListDownEnd1()
{
	imgListDowning = false;
}
function imgListDown()
{
	if(window.event)
	{
		imgListDowning = true;
	}
	var t = 0;
	if(moveDirction == "up")
	{
		t = parseInt(inImgList.style.top);
	}
	else
	{
		t = parseInt(inImgList.style.left);
	}
	if(t.toString() == "NaN")t = 0;
	if(t < 0 && imgListDowning)
	{
		if(moveDirction == "up")
			inImgList.style.top = (t + moveSpeed);
		else
			inImgList.style.left = (t + moveSpeed);
		window.setTimeout("imgListDown()",moveSpeedTime);
	}
}
function imgListUp()
{
	if(window.event)
	{
		imgListUping = true;
	}
	var t = 0;
	var p = 0;
	if(moveDirction == "up")
	{
		t = parseInt(inImgList.style.top);
		if(t.toString() == "NaN")t = 0;
		p = parseInt(inImgList.height) - Math.abs(t)
	}
	else
	{
		t = parseInt(inImgList.style.left);
		if(t.toString() == "NaN")t = 0;
		p = parseInt(inImgList.width) - Math.abs(t);
	}
	//alert(inImgList.height);
	//alert(p);
	if(listWidth == 0)
	{
		if(imgList.moveDirction == "up")
		{
			listWidth = parseInt(document.getElementById("imgList").style.height);
		}
		else
		{
			listWidth = parseInt(document.getElementById("imgList").style.width);
		}
	}
	if(p > listWidth && imgListUping)
	{
		if(moveDirction == "up")
			inImgList.style.top = t - moveSpeed;
		else
			inImgList.style.left = t - moveSpeed;
		setTimeout("imgListUp()",moveSpeedTime)
	}
}
function initImageList()
{
	
	var sourceData = document.getElementById("sourceData");
	imgList.document.body.innerHTML = sourceData.innerHTML;
	sourceData.innerHTML = "";
	imgList.document.body.style.margin = 0;
	inImgList = imgList.document.getElementById("inImgList");
	if(moveDirction == "up")
	{
		listEnd = imgList.document.getElementById("listEnd");
	}
	else
	{
		listEnd = imgList.document.getElementById("listEnd1");
	}
	listStart = imgList.document.getElementById("listStart");
	//alert(moveDirction);
	imgList.moveDirction = moveDirction
	
	imgList.document.body.oncontextmenu = function()
	{
		return false;
	}
	imgList.document.body.ondrag = function()
	{
		return false;
	}
	imgList.document.body.onselectstart = function()
	{
		return false;
	}
	var maxLen = 0;
	var imgList0 = document.getElementById("imgList");
	if(imgList.moveDirction == "up")
	{
		maxLen = parseInt(imgList0.style.width);
	}
	else
	{
		maxLen = parseInt(imgList0.style.height);
	}
	maxLen -= 15;
	if(maxLen < 80)maxLen = 80
	for(var i = 0;i < imgList.document.images.length;i++)
	{
		var img = imgList.document.images[i];
		if(img.attributes["inImgList"])
		{
			var s = new Size(img.width,img.height);
			s = GetSizeForMax(s,maxLen,maxLen);
			img.width = s.Width;
			img.height = s.Height;
		}
	}
	if(imgList.moveDirction == "up")
	{
		//alert(listEnd.innerHTML);
		inImgList.height = 1;
		var h = getTop(listEnd);
		if(h > 0)inImgList.height = h;
		//inImgList.height = 0;
	}
	else
	{
		//alert();
		inImgList.width = getLeft(listEnd);
	}
	//alert(inImgList.innerHTML);
}
////////////
////
var iframeWidth = 500; //图片的标准大小
var showHiddenSpeed = 10; //
var initOpacity = 70; //默认图片透明度
var reSizeSpeed = 40;

var reSizeSpeed1 = 0;
var reSizeSpeed2 = 40;

var reSizeWidth = 0.02;
var reSizeWidth1 = 0.06;
var reSizeWidth2 = 0.02;

var cuIndex = 0;
var cImg
var imgObjs;
var preImg = null;
function imageOver(index,win)
{
	//alert(bigImg.document.body.innerHTML);
	if(imgObjs == null)imgObjs = new Array(bigImages.length);
	if(imgObjs[index] == null)
	{
		imgObjs[index] = win.document.getElementById(imgs["img" + index]);
		imgObjs[index].style.filter = "alpha(opacity=" + initOpacity + ");"
	}
	if(preImg != null)
	{
		imageOut(preImg);
	}
	preImg = index;
	imgObjs[index].startTime = setTimeout("showImage(" + index + ")",showHiddenSpeed);
}
function imageOut(index,win)
{
	if(imgObjs == null)imgObjs = new Array(bigImages.length);
	if(imgObjs[index] == null)
	{
		imgObjs[index] = win.document.getElementById(imgs["img" + index]);
		imgObjs[index].style.filter = "alpha(opacity=" + initOpacity + ");"
	}
	imgObjs[index].endTime = setTimeout("hiddenImage(" + index + ")",showHiddenSpeed);
}
function hiddenImage(imgIndex)
{
	if(imgObjs[imgIndex].filters.alpha.opacity > initOpacity & !imgObjs[imgIndex].showing)
	{
		imgObjs[imgIndex].hiddening = true;
		imgObjs[imgIndex].filters.alpha.opacity -= 1;
		setTimeout("hiddenImage(" + imgIndex + ")",showHiddenSpeed)
	}
	else
	{
		clearTimeout(imgObjs[imgIndex].endTime);
		imgObjs[imgIndex].hiddening = false;
	}
}
function showImage(imgIndex)
{
	if(imgObjs[imgIndex].filters.alpha.opacity < 100 && !imgObjs[imgIndex].hiddening)
	{
		imgObjs[imgIndex].showing = true;
		imgObjs[imgIndex].filters.alpha.opacity += 1;
		setTimeout("showImage(" + imgIndex + ")",showHiddenSpeed)
	}
	else
	{
		clearTimeout(imgObjs[imgIndex].startTime);
		imgObjs[imgIndex].showing = false;
	}
}
function move(win){
	if(win == null)win = window;
	if(s != null){
		s.style.top =  win.event.y - y + document.body.scrollTop
		s.style.left = win.event.x - x + document.body.scrollLeft
	}
	win.moveLayer = false;
	win.event.returnValue = false
}
function down(obj,win){
	s = obj
	if(win == null)win = window;
	win.moveLayer = true;
	if(win.event != null)
	{
		s.style.cursor = "move";
		x = win.event.offsetX + document.body.scrollLeft;	//+ getLeft(win.event.srcElement) - getLeft(obj) //event.offsetX
		y = win.event.offsetY + document.body.scrollTop;	//+ getTop(win.event.srcElement) - getTop(obj)//event.offsetY 
	}
}
function up(obj,win){
	if(win == null)win = window;
	startX = win.event.x - win.event.offsetX - 2;
	startY = win.event.y// //+ document.body.scrollTop;// - event.offsetY;
	currrentY = startY + win.document.body.scrollTop;
	if(s != null)s.style.cursor = "";
	s = null
	
}

var cW,cH;
var bSizeing = false;
var sSizeing = false;
//大
function checkHaveCImg()
{
	if(cImg == null)cImg = bigImg.document.getElementById("cuImg");
}
function bSize()
{
	checkHaveCImg();
	if(window.event)
	{
		bSizeing = true;
	}
	if(!bSizeing)return;
	cImg.onload = null;
	if(cImg.w == null)cImg.w = cImg.width;
	if(cImg.h == null)cImg.h = cImg.height;
	
	var l,t;
	l = cImg.w;
	t = cImg.h;
	cImg.w *= 1 + reSizeWidth;
	cImg.h *= 1 + reSizeWidth;
	l = (cImg.w - l) /2;
	t = (cImg.h - t) /2;
	var ll,tt;
	ll = parseInt(cImg.style.left);
	tt = parseInt(cImg.style.top);
	if(ll.toString() == "NaN")ll = 0;
	if(tt.toString() == "NaN")tt = 0;
	ll -= l;
	tt -= t;
	cImg.style.left = ll + 0.4;
	cImg.style.top = tt + 0.4;
	
	cImg.width = cImg.w;
	cImg.height = cImg.h;
	
	//var w = cImg.width * 1.02;
	//cImg.width = w;
	//cImg.height *= 1.02;
	setTimeout("bSize()",reSizeSpeed);
}
function bSizeEnd()
{
	bSizeing = false;
}
//小
function sSize()
{
	checkHaveCImg();
	if(window.event)
	{
		sSizeing = true;
	}
	if(!sSizeing)return;
	cImg.onload = null;
	if(cImg.w == null)cImg.w = cImg.width;
	if(cImg.h == null)cImg.h = cImg.height;
	//cImg.w *= 0.98;
	//cImg.h *= 0.98;
	
	var l,t;
	l = cImg.w;
	t = cImg.h;
	cImg.w *= 1 - reSizeWidth;
	cImg.h *= 1 - reSizeWidth;
	l = (l - cImg.w) /2;
	t = (t - cImg.h) /2;
	var ll,tt;
	ll = parseInt(cImg.style.left);
	tt = parseInt(cImg.style.top);
	if(ll.toString() == "NaN")ll = 0;
	if(tt.toString() == "NaN")tt = 0;
	ll += l;
	tt += t;
	
	cImg.style.left = ll - 0.7;
	cImg.style.top = tt - 0.7;
	
	var w,h;
	l = parseInt(cImg.style.left);
	t = parseInt(cImg.style.top);
	w = parseInt(cImg.width);
	h = parseInt(cImg.height);
	if(l.toString() == "NaN") l = 0;
	if(t.toString() == "NaN") t = 0;
	if(w.toString() == "NaN") w = 0;
	if(h.toString() == "NaN") h = 0;
	if(l + w < 10 || t + h < 10 )
	{
		l *= 0.3;
		t *= 0.3;
	}
	if(l > iframeWidth - 50 | t > iframeWidth - 50)
	{
		l *= 0.7;
		t *= 0.7;
	}
	cImg.style.left = l;
	cImg.style.top = t;
	
	if(w > 50 && h > 50)
	{
		cImg.width = cImg.w;
		cImg.height = cImg.h;
		setTimeout("sSize()",reSizeSpeed);
	}
	
}
function sSizeEnd()
{
	sSizeing = false;
}
//实际大小
function realSize()
{
	checkHaveCImg();
	cImg.onload = null;
	cImg.style.left = 0;
	cImg.style.top = 0;
	cImg.width = cW;
	cImg.height = cH;
	cImg.w = cImg.width;
	cImg.h = cImg.height;
}
//适合大小
function defaultSize()
{
	checkHaveCImg();
	cImg.onload = null;
	showBigImageForGoodsImagePage(cuIndex);
}
//ＲＥＳＩＺＥ加速
function addReSizeSpeed()
{
	reSizeSpeed = reSizeSpeed1;
	reSizeWidth = reSizeWidth1;
}
//ＲＥＳＩＺＥ减速
function subReSizeSpeed()
{
	reSizeSpeed = reSizeSpeed2;
	reSizeWidth = reSizeWidth2;
}
var s;
function initImageLayer()
{
	var imageLayer = null;
	imageLayer = document.getElementById("divStayTopLeft")
	imageLayer.style.display = "";
}

