var img_bump = new Array();
//0:本地图片的原始长度, 1:本地图片的原始高度, 2:Table所在层的初始左偏移, 3:Table所在层的初始上偏移, 4:Table的中间单元格的长度, 5:Table的中间单元格的高度  6:Table的中间单元格的Left  7:Table的中间单元格的Top(如果在原图情况下虚线框没有完全吻合图片的长度和宽度，调节6,7两个参数)   8:在原图状态下，初始时图片不能操作当前Table框的最大倍数  9:虚线框的缩小倍数
var SizeParaArray = new Array(0, 0, 240, -250, 240, 175, 3, 26, 3, -1)
var DragDivPara = new Array(); //图片开始缩放时DragDiv的位置参数集和;
var ScaleTimeID = null;
var PreviewImageWidth = new Array();
var PreviewImageHeight = new Array();
var OriginImgSize = new Array();  //用来存放图片的原始大小的集和
var PreviewRatio = new Array();  //  裁剪框的X轴位置   裁剪框的Y轴位置  整体图片的缩放比例
var CurOperateDivID = -1;  //当前焦点落在哪个缩放窗口
var TopestIndex = 1000;
var E7; //是否是IE7(IE7禁止读取本地图片)
E7 = navigator.userAgent.toLowerCase();
if(E7.indexOf('msie 7')!=-1) E7 = true; else E7 = false;
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
    document.writeln('</scr' + 'ipt>');
}

