﻿// 图片大小滚动JavaScript Document
var dragapproved = false;
var z,x,y;
var MyMar;
function move()
{
	if(event.button==1&&dragapproved)
	{
		z.style.pixelLeft=temp1+event.clientX-x;
		z.style.pixelTop = temp2+event.clientY-y;
		return false;
	}
}
function drags()
{
	if(!document.all)
		return;
	if(event.srcElement.className=="drag")
	{
		dragapproved = true;
		z=event.srcElement;
		temp1=z.style.pixelLeft;
		temp2=z.style.pixelTop;
		x=event.clientX;
		y=event.clientY;
		document.onmousemove=move;
	}
}
document.onmousedown=drags;
document.onmouseup=new Function("dragapproved=false");

var zoomp = 92;
function zoomimg(img)
{
  var zoom = parseInt(img.style.zoom,10) || 100;
  zoom += event.wheelDelta / 12;
  if (zoom>10) img.style.zoom = zoom + "%";
  return false;
}
function zoom()
{
  var zoom = parseInt(imagPreview.style.zoom,10) || 100;
  zoom += 20;
  if (zoom>10) imagPreview.style.zoom = zoom + "%";
}
function zoomout()
{
  //showlayerVidio(false);
  var zoom = parseInt(imagPreview.style.zoom,10) || 100;
  zoom -= 20;
  if (zoom>10) imagPreview.style.zoom = zoom + "%";
}
function zoom0(MainPhotoName)
{
	//showlayerVidio(false);
	var img=document.getElementById(MainPhotoName);
	img.style.zoom = 100 + "%";

	img.style.pixelLeft=0;
	img.style.pixelTop=0;

}

//限制图片的长宽
function ImageResize(obj,MaxImagWidth,MaxImagHeight)
{	

	var ImagWidth=obj.width;
	var ImagHeight=obj.height;
	var TempImagWidth = ImagWidth;
	var TempImagHeight = ImagHeight;
	//1\检测参数，如果图片不是对象，则退出
	if(obj==null)
	{	
		return;
	}
	//2\如果图片是对象，并且没能检测图片的宽高，  如果图片的最大宽度不为0 ，则返回图片的最大宽度
	else if(obj!=null&&(ImagWidth==0||ImagHeight==0))
	{
		if(MaxImagWidth>0)
		{obj.width=MaxImagWidth;}
		else if(MaxImagHeight>0)
		{obj.height=MaxImagHeight;}
		else
		{return;}
	}
	//3\如果能够检测出图片的实际宽高，则进行宽度调整处理
	else
	{
		try{
	
				//1\如果只限制宽度，则处理宽度就可以了 
				if ((MaxImagWidth!=null&&MaxImagWidth>0)&&MaxImagHeight==0)
				{if(ImagWidth>MaxImagWidth)ImagWidth=MaxImagWidth;} 
				
				
				//2\如果只限制高度，则处理高度就可以了
				else if ((MaxImagHeight!=null&&MaxImagHeight>0)&&MaxImagWidth==0)
				{if(ImagHeight>MaxImagHeight)ImagHeight=MaxImagHeight;}	
				
				
				//3\如果限制高度和宽度，则进行复杂的处理
				else if ((MaxImagHeight!=null&&MaxImagHeight>0)&&(MaxImagWidth!=null&&MaxImagWidth>0))
				{
					//重新计算图片的长度和高度
					//先限制图片的宽度
					//---------------------------------------------------
					//情况1：图片的宽度超过最大限定宽度  
					
					if(ImagWidth > MaxImagWidth)
					{
					
					
						var TempWidth,TempHeight;
						//第一次计算
						TempWidth = MaxImagWidth;
						//计算图片的高度
						TempHeight = parseInt(ImagHeight / ImagWidth * MaxImagWidth);
					
						//第二次计算
						//判断图片的高度是否超出制定的高度
						if(TempHeight > MaxImagHeight)
						{
							TempHeight = MaxImagHeight;
							//重新计算图片的宽度
							TempWidth = parseInt(ImagWidth / ImagHeight * MaxImagHeight);
						}
						ImagWidth = TempWidth;
						ImagHeight = TempHeight;
						
						//alert("a="+ImagHeight / ImagWidth +"b="+parseInt(ImagHeight / ImagWidth * MaxImagWidth))
					}
					//情况2：图片的宽度不超过最大限定宽度，但是高度超过了限定宽度
					else if(ImagHeight > MaxImagHeight)
					{//alert("a="+MaxImagHeight +"b="+parseInt(TempImagWidth / TempImagHeight * MaxImagHeight))
						ImagHeight = MaxImagHeight;
						ImagWidth = parseInt(TempImagWidth / TempImagHeight * MaxImagHeight);
					}
				}
		}
		catch(e)
		{
			//alert(e);
		}
		if(ImagWidth>0&&ImagHeight>0)
		{
			obj.width=ImagWidth;
			obj.height=ImagHeight;
		}
		else
		{
			if(MaxImagWidth!=null&&MaxImagWidth>0)
			{obj.width=MaxImagWidth;}
		}
	}
}


