﻿//支持IE6背景透明

function correctPNG()  
{ 
for(var i=0; i<document.images.length; i++) 
{ 
  var img = document.images[i] 
  var imgName = img.src.toUpperCase() 
  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
  { 
   var imgID = (img.id) ? "id='" + img.id + "' " : "" 
   var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
   var imgStyle = "display:inline-block;" + img.style.cssText  
   if (img.align == "left") imgStyle = "float:left;" + imgStyle 
   if (img.align == "right") imgStyle = "float:right;" + imgStyle 
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
   var strNewHTML = "<span " + imgID + imgClass + imgTitle 
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
   img.outerHTML = strNewHTML 
   i = i-1 
  } 
} 
} 
window.attachEvent("onload", correctPNG);



//缩放缩略图
function imgZoomer(imgObj,canvas_width,canvas_height){
    var obj = imgObj;
    var src_width = GetImageWidth(obj);
    var src_height =GetImageHeight(obj);
    var widthScale =  src_width / canvas_width;
	  var heightScale = src_height / canvas_height;
  
    if (widthScale >= 1 || heightScale >= 1) {
      //哪边差的小，以哪边为基准放大
      if (widthScale < heightScale) {
        obj.width = src_width / heightScale;
        obj.height = canvas_height;
      } else {
        obj.width = canvas_width;
        obj.height = src_height / widthScale;
      }
    }else {
        obj.width = src_width;
        obj.height = src_height;
    }
}
var OriginImage=new Image();
function GetImageWidth(oImage){
  if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src;
  return OriginImage.width;
}

function GetImageHeight(oImage){
  if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src;
  return OriginImage.height;
}

//左边菜单
function menu_display(x)
{
  var x;
  if(document.getElementById(x).style.display == "none")
      document.getElementById(x).style.display = "block";
   else
      document.getElementById(x).style.display = "none";
}