//Width1, Height1:如果为空或为0，表示不出现裁减框
function preview_me(FileInput1, Width1, Height1, Para1, PathStr, IdIndex, IframeName){
	var str, ext, Indexs, path1, path2, obj, DivObj, DivHandle, FuncHandle, IframeHandle, FrameStr, input_obj, tmp, tmp1, tmp2, IconExist;
	var file_type = new Array("jpg|jpeg|gif|bmp|png|tif|iff","swf|swi","mp3|m3u|wav|wma|wax|asx|mp2|au|aif|aiff|mid|midi|rmi","rm|rmvb|ram|ra|mov","mpg|mpeg|mpv|mps|m2v|m1v|mpe|mpa|avi|wmv|wm|wmx|wvx|asf","asa|asp|bat|cmd|code|com|db|dll|doc|exe|fla|ftp|h|hlp|htm|html|inc|info|ini|js|log|mdb|pdf|php|pic|ppt|rar|real|torrent|txt|xls|xml|zip");
	eval('input_obj=document.'+FileInput1);
	PreviewImageWidth[IdIndex] = Width1;
	PreviewImageHeight[IdIndex] = Height1;
	ext = GetFileSuff(input_obj.value);
	Indexs = -1
	if(img_bump[IdIndex]) img_bump[IdIndex].removeNode(true);
	for(var i=0;i<file_type.length;i++){
		str = file_type[i].split('|');
		for(var ii=0;ii<str.length;ii++){
			if(str[ii]==ext.toLowerCase()){
				Indexs = i;
				break;
			}
		}
	}
	if(IframeName!=''){//有iframe存在,发出调用的页面和函数执行的页面不在同一级,如文章录入,发出调用的页面在article下,二运行函数在主窗口下,如果没有iframe处在,则视为两者在一个级上
		IframeHandle = 'parent.';

		if(PathStr.indexOf('|')==-1){
			path1 = '../'+PathStr;
			path2 = PathStr;
		}else{
			tmp = PathStr.split('|');
			path1 = '../'+tmp[0];

			path2 = tmp[1];
		}
		DivObj = parent.document.getElementById('dragDiv'+IdIndex);
		FuncHandle = IframeName+'.';
	}else{
		IframeHandle = '';
		path1 = PathStr;
		path2 = PathStr;
		//PathStr = '../'+PathStr;
		DivObj = document.getElementById('dragDiv'+IdIndex);
		FuncHandle = '';
	}
	if(DivObj==null){
		if(IframeName!=''){
			DivObj = parent.document.createElement('div');
			parent.document.getElementById('DivCont').appendChild(DivObj);
			DivHandle = 'parent.'
		}else{
			DivObj = document.createElement('div');
			document.body.appendChild(DivObj);
			DivHandle = '';
		}
		DivObj.id = 'dragDiv'+IdIndex;
		DivObj.style.position = 'absolute';
		TopestIndex = TopestIndex+1
		DivObj.style.zIndex = TopestIndex;
		DivObj.style.width = 0;
		DivObj.style.height = 0;
		//确定层的定位
		tmp2 = new Array(new Array(-80, -80, -65, -80, -80, -80), new Array(15, 37, 25, 20, 20, 15))
		if(IframeName!=''){
			tmp = parent.document.getElementById(IframeName);
			if(tmp==null) alert('iframe的id不对');
			tmp = GetObjPos(tmp);
			tmp1 = document.getElementById('img_icon'+IdIndex);
			if(tmp1==null) alert('img_icon的id不对');
			tmp1 = GetObjPos(tmp1);
		}else{
			tmp = new Array(0, 0, 0, 0);
			tmp1 = document.getElementById('img_icon'+IdIndex);
			if(tmp1==null) alert('img_icon的id不对');
			tmp1 = GetObjPos(tmp1);
		}
		if(Indexs==-1){;
			DivObj.style.left = tmp[0]+tmp1[0]+tmp2[0][5];
			DivObj.style.top = tmp[1]+tmp1[1]+tmp2[1][5];
			DivObj.style.display = 'none';
		}else{
			DivObj.style.left = tmp[0]+tmp1[0]+tmp2[0][Indexs];
			DivObj.style.top = tmp[1]+tmp1[1]+tmp2[1][Indexs];
		}
	}else{
		//这里有一种可能性，第一次选择上传文件,由于文件后缀未知,致使Indexs为-1;,同时DivObj已生成了对象,不再是null,那么当下次选择上传文件时,要设定DivObj.style.left,DivObj.style.top,因为他们根本就未被设定,造成欲览框不可见
		if(IframeName!=''){
			parent.document.getElementById('dragDiv'+IdIndex).style.display = 'block';
		}else{
			document.getElementById('dragDiv'+IdIndex).style.display = 'block';
		}
	}

	FrameStr = '' //如果在父窗口显示预览框,需要增加的一些字符
	if(IframeName!=''){
		FrameStr = 'cursor:move;'
	}
	DivObj.innerHTML = '<div></div>';
	//IconExist:有时用想用自己的图片,不用默认的icon_img.gif图标
	if(document.getElementById('img_icon'+IdIndex).innerHTML!=''){
		IconExist = document.getElementById('img_icon'+IdIndex).firstChild.src;
		document.getElementById('img_icon'+IdIndex).style.visibility = 'visible';
	}else{
		IconExist = '';
	}
	switch(Indexs){
		case 0:
			img_bump[IdIndex]=document.createElement("img");
			DivObj.innerHTML = '<table width="250" border="1" onmousedown="'+FuncHandle+'FocusDiv('+IdIndex+', this)" cellpadding="0" cellspacing="3" CheckValid="" style="display:none;position:absolute;left:'+SizeParaArray[2]+'px;top:'+SizeParaArray[3]+'px;background-color:#F2F9FF;border-color:#CCCCCC;"><tr><td width="100%" align="center" height="14" colspan="3"><table width="100%" style="table-layout:fixed;"><tr><td class="handle" handlefor="dragDiv'+IdIndex+'" align="center" style="line-height:12px;overflow:hidden;'+FrameStr+'"></td><td width="18" align="right"><a onClick="'+FuncHandle+'preview_show(\'img\', \''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')" onFocus="this.blur();" style="cursor:hand;""><img src="'+path2+'Close.gif" align="absmiddle" border="0"></a></td></tr></table></td></tr><tr><td colspan="3" height="'+SizeParaArray[5]+'" align="center"></td></tr><tr><td colspan="3"><div id="ThumbHandle'+IdIndex+'" style="position:absolute;z-index:10;border:#000000 1px dotted;top:26px;left:3px;display:none"><img src="'+path2+'white.gif" handlefor="ThumbHandle'+IdIndex+'" class="handle" style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30);'+FrameStr+'"></div></td></tr><tr><td style="display:none" width="32"><input type="radio" value="thumb" name="PreviewType'+IdIndex+'" checked onClick="'+FuncHandle+'ChangePreviewType(0, '+IdIndex+', \''+IframeName+'\')">缩</td><td align="center" id="ImgContents">&nbsp;</td><td style="display:none;text-align:right;" width="32"><input type="radio" value="normal" name="PreviewType'+IdIndex+'" onClick="'+FuncHandle+'ChangePreviewType(1, '+IdIndex+', \''+IframeName+'\')">原</td></tr><tr style="display:none"><td height="16" colspan="3" style="background:url('+path2+'scale.gif) no-repeat center center;"></td></tr></table><div onmousedown="'+FuncHandle+'ScaleBump('+IdIndex+', 1, \''+IframeName+'\');" onmouseup="'+FuncHandle+'ScaleOver('+IdIndex+', \''+IframeName+'\');" id="ScaleHandle'+IdIndex+'" style="position:absolute;z-index:11;left:0px;top:0px;display:none;'+FrameStr+'" class="moveme" handlefor="ScaleHandle'+IdIndex+'" ><img src="'+path2+'mover.gif"></div><iframe id="DivShim'+IdIndex+'" src="javascript:void(null);" scrolling="no" frameborder="0" style="position:absolute; top:'+SizeParaArray[3]+'px; left:'+SizeParaArray[2]+'px;width:250px;height:237px;display:none;z-index:-11;"></iframe>';

			if(IconExist!=path1+'icon_img.gif') IconExist = path1+'icon_img.gif';
			document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+IconExist+'" border="0" onFocus="this.blur();" onClick="preview_show(\'img\', \''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')" title="预览图片"  align="absmiddle">';
			PreviewRatio[IdIndex] = [0, 0, 1];
			if(E7){
				if(IframeName!='') obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild; else obj = document.getElementById('dragDiv'+IdIndex).firstChild;
				obj.rows[1].cells[0].innerHTML = '<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);width:10px;height:10px;"></div>';
				try{
					obj.rows[1].cells[0].firstChild.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = input_obj.value;
					eval(IframeHandle+'document.getElementById(\'dragDiv'+IdIndex+'\').firstChild.CheckValid=\'true\'');
					window.setTimeout('img_fit(\''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')', 200);
				}catch(e){}

			}else{
				img_bump[IdIndex].attachEvent('onreadystatechange', function(){if(img_bump[IdIndex].readyState=='complete');eval(IframeHandle+'document.getElementById(\'dragDiv'+IdIndex+'\').firstChild.CheckValid=\'true\'');img_fit(FileInput1, IdIndex, IframeName)});
				img_bump[IdIndex].src = input_obj.value;
			}
			current_img_type = 'img';
			break;
		case 1:
			if(IconExist!=path1+'icon_swf.gif') IconExist = path1+'icon_swf.gif';
			document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+IconExist+'" border="0" onFocus="this.blur();" onClick="alert(\'不能预览swf\')"  title="预览Flash" align="absmiddle">';
			current_img_type = 'swf';
			break;
		case 2:   //mp3
			DivObj.innerHTML = '<table width="250" border="1" cellpadding="0" cellspacing="3" style="display:none;position:absolute;left:'+SizeParaArray[2]+'px;top:'+SizeParaArray[3]+'px;background-color:#D8D8D8;border-color:#CCCCCC;"><tr><td align="center" class="handle" handlefor="dragDiv'+IdIndex+'" '+FrameStr+'><embed width="250" height="222" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" showstatusbar="0" showcontrols="1"  autostart="1" name="preview_media'+IdIndex+'" id="preview_media'+IdIndex+'"></embed></td></tr></table>';
			if(IframeName!='') obj = parent.document.getElementById('preview_media'+IdIndex); else obj = document.getElementById('preview_media'+IdIndex);
			obj.height = '67';
			DivObj.firstChild.style.top = '-100';
			if(IconExist=='') IconExist = path1+'icon_mp3.gif';
			document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+IconExist+'" border="0" onFocus="this.blur();" onClick="preview_show(\'mp3\', \''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')" title="预听音乐" align="absmiddle">';
			current_img_type = 'mp3';
			break;
		case 3:
			if(IconExist!=path1+'icon_real.gif') IconExist = path1+'icon_real.gif';
			if(detectActiveXControl('rmocx.RealPlayer G2 Control') ||detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)')){
				DivObj.innerHTML = '<table width="250" border="1" cellpadding="0" cellspacing="3" style="display:none;position:absolute;left:'+SizeParaArray[2]+'px;top:'+SizeParaArray[3]+'px;background-color:#D8D8D8;border-color:#CCCCCC;"><tr><td align="center" class="handle" handlefor="dragDiv'+IdIndex+'" '+FrameStr+'><object id="preview_real'+IdIndex+'" width="250" height="220" classid="CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"><PARAM NAME="CONSOLE" VALUE="one"><PARAM NAME="CONTROLS" VALUE="ImageWindow,StatusBar,ControlPanel"><PARAM NAME="autostart" VALUE="true"><param name="PREFETCH" value="true"></object></td></tr></table>'
				document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+IconExist+'" border="0" onFocus="this.blur();" onClick="preview_show(\'real\', \''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')" title="预览RealOne" align="absmiddle">';
				current_img_type = 'real';
				break;
			}else{
				document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+IconExist+'" border="0" onFocus="this.blur();" onClick="alert(\'尚未安装RealOne播放器\')" title="预览RealOne" align="absmiddle">';
				break;
			}
		case 4:
			DivObj.innerHTML = '<table width="250" border="1" cellpadding="0" cellspacing="3" style="display:none;position:absolute;left:'+SizeParaArray[2]+'px;top:'+SizeParaArray[3]+'px;background-color:#D8D8D8;border-color:#CCCCCC;"><tr><td align="center" class="handle" handlefor="dragDiv'+IdIndex+'" '+FrameStr+'><embed width="250" height="222" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" showstatusbar="0" showcontrols="1"  autostart="1" name="preview_media'+IdIndex+'" id="preview_media'+IdIndex+'"></embed></td></tr></table>';
			if(IframeName!='') obj = parent.document.getElementById('preview_media'+IdIndex); else obj = document.getElementById('preview_media'+IdIndex);
			obj.height = '220';
			DivObj.firstChild.style.top = '-250';
			if(IconExist!=path1+'icon_media.gif') IconExist = path1+'icon_media.gif';
			document.getElementById('img_icon'+IdIndex).innerHTML = '<img src="'+path1+'icon_media.gif" border="0" onFocus="this.blur();" onClick="preview_show(\'media\', \''+FileInput1+'\', '+IdIndex+', \''+IframeName+'\')" title="预览视频" align="absmiddle">';
			current_img_type = 'media';
			break;
		case 5:
			if(IconExist=='') document.getElementById('img_icon'+IdIndex).innerHTML = ''; else document.getElementById('img_icon'+IdIndex).style.visibility = 'hidden';
			current_img_type = 'file';
			break;
		default:
			current_img_type = '';
			if(IconExist=='') document.getElementById('img_icon'+IdIndex).innerHTML = ''; else document.getElementById('img_icon'+IdIndex).style.visibility = 'hidden';
	}
}