//循环调整对象里面包含图片的长宽
//参数：对象ID,最长宽度,最长高度
function AutoAdjustPictures(objID,MaxWidth,MaxHeight) 
{   
  var   sfEls   =   document.getElementById(objID);   	  
  sfEls   =   sfEls.getElementsByTagName("img");
  for   (var   i=0; i<sfEls.length;i++)  
   {
		  ImageResize(sfEls[i],MaxWidth,MaxHeight);
	}
}

  
function ChangeImg(imgid,src) {
    document.getElementById(imgid).src=src;
}




//产品的详细页的功能页
function openWin(url,name,w,h)
{
    var x=(window.screen.width-w)/2;
    var y=(window.screen.height-h)/2;
    var win=window.open(url,name,'toolbar=0,location=0,status=0,top='+y+',left='+x+',width='+w+',height='+h );
    win.focus();

    return win;
}

 
function ImgBtnChgPrd_Mouseover(obj,mainpictureurl,largepictureurl)
{
    document.getElementById('bigphoto').src=mainpictureurl;
    document.getElementById('bigphoto').onclick=function(){ImgBtnChgPrd_Click(this,largepictureurl);}
}
 
function ImgBtnChgPrd_Click(obj,largepictureurl)
{
    var win=openWin('/UcProduct/ViewImg.aspx?ID='+document.getElementById('hid_largepictureurl').value+'&BigImg='+largepictureurl,'preview',700,580);
    win.opener=this;
}

function suitImage(img,w,h)
{
		var image=new Image();
        image.src=img.src;

		var iw=image.width;
		var ih=image.height;
		var iratio=iw/ih;
        
        if(iw>w)
		{
                iw=w;
				ih=w/iratio;
        }
        if(ih>h)
		{
                ih=h;
                iw=h*iratio;
        }  
		img.width=iw;
		img.height=ih;
}


var scale=0;
var original=0;
var change=0;
var iratio=0;
var objImg=null;

function doZoomIn(objImgs)
{
    objImg=document.getElementById('objImg');
    if(original==0)
    {
        original=objImg.width;
        scale=objImg.width;
        iratio=objImg.width/objImg.height;
    }

	if(scale-original>2048) return false;
	
	scale+=5;
	change+=5;
    if(change>100) {change=0; return false;}
	objImg.width=scale;
	objImg.height=scale/iratio;
	window.setTimeout("doZoomIn()",50);
	return true;
}

function doZoomOut(objImgs)
{
    objImg=document.getElementById('objImg');
	if(original==0)
    {
        original=objImg.width;
        scale=objImg.width;
        iratio=objImg.width/objImg.height;
    }
    
	if(scale<=100) return false;
	scale-=5;
	change+=5;
    if(change>100) {change=0; return false;}
	objImg.width=scale;
	objImg.height=scale/iratio;
    window.setTimeout("doZoomOut()",50);
	return true;
}


function doReset(objImgs)
{
    objImg=document.getElementById('objImg');
    if(original==0)
    {
        original=objImg.width;
        scale=objImg.width;
        iratio=objImg.width/objImg.height;
    }
    else
    {
        objImg.width=original;
	    objImg.height=original/iratio;
	    scale=original;
    }
    
	return true;
}


