/*
Name:				MtActiveImg ( isAlone )
Function:			多图或单图放大特效
Arguments:			isAlone:是否是单图放大
Date:				2009-3-13
Author:				mataofq@163.com
Modify:				优化图片展现速度

*/

function MtActiveImg (isAlone)
{
	this.imgs = [];//以数组形式存储图片地址：{"小图地址","大图地址"}
	this.data = [];//设定要回传的图片数组
	this.isLoaded = false;//html内容是否加载
	this.bgColors = [];//回传的换肤颜色
	this.deBug = function ()
	{
		document.getElementById('ipt').value = (arguments[0] + ':failed');
		return;
	}
	if (typeof isAlone != 'boolean')
	{
		this.init();
	}
	else
	{
		this.alone=isAlone;//初始化时设定是否单图放大
		this.initAlone();
	}
}

MtActiveImg.prototype = {
	//初始化多图页面元素
	init: function ()
	{
		this.writeStyle();
		this.writeHtml();
		if (!this.isLoaded)
		{
			this.deBug('LoadXHTML');
			return;
		}
		this.nowImgIndex = 0;//记录当前鼠标事件触发的图片索引
		this.sltWrap = document.getElementById('m_sltimg');//获取控制缩略图外围对象
		this.bimgWrap = document.getElementById('m_bimgwrap');//获取中图外围对象
		this.moveLayer = document.getElementById('m_movelayer');//获取控制移动小方块儿对象
		this.moveWrap = document.getElementById('m_movewrap');//获取移动小方块儿的外围对象
		this.showWrap = document.getElementById('m_showwrap');//获取放大图外围对象
	},

	//初始化单图页面元素
	initAlone: function ()
	{
		this.writeStyle();
		this.writeHtml();
		if (!this.isLoaded)
		{
			this.deBug('LoadXHTML');
			return;
		}
		this.nowImgIndex = 0;//记录当前鼠标事件触发的图片索引
		this.bimgWrap = document.getElementById('m_bimgwrap');//获取中图外围对象
		this.moveLayer = document.getElementById('m_movelayer');//获取控制移动小方块儿对象
		this.moveWrap = document.getElementById('m_movewrap');//获取移动小方块儿的外围对象
		this.showWrap = document.getElementById('m_showwrap');//获取放大图外围对象
	},

	//输出样式
	writeStyle: function ()
	{
		var styleStr = '<style type="text/css">'
			+'#m_styleId{height:232px;overflow:hidden;font-size:12px;}'
			+'#m_styleId *{margin:0;padding:0;}'
			+'#m_styleId ul,#m_styleId li{list-style:none;}'
			+'#m_bimgSrc{display:block;width:230px;height:230px;}'
			+'#m_movewrap{float:left;border:1px solid #666666;margin-right:10px;position:relative;width:230px;height:230px;cursor:default;}'
			+'#m_showwrap img{display:absolute;position:absolute;background-color:#FFFFFF;}'
			+'#m_movelayer{position:absolute;top:0;left:0;width:87px;height:65px;background:yellow;filter:alpha(opacity=40);visibility:hidden;opacity:0.4;z-index:10;cursor:move;}'
			+'#m_showwrap{display:block;position:absolute;left:240px;top:-1px;width:304px;height:228px;border:1px solid #666666;z-index:10000;overflow:hidden;visibility:hidden;}'
			if(!!this.alone)
			{
				styleStr += '</style>';
				document.write(styleStr);
				return;
			}
		styleStr += '#m_showwrap{display:block;position:absolute;left:305px;top:-1px;width:304px;height:228px;border:1px solid #666666;z-index:10000;overflow:hidden;visibility:hidden;}'
			+'#m_sltimg{float:left;}'
			+'#m_sltimg li{width:48px;height:48px;vertical-align:bottom;font-size:0;margin-bottom:10px;border:1px solid #666666;}'
			+'#m_sltimg .on{border-color:#FF5400;}'
			+'#m_sltimg a{position:relative;display:block;text-decoration:none;width:48px;height:48px;cursor:default;}'
			+'#m_sltimg a b{display:block;position:absolute;top:1px;left:1px;z-index:80;height:46px;width:46px;cursor:pointer;}'
			+'#m_sltimg img{padding:1px;display:block;vertical-align:bottom;cursor:pointer;width:46px;height:46px;border:none;}'
			+'#m_sltimg a span{display:block;position:absolute;top:2px;padding:0 3px;right:2px;color:#FFFFFF;cursor:pointer;font-size:12px;visibility:hidden;z-index:100;}'
			+'#m_sltimg a:hover{background:none;}'
			+'#m_sltimg a:hover span{visibility:visible;background:#FF5400;}'
			+'</style>';
		document.write(styleStr);
	},

	//输出html
	writeHtml: function ()
	{
		var htmlStr =  '<div id="m_styleId">'
			+'<div id="m_movewrap">'
				+'<div id="m_bimgwrap"></div>'//左侧图片区域
				+'<div id="m_movelayer"></div>'//移动小块儿
				+'<div id="m_showwrap"></div>'//大图呈现区域
			+'</div>';
			//多图时显示右侧图片列表
			!!this.alone?htmlStr+='<div style="clear:both;height:0;overflow:hidden;font-size:0;line-height:0;"/></div>':htmlStr+='<div id="m_sltimg"><ul><li><a href="javascript:void(0)"></a></li><li><a href="javascript:void(0)"></a></li><li><a href="javascript:void(0)"></a></li><li><a href="javascript:void(0)"></a></li><li><a href="javascript:void(0)"></a></li></ul></div></div>';
		document.write(htmlStr);
		this.isLoaded = true;
	},

	//加载初始化多张图片
	loadImg: function ()
	{
		var argRule = !!eval('('+arguments[0]+')').sImg && !!eval('('+arguments[0]+')').bImg;
		if (arguments.length>4 || arguments.length==0 || !argRule)
		{
			this.deBug('LoadImg');
			return false;
		}
		else
		{
			for (var i=0; i<arguments.length; i++)
			{
				this.imgs[i] = eval("("+arguments[i]+")");
				this.createMimg(i,this.imgs[i].bImg);
			}
		}
		this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[0].bImg +'"/>';//初始化左侧中图
		var temp = new Image();
		temp.src = this.imgs[0].bImg;
		temp.id = 'm_showimg';
		this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
		this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
		this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
		this.sltImgBindEvent(false,false);
		if(temp.complete)
		{
		    this.scaleImg();
			return;
		}
		thisObj = this;
		temp.onload = function ()
		{
		    thisObj.scaleImg();
		}
	},
	
	//加载初始化单张图片
	loadAlnImg: function ()
	{
		var argRule = !!eval('('+arguments[0]+')').sImg && !!eval('('+arguments[0]+')').bImg;
	    if (arguments.length==0 || arguments.length>1 || !argRule)
		{
			this.deBug('LoadImg');
			return false;
		}
		this.imgs[0] = eval("("+arguments[0]+")");
		this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[0].bImg +'"/>';//初始化左侧中图
		var temp = new Image();
		temp.src = this.imgs[0].bImg;
		temp.id = 'm_showimg';
		this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
		this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
		this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
		this.mImgBindEvent();
		if(temp.complete)
		{
		    this.scaleImg();
			return;
		}
		thisObj = this;
		temp.onload = function ()
		{
		    thisObj.scaleImg();
		}
	},

	//加载换肤多张图片
	loadClrImg: function ()
	{
	    var argRule = !!eval('('+arguments[0]+')').sImg && !!eval('('+arguments[0]+')').bImg;
		if (arguments.length>4 || arguments.length==0 || !argRule)
		{
			this.deBug('LoadImg');
			return false;
		}
		else
		{
			for (var i=0; i<arguments.length; i++)
			{
				this.imgs[i] = eval("("+arguments[i]+")");
				//this.createMimg(i,this.imgs[i].bImg);
				var tmp = document.createElement('img');				//tmp.style.backgroundColor = this.imgs[i].bgClr;
				tmp.src = this.imgs[i].bImg;
				this.sltWrap.getElementsByTagName('a')[i].appendChild(tmp);
				tmp = null;
			}
		}
		this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[0].bImg +'"/>';//初始化左侧中图
		var temp = new Image();
		temp.src = this.imgs[0].bImg;
		temp.id = 'm_showimg';
		this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
		this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
		this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
		this.sltBgBindEvent();
		if(temp.complete)
		{
		    this.scaleImg();
			return;
		}
		thisObj = this;
		temp.onload = function ()
		{
		    thisObj.scaleImg();
		}
	},

	//色块绑定事件
	sltBgBindEvent: function ()
	{
	    this.mImgBindEvent();
		var thisObj = this;
		var sltBg = document.getElementById('m_sltimg').getElementsByTagName('img');
		var sltLis = document.getElementById('m_sltimg').getElementsByTagName('li');
		for (i=0; i<sltBg.length; i++)
		{
			sltBg[i].onmouseover = function (i)
			{
				return function ()
				{
					if(thisObj.nowImgIndex == i) 
					{
						sltLis[i].className = 'on';
						return;
					}
					else
					{
						sltLis[thisObj.nowImgIndex].className = ''
						sltLis[i].className = 'on';
						var temp = new Image();
						temp.src = thisObj.imgs[i].bImg;
						temp.id = 'm_bimgSrc';
						thisObj.bimgWrap.firstChild==null?thisObj.bimgWrap.appendChild(temp):thisObj.bimgWrap.replaceChild(temp,thisObj.bimgWrap.firstChild);
						thisObj.staticImg = document.getElementById('m_bimgSrc');//重新获取左侧中图对象
						var tmp = new Image();
						tmp.src = thisObj.imgs[i].bImg;
						tmp.id = 'm_showimg';
						thisObj.showWrap.replaceChild(tmp,thisObj.showWrap.firstChild);
						temp = null;
						thisObj.showImg = document.getElementById('m_showimg');//获取放大后大图对象
						thisObj.scaleImg();
						thisObj.nowImgIndex = i;
						thisObj.mImgBindEvent();
					}
				}
			}(i)
		}
	},

	//显示中图和大图
	//argIndex:缩略图外框的索引
	//bSrc:该位置显示大图url
	//hasDel:是否输出删除按钮
	createMimg: function (argIndex,bSrc,hasDel,hasClr,bgClr)
	{
		var tempPar = this.sltWrap.getElementsByTagName('li')[argIndex].getElementsByTagName('a')[0];
		var temp = document.createElement('img');
		temp.src = bSrc;
		if(tempPar.firstChild==null)
		{
			tempPar.appendChild(temp);
			if(!!hasDel)
			{
				temp = document.createElement('span');
				temp.innerHTML = '×';
				tempPar.appendChild(temp);
			}
			if(!!hasClr)
			{
				temp = document.createElement('span');
				temp.innerHTML = '+';
				temp.style.top = '31px';
				tempPar.appendChild(temp);
				temp = document.createElement('b');
				temp.style.backgroundColor = bgClr;
				tempPar.appendChild(temp);
			}
		}
		else
		{
			tempPar.replaceChild(temp,this.firstChild);
		}
		temp = null;
	},

	//遍历缩略图绑定事件
	//canDel:是否显示删除提示
	sltImgBindEvent: function (canDel,hasClr)
	{
		this.mImgBindEvent();
		var thisObj = this;
		var sltAs = document.getElementById('m_sltimg').getElementsByTagName('a');
		var sltLis = document.getElementById('m_sltimg').getElementsByTagName('li');
		for (i=0; i<sltAs.length; i++)
		{
			sltAs[i].onmouseover = function (i)
			{
				return function ()
				{
					if (canDel)
					{
						if(!sltLis[i].getElementsByTagName('span')[0]) return;
						sltLis[i].getElementsByTagName('span')[0].onclick = function (i)
						{
							return function ()
							{
								thisObj.delImg(sltLis[i].getElementsByTagName('a')[0]);
							}
						}(i)
					}
					if (hasClr)
					{
						sltLis[i].getElementsByTagName('span')[1].onclick = function (i)
						{
							return function ()
							{
								var getColor = showModalDialog("selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
								var tmp = document.createElement('b');
								tmp.style.backgroundColor = getColor;
								this.parentNode.appendChild(tmp);
								//this.parentNode.removeChild(this);
								thisObj.bgColors[i] = getColor;//按顺序记录填充颜色
								thisObj.setData(thisObj.dataID,true);
							}
						}(i)
					}
					if(thisObj.nowImgIndex == i) 
					{
						sltLis[i].className = 'on';
						return;
					}
					else
					{
						sltLis[thisObj.nowImgIndex].className = ''
						sltLis[i].className = 'on';
						var temp = new Image();
						temp.src = thisObj.imgs[i].sImg;
						temp.id = 'm_bimgSrc';
						thisObj.bimgWrap.firstChild==null?thisObj.bimgWrap.appendChild(temp):thisObj.bimgWrap.replaceChild(temp,thisObj.bimgWrap.firstChild);
						thisObj.staticImg = document.getElementById('m_bimgSrc');//重新获取左侧中图对象
						var tmp = new Image();
						tmp.src = thisObj.imgs[i].bImg;
						tmp.id = 'm_showimg';
						thisObj.showWrap.replaceChild(tmp,thisObj.showWrap.firstChild);
						temp = null;
						thisObj.showImg = document.getElementById('m_showimg');//获取放大后大图对象
						thisObj.scaleImg();
						thisObj.nowImgIndex = i;
						thisObj.mImgBindEvent();
					}
				}
			}(i)
		}
	},

	//缩放大图显示比例
	scaleImg: function ()
	{
		var staticImgWidth = this.staticImg.offsetWidth, staticImgHeight = this.staticImg.offsetHeight,
			moveLayerWidth = this.moveLayer.offsetWidth, moveLayerHeight = this.moveLayer.offsetHeight,
			showWrapWidth = this.showWrap.clientWidth, showWrapHeight = this.showWrap.clientHeight,
			showImgWidth = this.showImg.offsetWidth, showImgHeight = this.showImg.offsetHeight;
		if (showImgHeight < staticImgHeight && showImgWidth < staticImgWidth)
		{
			var padLeft = showWrapWidth/moveLayerWidth*(staticImgWidth - showImgWidth)/2;
			var padTop = showWrapHeight/moveLayerHeight*(staticImgHeight - showImgHeight)/2;
			this.showImg.style.padding = padTop + 'px ' + padLeft +'px';
			this.showImg.style.width =  showWrapWidth/moveLayerWidth*showImgWidth + 'px';
			this.showImg.style.height =  showWrapHeight/moveLayerHeight*showImgWidth + 'px';
		}
		else
		{
			if (showImgHeight > showImgWidth)
			{
				var padLeft = showWrapWidth/moveLayerWidth*(staticImgWidth - showImgWidth*staticImgHeight/showImgHeight)/2;
				this.showImg.style.height = staticImgHeight/moveLayerHeight*showWrapHeight + 'px';
				this.showImg.style.width = showImgWidth*parseInt(this.showImg.style.height)/showImgHeight + 'px';
				this.showImg.style.padding = '0 ' + padLeft +'px';
			}
			else
			{
				var padTop = staticImgHeight/moveLayerHeight*(staticImgHeight - showImgHeight*staticImgWidth/showImgWidth)/2;
				this.showImg.style.padding = padTop +'px' + ' 0' ;
				this.showImg.style.width = staticImgWidth/moveLayerWidth*showWrapWidth + 'px';
				this.showImg.style.height = showImgHeight*parseInt(this.showImg.style.width)/showImgWidth + 'px';
			}
		}
	},

	//移动缩放大图
	moveImgview: function ()
	{
		this.showWrap.style.visibility = 'visible';
		var showImgHeight = this.showImg.offsetHeight, showImgWidth = this.showImg.offsetWidth, 
			moveWrapHeight = this.moveWrap.offsetHeight, moveWrapWidth = this.moveWrap.offsetWidth, 
			moveLayerTop = parseInt(this.moveLayer.style.top), moveLayerLeft = parseInt(this.moveLayer.style.left);
		this.showImg.style.top = -1*showImgHeight/moveWrapHeight*moveLayerTop  + 'px';
		this.showImg.style.left = -1*showImgWidth/moveWrapWidth*moveLayerLeft + 'px';
	},

	//还原移动窗口和大图视图状态
	defaultView: function()
	{
		this.moveLayer.style.visibility = 'hidden';
		this.showWrap.style.visibility = 'hidden';
	},

	//给中图绑定事件
	mImgBindEvent: function ()
	{
		var thisObj = this;
		this.staticImg.onmouseover = function (e)
		{
			var evt = e || window.event;
			var _top = evt.clientY - thisObj.moveWrap.offsetTop - thisObj.moveLayer.offsetHeight/2 + parseInt(document.documentElement.scrollTop);
			var maxTop = thisObj.moveWrap.clientHeight - thisObj.moveLayer.offsetHeight;
			var _left = evt.clientX - thisObj.moveWrap.offsetLeft - thisObj.moveLayer.offsetWidth/2;
			var maxLeft = thisObj.moveWrap.offsetWidth - thisObj.moveLayer.offsetWidth;
			thisObj.moveLayer.style.top = (_top<=0?0:_top>maxTop?maxTop:_top) + 'px';
			thisObj.moveLayer.style.left = (_left<=0?0:_left>maxLeft?maxLeft:_left) + 'px';
			thisObj.moveLayer.style.visibility = 'visible';
			thisObj.moveLayerBindEvent(maxTop,maxLeft);
		}
	},

	//给移动方块儿绑定事件
	moveLayerBindEvent: function (maxTop,maxLeft)
	{
		var thisObj = this;
		var moveWrapTop = this.moveWrap.offsetTop - parseInt(document.documentElement.scrollTop), moveWrapLeft = this.moveWrap.offsetLeft,
			moveLayerHeight = this.moveLayer.clientHeight, moveLayerWidth = this.moveLayer.clientWidth;
		this.moveLayer.onmousemove = function (e)
		{
			var evt = e || window.event;
			this.onmouseout = function ()
			{
				thisObj.defaultView();
				this.onmousemove = null;
			}
			if(evt.clientY - moveWrapTop - moveLayerHeight/2 <= 0)
			{
				this.style.top = 0;
			}
			else
			{
				if ((evt.clientY - moveWrapTop - moveLayerHeight/2) > maxTop)
				{
					this.style.top = maxTop + 'px';
				}
				else
				{
					this.style.top = evt.clientY - moveWrapTop - moveLayerHeight/2 + 'px';
				}
			}
			if(evt.clientX - moveWrapLeft - moveLayerWidth/2 <= 0)
			{
				this.style.left = 0;
			}
			else
			{
				if ((evt.clientX - moveWrapLeft - moveLayerWidth/2) > maxLeft)
				{
					this.style.left = maxLeft + 'px';
				}
				else
				{
					this.style.left = evt.clientX - moveWrapLeft - moveLayerWidth/2 + 'px';
				}
			}
		thisObj.moveImgview();
		}
	},

	//增加多图显示的图片
	//imgObj:如-"{sImg:"test1.jpg",bImg:"test11.jpg"}"格式的JSON，sImg是小图地址，bImg是大图地址
	//dataId:要输出图片数组的表单域ID
	addImg: function (imgObj,dataId)
	{
		var argRule = !!eval('('+imgObj+')').sImg && !!eval('('+imgObj+')').bImg;
		if (2 != arguments.length || !argRule)
		{
			this.deBug('AddArg');
			return false;
		}
		var thisObj = this;
		this.dataID = dataId;
		for (var i=0; i<4; i++)
		{
			if(!this.imgs[i])
			{
				this.imgs[i] = eval('('+arguments[0]+')');
				this.createMimg(i,this.imgs[i].bImg,true);
				this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[i].bImg +'"/>';//初始化左侧中图
				this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
				var temp = new Image();
				temp.src = this.imgs[i].bImg;
				temp.id = 'm_showimg';
				if (temp.complete)
				{
					this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
					this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
					this.scaleImg();
					this.sltImgBindEvent(true);
					this.setData(this.dataID);
					this.nowImgIndex ++;
					return;
				}
				temp.onload = function ()
				{
					thisObj.showWrap.firstChild==null?thisObj.showWrap.appendChild(temp):thisObj.showWrap.replaceChild(temp,thisObj.showWrap.firstChild);
					thisObj.showImg = document.getElementById('m_showimg');//获取放大后大图对象
					thisObj.scaleImg();
					thisObj.sltImgBindEvent(true);
					temp = null;
					thisObj.nowImgIndex ++;
					thisObj.setData(thisObj.dataID);
				}
				return;
			}
		}
		this.deBug('AddImg');
		return;
	},

	//增加单图显示图片
	addAlnImg: function (imgObj,dataId)
	{
		var argRule = !!eval('('+imgObj+')').sImg && !!eval('('+imgObj+')').bImg;
		if (2 != arguments.length || !argRule)
		{
			this.deBug('AddArg');
			return false;
		}
	    this.imgs[0] = eval("("+arguments[0]+")");
		this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[0].bImg +'"/>';//初始化左侧中图
		var temp = new Image();
		temp.src = this.imgs[0].bImg;
		temp.id = 'm_showimg';
		this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
		temp = null;
		this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
		this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
		this.scaleImg();
		this.mImgBindEvent();
		this.setData(dataId);
	},

	//增加色块显示图片
	addClrImg: function (imgObj,dataId,bgCls)
	{
	    var argRule = !!eval('('+imgObj+')').sImg && !!eval('('+imgObj+')').bImg;
		if (3 != arguments.length || !argRule)
		{
			this.deBug('AddArg');
			return false;
		}
		this.bgColors.push(bgCls);
		var thisObj = this;
		this.dataID = dataId;
		for (var i=0; i<4; i++)
		{
			if(!this.imgs[i])
			{
				this.imgs[i] = eval('('+arguments[0]+')');
				this.createMimg(i,this.imgs[i].bImg,true,true,bgCls);
				this.bimgWrap.innerHTML = '<img id="m_bimgSrc" src="'+ this.imgs[i].bImg +'"/>';//初始化左侧中图
				this.staticImg = document.getElementById('m_bimgSrc');//获取中图对象
				var temp = new Image();
				temp.src = this.imgs[i].bImg;
				temp.id = 'm_showimg';
				if (temp.complete)
				{
					this.showWrap.firstChild==null?this.showWrap.appendChild(temp):this.showWrap.replaceChild(temp,this.showWrap.firstChild);
					this.showImg = document.getElementById('m_showimg');//获取放大后大图对象
					this.scaleImg();
					this.sltImgBindEvent(true,true);
					this.setData(this.dataID,true);
					this.nowImgIndex ++;
					return;
				}
				temp.onload = function ()
				{
					thisObj.showWrap.firstChild==null?thisObj.showWrap.appendChild(temp):thisObj.showWrap.replaceChild(temp,thisObj.showWrap.firstChild);
					thisObj.showImg = document.getElementById('m_showimg');//获取放大后大图对象
					thisObj.scaleImg();
					thisObj.sltImgBindEvent(true,true);
					temp = null;
					thisObj.nowImgIndex ++;
					thisObj.setData(thisObj.dataID,true);
				}
				return;
			}
		}
		this.deBug('AddImg');
		return;
	},

	//删除图片
	//target:要删除里边图片的LI
	delImg: function (target)
	{
		delete this.imgs[this.nowImgIndex];
		target.parentNode.className = '';
		target.innerHTML = '';
		this.bimgWrap.innerHTML = '';
		if (this.bgColors.length>0)
		{
		    delete this.bgColors[this.nowImgIndex];
			this.setData(this.dataID,true);
			return;
		}
		this.setData(this.dataID);
	},

	//设置表单域
	setData: function (inputId,hasCls)
	{
		var imgStr=[];
		var formInput = document.getElementById(inputId);
		if (!formInput)
		{
			this.deBug('SubmitForm');
			return false;
		}
		for ( var i=j=0; i<this.imgs.length; i++)
		{
			if(this.imgs[i] != undefined)
			{
				imgStr[j]= 'sImg:"'+this.imgs[i].sImg+'",bImg:"'+this.imgs[i].bImg+'"';
				if(!!hasCls) imgStr[j] += '",bgClr:"'+this.bgColors[i]+'"';
				j++;
			}
		}
		formInput.value = imgStr.join('|');
	}
}