function FocusDiv(IdIndex, obj){
	var str, tmp;

	if(IdIndex!=CurOperateDivID){
		CurOperateDivID = IdIndex;
		SizeParaArray[0] = OriginImgSize[IdIndex][0];
		SizeParaArray[1] = OriginImgSize[IdIndex][1];
	}
}

//改变缩略图样式,如果原图比缩略图大,1:按比例将原图缩小成缩略图大小,虚线框只能水平或垂直移动. 2:原图大小有用户自己决定,虚线框可自由移动.
function ChangePreviewType(PreviewType, IdIndex, IframeName){
	var str, tmp, tmp1, obj, obj1, obj2, PreviewTypeObj, LeftPos, TopPos, CellWidth, CellHeight, InitImgW, InitImgH, DivShimObj;
	//如果尺寸大于规定值，则返回
	ratio = 1;
	if(IframeName!=''){
		obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild;
		DivShimObj = parent.document.getElementById('DivShim'+IdIndex);
	}else{
		obj = document.getElementById('dragDiv'+IdIndex).firstChild;
		DivShimObj = document.getElementById('DivShim'+IdIndex);
	}
	//判断是否可以还原图片
	if(IframeName!='') PreviewTypeObj = parent.document.getElementsByName('PreviewType'+IdIndex)[1]; else PreviewTypeObj = document.getElementsByName('PreviewType'+IdIndex)[1];
	if(IframeName!='') DivShimObj = parent.document.getElementById('DivShim'+IdIndex); else DivShimObj = document.getElementById('DivShim'+IdIndex);
	if(SizeParaArray[0]<=SizeParaArray[4]&&SizeParaArray[1]<=SizeParaArray[5]){
		PreviewTypeObj.disabled = true;
	}else{
		if(typeof(ThumbPara)!='undefined'){
			if(typeof(ThumbPara[5])!='undefined'&&ThumbPara[5]!='true') PreviewTypeObj.disabled = true;
		}
	}
	if(PreviewType==0){//点击缩
		obj.rows[4].style.display = 'none';
		if(IframeName!='') obj1 = parent.document.getElementById('ScaleHandle'+IdIndex); else obj1 = document.getElementById('ScaleHandle'+IdIndex);
		obj1.style.display = 'none';
		obj1.style.left = 0;
		obj1.style.top = 0;


		if(SizeParaArray[0]>SizeParaArray[4]||SizeParaArray[1]>SizeParaArray[5]) {
			if(SizeParaArray[0]/SizeParaArray[4]>SizeParaArray[1]/SizeParaArray[5]){
				ratio = SizeParaArray[4]/SizeParaArray[0];
				img_bump[IdIndex].height = SizeParaArray[1]*ratio;
				img_bump[IdIndex].width = SizeParaArray[4];
				LeftPos = 0;
				TopPos = (SizeParaArray[5]-img_bump[IdIndex].height)/2;
			}else{
				ratio = SizeParaArray[5]/SizeParaArray[1];
				img_bump[IdIndex].width = SizeParaArray[0]*ratio;
				img_bump[IdIndex].height = SizeParaArray[5];
				LeftPos = (SizeParaArray[4]-img_bump[IdIndex].width)/2;
				TopPos = 0;
			}
		}else{
			LeftPos = (SizeParaArray[4]-img_bump[IdIndex].width)/2;
			TopPos = (SizeParaArray[5]-img_bump[IdIndex].height)/2;
		}


		SetThumbHandle(img_bump[IdIndex].width, img_bump[IdIndex].height, SizeParaArray[4], SizeParaArray[5], LeftPos, TopPos, ratio, IdIndex, IframeName);
		if(IframeName!='') obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild; else obj = document.getElementById('dragDiv'+IdIndex).firstChild;
		if(E7){
			obj.rows[1].cells[0].firstChild.style.width = img_bump[IdIndex].width;
			obj.rows[1].cells[0].firstChild.style.height = img_bump[IdIndex].height;
			obj.rows[1].cells[0].firstChild.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
		}else{
			obj.rows[1].cells[0].innerHTML = '<img src="'+img_bump[IdIndex].src+'" width="'+img_bump[IdIndex].width+'" height="'+img_bump[IdIndex].height+'">';
		}
		obj.rows[1].cells[0].width = SizeParaArray[4];
		obj.rows[1].cells[0].height = SizeParaArray[5];

		DivShimObj.style.width = obj.offsetWidth;
		DivShimObj.style.height = obj.offsetHeight;
		DivShimObj.style.left = obj.offsetLeft;
		DivShimObj.style.top = obj.offsetTop;
	}
	if(PreviewType==1){//点击原,注意这里要考虑保持原图时设置的缩放比例,因为如果设置了缩放比例,则原图的尺寸要缩小成相等比例.
		if(SizeParaArray[0]>SizeParaArray[4]||SizeParaArray[1]>SizeParaArray[5]) obj.rows[4].style.display = 'block';
		if(IframeName!='') obj1 = parent.document.getElementById('ScaleHandle'+IdIndex); else obj1 = document.getElementById('ScaleHandle'+IdIndex);//下面的滑动块
		if(IframeName!='') obj2 = parent.document.getElementById('ThumbHandle'+IdIndex); else obj2 = document.getElementById('ThumbHandle'+IdIndex);//虚线框
		if(IframeName!='') obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild; else obj = document.getElementById('dragDiv'+IdIndex).firstChild;//最外面的div,包含着table
		PreviewRatio[IdIndex][0] = 0.5;
		PreviewRatio[IdIndex][1] = 0.5;

		obj1.style.display = 'block';
		//计算水平中心点，以obj为参照,其左上角为原点(LeftPos, TopPos),注意单元格,虚线框和原图之间的大小关系
		tmp = Math.max(SizeParaArray[4], PreviewImageWidth[IdIndex]);
		LeftPos = tmp/2;
		tmp1 =  Math.max(SizeParaArray[5]-2, PreviewImageHeight[IdIndex]);
		TopPos = tmp1/2;
		//设置缩放滑动块
		obj1.PosX = Math.floor(obj.style.pixelLeft+LeftPos-100);
		obj1.PosY = Math.ceil(obj.style.pixelLeft+LeftPos+100);
		obj1.style.left = obj.style.pixelLeft+LeftPos-100;
		obj1.style.top = obj.style.pixelTop+TopPos*2+64;
		obj1.style.display = 'block';
		obj1.axis = 'X';

		//处理虚线框,虚线框的坐标原点在obj的左上角,如果虚线框的大小大于当前单元格的大小,就放大单元格以适应虚线框,将虚线框放中间
		obj2.firstChild.width = PreviewImageWidth[IdIndex];
		obj2.firstChild.height = PreviewImageHeight[IdIndex];
		if(PreviewImageWidth[IdIndex]>SizeParaArray[4]){
			obj.rows[1].cells[0].width = PreviewImageWidth[IdIndex];
			CellWidth = PreviewImageWidth[IdIndex];
		}else{
			CellWidth = SizeParaArray[4];
		}
		if(PreviewImageHeight[IdIndex]>SizeParaArray[5]){
			obj.rows[1].cells[0].height = PreviewImageHeight[IdIndex];
			CellHeight = PreviewImageHeight[IdIndex];
		}else{
			CellHeight = SizeParaArray[5];
		}

		if(PreviewImageWidth[IdIndex]/SizeParaArray[0]>PreviewImageHeight[IdIndex]/SizeParaArray[1]){
			InitImgH = Math.round(PreviewImageHeight[IdIndex]);
			InitImgW = Math.round(SizeParaArray[0]*PreviewImageHeight[IdIndex]/SizeParaArray[1]);
		}else{
			InitImgW = Math.round(PreviewImageWidth[IdIndex]);
			InitImgH = Math.round(SizeParaArray[1]*PreviewImageWidth[IdIndex]/SizeParaArray[0]);
		}
		if(E7){
			obj.rows[1].cells[0].firstChild.style.width = InitImgW;
			obj.rows[1].cells[0].firstChild.style.height = InitImgH;
		}else{
			obj.rows[1].cells[0].innerHTML = '<img src="'+img_bump[IdIndex].src+'" width="'+InitImgW+'" height="'+InitImgH+'">';
		}

		obj2.axis = '';
		obj2.style.left = SizeParaArray[6]+LeftPos-PreviewImageWidth[IdIndex]/2;
		obj2.style.top = SizeParaArray[7]+TopPos-PreviewImageHeight[IdIndex]/2;
		if(InitImgW>PreviewImageWidth[IdIndex]&&InitImgH>PreviewImageHeight[IdIndex]){
			obj2.axis = 'XY';
			obj2.PosX = Math.ceil(SizeParaArray[6]+LeftPos-InitImgW/2);
			obj2.PosX1 = Math.floor(obj2.PosX+InitImgW-PreviewImageWidth[IdIndex]);
			obj2.PosY = Math.ceil(SizeParaArray[7]+TopPos-InitImgH/2);
			obj2.PosY1 = Math.floor(obj2.PosY+InitImgH-PreviewImageHeight[IdIndex]);
		}else{
			if(InitImgW<=PreviewImageWidth[IdIndex]){
				obj2.axis = 'Y';
				obj2.PosX = Math.ceil(SizeParaArray[7]);
				obj2.PosY = Math.floor(SizeParaArray[7]+InitImgH-PreviewImageHeight[IdIndex]);
			}
			if(InitImgH<=PreviewImageHeight[IdIndex]){
				obj2.axis = 'X';
				obj2.PosX = Math.ceil(SizeParaArray[6]);
				obj2.PosY = Math.floor(SizeParaArray[6]+InitImgW-PreviewImageWidth[IdIndex]);
			}
		}
		PreviewRatio[IdIndex][2] = Math.round(100*InitImgW/SizeParaArray[0])/100;
		DivShimObj.style.width = obj.offsetWidth;
		DivShimObj.style.height = obj.offsetHeight;
		DivShimObj.style.left = obj.offsetLeft;
		DivShimObj.style.top = obj.offsetTop;
	}
}

function ScaleBump(IdIndex, IsInits, IframeName){//IsInits的意义:  1:初始化, 0:循环 2:不循环
	var tmp, str, tmp1, obj, obj1, obj2, Scale, ScaleAxis, SrcWidth, SrcHeight, LeftPos, TopPos, DivShimObj;
	if(IframeName!='') obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild; else obj = document.getElementById('dragDiv'+IdIndex).firstChild;
	if(IframeName!='') obj1 = parent.document.getElementById('ScaleHandle'+IdIndex); else obj1 = document.getElementById('ScaleHandle'+IdIndex);
	if(IframeName!='') obj2 = parent.document.getElementById('ThumbHandle'+IdIndex); else obj2 = document.getElementById('ThumbHandle'+IdIndex);
	if(IframeName!='') DivShimObj = parent.document.getElementById('DivShim'+IdIndex); else DivShimObj = document.getElementById('DivShim'+IdIndex);
	if(IsInits==1){
		DragDivPara[0] = obj.style.pixelLeft;
		DragDivPara[1] = obj.style.pixelTop;
		DragDivPara[2] = obj.rows[1].cells[0].firstChild.width;;
		DragDivPara[3] = obj.rows[1].cells[0].firstChild.height;
		//这里要考虑图片超出窗口上部的情况
		//parent.document.getElementById('ImgContents').innerText=obj.style.pixelLeft+' '+obj.style.pixelTop+' '+obj.rows[1].cells[0].firstChild.style.pixelWidth+' '+obj.rows[1].cells[0].firstChild.style.pixelHeight
	}

	if(GenMovieObj){
		Scale = Math.floor(100*(obj1.style.pixelLeft-obj1.PosX)/(obj1.PosY-obj1.PosX))/100;
		if(SizeParaArray[0]/PreviewImageWidth[IdIndex]>SizeParaArray[1]/PreviewImageHeight[IdIndex]){
			ScaleAxis = 'X';
		}else{
			ScaleAxis = 'Y';
		}
		if(Scale>1) Scale = 1;
		if(Scale<0) Scale = 0;

		if(ScaleAxis=='X'){
			SrcWidth = PreviewImageWidth[IdIndex]+Math.ceil((SizeParaArray[0]-PreviewImageWidth[IdIndex])*Scale);
			SrcHeight = Math.ceil(SizeParaArray[1]*(SrcWidth/SizeParaArray[0]));
		}
		if(ScaleAxis=='Y'){
			SrcHeight = PreviewImageHeight[IdIndex]+Math.ceil((SizeParaArray[1]-PreviewImageHeight[IdIndex])*Scale);
			SrcWidth = Math.ceil(SizeParaArray[0]*(SrcHeight/SizeParaArray[1]));
		}

		//重新定位obj以便滑动快保持不变
		LeftPos = Math.max(Math.max(SrcWidth, SizeParaArray[4]), PreviewImageWidth[IdIndex]);
		TopPos = Math.max(Math.max(SrcHeight, SizeParaArray[5]-2), PreviewImageHeight[IdIndex]);
		if(PreviewImageWidth[IdIndex]>SizeParaArray[4]) tmp1 = PreviewImageWidth[IdIndex]; else tmp1 = SizeParaArray[4];
		if(SrcWidth>tmp1){
			if(DragDivPara[2]>tmp1) tmp = DragDivPara[2]-SrcWidth; else tmp = tmp1-SrcWidth;
			obj.style.left = DragDivPara[0]+tmp/2;
		}else{

		}

		obj2.style.left = SizeParaArray[6]+(LeftPos-PreviewImageWidth[IdIndex])/2;
		if(PreviewImageHeight[IdIndex]>SizeParaArray[5]) tmp1 = PreviewImageHeight[IdIndex]; else tmp1 = SizeParaArray[5]-2;
		if(SrcHeight>tmp1){
			if(DragDivPara[3]>tmp1) tmp = DragDivPara[3]-SrcHeight; else tmp = tmp1-SrcHeight;
			obj.style.top = DragDivPara[1]+tmp;
		}else{
			if(DragDivPara[3]>tmp1) obj.style.top = DragDivPara[1]+(DragDivPara[3]-tmp1);
		}
		//window.status=DragDivPara[1]+' | '+DragDivPara[3]+' | '+tmp1
		obj2.style.top = SizeParaArray[7]+(TopPos-PreviewImageHeight[IdIndex])/2;
		if(E7){
			obj.rows[1].cells[0].firstChild.style.width = SrcWidth;
			obj.rows[1].cells[0].firstChild.style.height = SrcHeight;
		}else{
			obj.rows[1].cells[0].firstChild.width = SrcWidth;
			obj.rows[1].cells[0].firstChild.height = SrcHeight;
		}

	}
	if(IsInits==2){
		PreviewRatio[IdIndex][2] = Math.round(100*SrcWidth/SizeParaArray[0])/100;
		if(Scale==0||Scale==1){
			if(Scale==0){
				if(PreviewImageWidth[IdIndex]>SizeParaArray[4]) tmp = PreviewImageWidth[IdIndex]; else tmp = SizeParaArray[4];
				LeftPos = tmp/2;
				obj1.style.left = obj.style.pixelLeft+LeftPos-100;
				if(DragDivPara[3]>tmp1) obj.style.top = DragDivPara[1]+(DragDivPara[3]-tmp1);
			}
			if(Scale==1){
				tmp = Math.max(Math.max(SizeParaArray[0], SizeParaArray[4]), PreviewImageWidth[IdIndex]);
				LeftPos = tmp/2;
				obj1.style.left = obj.style.pixelLeft+LeftPos+100;
				tmp =  Math.max(Math.max(SizeParaArray[1], SizeParaArray[5]-2), PreviewImageHeight[IdIndex]);
				TopPos = tmp/2;
				obj1.style.top = obj.style.pixelTop+TopPos*2+64;
			}
			obj1.PosX = Math.floor(obj.style.pixelLeft+LeftPos-100);
			obj1.PosY = Math.ceil(obj.style.pixelLeft+LeftPos+100);
		}else{

		}
		//重新计算移动范围
		if(SizeParaArray[0]>PreviewImageWidth[IdIndex]&&SizeParaArray[1]>PreviewImageHeight[IdIndex]){
			tmp = Math.max(Math.max(SrcWidth, SizeParaArray[4]), PreviewImageWidth[IdIndex]);
			LeftPos = tmp/2;
			tmp =  Math.max(Math.max(SrcHeight, SizeParaArray[5]-2), PreviewImageHeight[IdIndex]);
			TopPos = tmp/2;
			obj2.axis = 'XY';
			obj2.PosX = Math.ceil(SizeParaArray[6]+LeftPos-SrcWidth/2);
			obj2.PosX1 = Math.floor(obj2.PosX+SrcWidth-PreviewImageWidth[IdIndex]);
			obj2.PosY = Math.ceil(SizeParaArray[7]+TopPos-SrcHeight/2);
			obj2.PosY1 = Math.floor(obj2.PosY+SrcHeight-PreviewImageHeight[IdIndex]);
		}else{
			if(SizeParaArray[0]<=PreviewImageWidth[IdIndex]){
				obj2.axis = 'Y';
				obj2.PosX = Math.ceil(SizeParaArray[7]);
				obj2.PosY = Math.floor(SizeParaArray[7]+SrcHeight-PreviewImageHeight[IdIndex]);
			}
			if(SizeParaArray[1]<=PreviewImageHeight[IdIndex]){
				obj2.axis = 'X';
				obj2.PosX = Math.ceil(SizeParaArray[6]);
				obj2.PosY = Math.floor(SizeParaArray[6]+SrcWidth-PreviewImageWidth[IdIndex]);
			}
		}
		DivShimObj.style.width = obj.offsetWidth;
		DivShimObj.style.height = obj.offsetHeight;
		DivShimObj.style.left = obj.offsetLeft;
		DivShimObj.style.top = obj.offsetTop;
	}
	if(IsInits!=2) ScaleTimeID = window.setTimeout('ScaleBump('+IdIndex+', 0, \''+IframeName+'\')', 50)
}

function ScaleOver(IdIndex, IframeName){
	var tmp, tmp1, str, obj1, obj, Scale;
	if(ScaleTimeID!=null){
		clearTimeout(ScaleTimeID);
		ScaleBump(IdIndex, 2, IframeName);
	}
}

function img_fit(FileInput1, IdIndex, IframeName){
	var tmp, obj, input_obj, obj1, DivObj;
	if(IframeName!=''){
		DivObj = parent.document.getElementById('dragDiv'+IdIndex);
		obj = parent.document.getElementById('dragDiv'+IdIndex).firstChild;
	}else{
		DivObj = document.getElementById('dragDiv'+IdIndex);
		obj = document.getElementById('dragDiv'+IdIndex).firstChild;
	}
	eval('input_obj=document.'+FileInput1);
	obj.rows[0].cells[0].firstChild.rows[0].cells[0].innerHTML = '<nobr>&nbsp;图片地址:<a title="'+input_obj.value+'"><font color="#FF0000">'+input_obj.value+'</font></a></nobr>';
	if(E7){
		DivObj.style.visibility = 'hidden';
		DivObj.firstChild.style.display = 'block';
		obj1 = obj.rows[1].cells[0].firstChild;
		try{

			tmp = obj1.offsetWidth;
			obj.rows[3].cells[1].innerHTML = '尺寸:<font color="#FF0000">'+obj1.offsetWidth+'*'+obj1.offsetHeight+'</font>';
			img_bump[IdIndex].width = obj1.offsetWidth;
			img_bump[IdIndex].height = obj1.offsetHeight;
		}catch(e){obj.rows[3].cells[1].innerHTML='<font color="#FF0000">文件格式不对</font>';return;};
		DivObj.style.visibility = 'visible';
		DivObj.firstChild.style.display = 'none';
	}else{
		tmp = img_bump[IdIndex].fileSize/1000;
		if(tmp>1) tmp = Math.round(img_bump[IdIndex].fileSize/1000); else tmp = Math.round(img_bump[IdIndex].fileSize*100/1000)/100
		obj.rows[3].cells[1].innerHTML = '尺寸:<font color="#FF0000">'+img_bump[IdIndex].width+'*'+img_bump[IdIndex].height+'</font> 大小:<font color="#FF0000">'+tmp+'K</font>';
		if(E7){
			obj.rows[1].cells[0].firstChild.style.width = img_bump[IdIndex].width;
			obj.rows[1].cells[0].firstChild.style.height = img_bump[IdIndex].height;
		}else{
			obj.rows[1].cells[0].innerHTML = '<img src="'+img_bump[IdIndex].src+'" width="'+img_bump[IdIndex].width+'" height="'+img_bump[IdIndex].height+'">';
		}

	}
	SizeParaArray[0] = img_bump[IdIndex].width;
	SizeParaArray[1] = img_bump[IdIndex].height;
	OriginImgSize[IdIndex] = new Array();
	OriginImgSize[IdIndex][0] = img_bump[IdIndex].width;
	OriginImgSize[IdIndex][1] = img_bump[IdIndex].height;

	obj.CheckValid = 'true';
	if(SizeParaArray[0]>PreviewImageWidth[IdIndex]||SizeParaArray[1]>PreviewImageHeight[IdIndex]){
		obj.rows[3].cells[0].style.display = 'block';
		obj.rows[3].cells[2].style.display = 'block';
		ChangePreviewType(0, IdIndex, IframeName);
	}
}

function preview_show(Types, FileInput1, IdIndex, IframeName){
	var obj, TableObj, input_obj, HandObj, DivShimObj; //HandObj:移动控制块,与dragDiv处于同一级别的层.
	eval('input_obj=document.'+FileInput1);
	if(IframeName!='') TableObj = parent.document.getElementById('dragDiv'+IdIndex).firstChild; else TableObj = document.getElementById('dragDiv'+IdIndex).firstChild;
	if(Types=='img'){
		if(IframeName!=''){
			HandObj = parent.document.getElementById('ScaleHandle'+IdIndex).firstChild;
			DivShimObj = parent.document.getElementById('DivShim'+IdIndex);
		}else{
			HandObj = document.getElementById('ScaleHandle'+IdIndex).firstChild;
			DivShimObj = document.getElementById('DivShim'+IdIndex);
		}
	}
	switch(Types){
		case 'img':

			if(TableObj.style.display!='none'){
				TableObj.style.display = 'none';
				HandObj.style.display = 'none';
				DivShimObj.style.display = 'none';
			}else{

				if(TableObj.CheckValid=='true'){

					TableObj.style.display = 'block';
					HandObj.style.display = 'block';
					DivShimObj.style.display = 'block';
					DivShimObj.style.width = TableObj.offsetWidth;
					DivShimObj.style.height = TableObj.offsetHeight;
					DivShimObj.style.left = TableObj.offsetLeft;
					DivShimObj.style.top = TableObj.offsetTop;

				}else{
					alert('照片载入中，稍候！');
					return;
				}
			}
			//document.my_news.title.value=parent.document.getElementById('dragDiv'+IdIndex).innerHTML
			break;
		case 'media':
			if(IframeName!='') obj = parent.document.getElementById('preview_media'+IdIndex); else obj = document.getElementById('preview_media'+IdIndex);
			if(TableObj.style.display!='none'){
				obj.FileName = '';
				TableObj.style.display = 'none';
			}else{
				obj.fileName = input_obj.value;
				TableObj.style.display = 'block';
			}
			break;
		case 'real':
			if(IframeName!='') obj = parent.document.getElementById('preview_real'+IdIndex); else obj = document.getElementById('preview_real'+IdIndex);
			if(TableObj.style.display!='none'){
				obj.DoStop();
				TableObj.style.display = 'none';
			}else{
				obj.SetSource(input_obj.value);
				obj.DoPlay();
				TableObj.style.display = 'block';
			}
			break;
		case 'mp3':
			if(IframeName!='') obj = parent.document.getElementById('preview_media'+IdIndex); else obj = document.getElementById('preview_media'+IdIndex);
			if(TableObj.style.display!='none'){
				obj.FileName = '';
				TableObj.style.display = 'none';
			}else{
				obj.fileName = input_obj.value;
				TableObj.style.display = 'block';
			}
			break;
		case 'swf':
			//浏览器不可能调用本地的flash预览
			break;
	}
}

//设置裁切框  ImgWidth, ImgHeight:被选择的图片当前的大小(如果原图比显示框大，则原图缩小以适应显示框)，FrameWidth, FrameHeight:图片显示框的大小。LeftPos, TopPos:当前被选择的图片在显示框的左上角的位置.
function SetThumbHandle(ImgWidth, ImgHeight, FrameWidth, FrameHeight, LeftPos, TopPos, Rations, IdIndex, IframeName){
	var ThumbWidth, ThumbHeight, obj, ThumbHandleWidth, ThumbHandleHeight;
	//if(ThumbPara[3]!=2) return;
	if(PreviewImageWidth[IdIndex]==''||PreviewImageHeight[IdIndex]==''||PreviewImageWidth[IdIndex]==0||PreviewImageHeight[IdIndex]==0) return;
	if(ImgWidth/Rations<=PreviewImageWidth[IdIndex]&&ImgHeight/Rations<=PreviewImageHeight[IdIndex]) return;   //如果原始图片的长和宽都小于缩略图的长宽,则返回
	if(IframeName!='') obj = parent.document.getElementById('ThumbHandle'+IdIndex); else obj = document.getElementById('ThumbHandle'+IdIndex);
	//分两种可能性, 1:原始图片的长宽都大于缩略图的长宽,此时虚线宽缩放到与当前图片(指原始图片缩小到适合欲览框的大小)同长或同宽  2:原始图片的长或者宽大于缩略图的长或者宽(此时虚线框只需缩小到原始图片缩小的比例,因为缩略框本身不缩小,只是为了显示,将虚线框按原始图片缩小的比例来缩小)
	if(ImgWidth/Rations>PreviewImageWidth[IdIndex]&&ImgHeight/Rations>PreviewImageHeight[IdIndex]){
		if(PreviewImageWidth[IdIndex]/ImgWidth>PreviewImageHeight[IdIndex]/ImgHeight){
			//此时虚线框肯定小于欲览框
			obj.firstChild.width = ImgWidth;
			obj.firstChild.height = Math.floor((ImgWidth/PreviewImageWidth[IdIndex])*PreviewImageHeight[IdIndex]);
			obj.PosX = LeftPos;
			obj.PosY = TopPos;
			ThumbHandleWidth = ImgWidth;
			ThumbHandleHeight = Math.floor((ImgWidth/PreviewImageWidth[IdIndex])*PreviewImageHeight[IdIndex]);
		}else{
			obj.firstChild.height = ImgHeight;
			obj.firstChild.width = Math.floor((ImgHeight/PreviewImageHeight[IdIndex])*PreviewImageWidth[IdIndex]);
			obj.PosY = TopPos;
			obj.PosX = LeftPos;
			ThumbHandleWidth = Math.floor((ImgHeight/PreviewImageHeight[IdIndex])*PreviewImageWidth[IdIndex]);
			ThumbHandleHeight = ImgHeight;
		}
	}else{
		ThumbHandleWidth = Math.floor(PreviewImageWidth[IdIndex]*Rations);
		ThumbHandleHeight = Math.floor(PreviewImageHeight[IdIndex]*Rations);
		//这里还要考虑到一种可能性,也许图片在欲览框中,但虚线框的大小可能还大于欲览框,此时则要继续缩小虚线看和图片的大小,注意,这个缩小只是为显示
		if(ThumbHandleWidth>SizeParaArray[4]||ThumbHandleHeight>SizeParaArray[5]){
			if(ThumbHandleWidth/SizeParaArray[4]>ThumbHandleHeight/SizeParaArray[5]){
				ThumbHandleWidth = SizeParaArray[4];
				ThumbHandleHeight = Math.floor(ThumbHandleHeight*(SizeParaArray[4]/ThumbHandleWidth));
			}else{
				ThumbHandleWidth = Math.floor(ThumbHandleWidth*(SizeParaArray[5]/ThumbHandleHeight));
				ThumbHandleHeight = SizeParaArray[5];
			}
		}
		obj.firstChild.width = ThumbHandleWidth;
		obj.firstChild.height = ThumbHandleHeight;
		if(ImgWidth/Rations>PreviewImageWidth[IdIndex]){
			obj.PosX = LeftPos;
			obj.PosY = (SizeParaArray[5]-ThumbHandleHeight)/2;

		}else{
			obj.PosY = TopPos;
			obj.PosX = (SizeParaArray[4]-ThumbHandleWidth)/2;
		};
	}

	obj.style.left = SizeParaArray[6]+obj.PosX;
	obj.style.top = SizeParaArray[7]+obj.PosY;
	if(PreviewImageWidth[IdIndex]/ImgWidth>PreviewImageHeight[IdIndex]/ImgHeight){
		obj.PosX = obj.style.pixelTop;
		obj.PosY = obj.style.pixelTop+(ImgHeight-ThumbHandleHeight);
		obj.axis = 'Y';
		PreviewRatio[IdIndex][1] = 0.5;
		PreviewRatio[IdIndex][0] = -1;
	}else{
		obj.PosX = obj.style.pixelLeft;
		obj.PosY = obj.style.pixelLeft+(ImgWidth-ThumbHandleWidth);
		obj.axis = 'X';
		PreviewRatio[IdIndex][0] = 0.5;
		PreviewRatio[IdIndex][1] = -1;
	}
	if(ImgWidth/Rations>PreviewImageWidth[IdIndex]&&ImgHeight/Rations>PreviewImageHeight[IdIndex]){
		if(PreviewImageWidth[IdIndex]/ImgWidth>PreviewImageHeight[IdIndex]/ImgHeight){
			PreviewRatio[IdIndex][2] = PreviewImageWidth[IdIndex]/SizeParaArray[0];
		}else{
			PreviewRatio[IdIndex][2] = PreviewImageHeight[IdIndex]/SizeParaArray[1];
		}
	}else{
		PreviewRatio[IdIndex][2] = 1;
	}
	obj.style.display = 'block';
}
