﻿/*Graphics播放类
接受参数:无
返回类型:无

应用技术：javascript

制作人：
黄若儒 Roy.Huang

注意:
null
*/
var Graphics=function(){};

try{//设置命名空间
	Class.setNameSpace("com.gzgi.gui.Graphics",Graphics);
	Class.getClass("com.gzgi.util.Method").init(Graphics);
}
catch(e){}

Graphics.images=["/SCRIPT/com/gzgi/gui/Graphics.gif"];

Graphics.init=function(t){//将所有有方法带出指定对象或window
	t=t?t:window;
	for(var i in this)
		if(!t[i] && i!="init" && i!="finally")
			t[i]=this[i];
};

Graphics.destroy=function(t){//将所有带出指定对象或window中的方法删除
	t=t?t:window;
	for(var i in this)
		if(t[i] && t[i]==this[i] && i!="init" && i!="finally")
			t[i]=undefined;
};


/********************图片处理********************/
Graphics.fitImageSize=function(img,maxW,maxH,auto){//自动缩放图片
	img=this.GEI(img);
	if(img==null)
		return this.onError(0);
	var image=document.createElement("img");
	image.onload=function (){
		var scale=1;
		var width=this.width;
		var height=this.height;
		if(auto || width>maxW || height>maxH)
			scale=Math.min(maxW/width,maxH/height);
		width*=scale;
		height*=scale;
		img.width=width;
		img.height=height;
		img.style.display="";
	};
	image.src=img.src;
};

Graphics.fixAllPNG=function(){//处理所有PNG图片
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5 && version < 7.0) && (document.body.filters))
		for(var i=0; i<document.images.length; i++)
			this.fixPNG(document.images[i]);
};

Graphics.fixPNG=function(img){//处理PNG图片
	try{
		var imgName = img.src.toUpperCase();
		if (imgName.indexOf(".PNG") > 0) {
			var width = img.width;
			var height = img.height;
			var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0)? "scale" : "image"; 
			img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
			img.src = this.images[0];
			img.width = width;
			img.height = height;
		}
	}
	catch(e){}
};


/********************平面相关处理********************/
Graphics.getPosition=function(o,style){//获取对象的坐标
	o=this.GEI(o);
	if(o==null)
		return this.onError(0);
	var rst={x:0,y:0};
	rst.x=o.offsetLeft;
	rst.y=o.offsetTop;
	while(o=o.offsetParent){
		rst.x+=o.offsetLeft;
		rst.y+=o.offsetTop;
	}
	if(style){
		var temp=this.getSize();
		rst.x-=temp.scrollLeft;
		rst.y-=temp.scrollTop;
	}
	return rst;
};

Graphics.getMousePosition=function(e,layer){//获取鼠标光标相对于整个页面的位置和相对于当前元素的位置。
	e=e||window.event;
	var rst={x:0,y:0};
	rst.x = !layer?e.pageX||e.clientX+document.body.scrollLeft:e.layerX||e.offsetX;
	rst.y = !layer?e.pageY||e.clientY+document.body.scrollTop:e.layerY||e.offsetY;
	return rst;
};

Graphics.getSize=function(t){//获取页面的一些size
	var rst={clientWidth:0,clientHeight:0,scrollWidth:0,scrollHeight:0,offsetWidth:0,offsetHeight:0}
	var de=document.documentElement;
	var cm=document.compatMode
	if(cm && cm!="BackCompat" && (!t || t==document.body)){
		rst.clientWidth=de.clientWidth;
		rst.clientHeight=de.clientHeight;
		rst.scrollWidth=de.scrollWidth;
		rst.scrollHeight=de.scrollHeight;
		rst.scrollTop=de.scrollTop;
		rst.scrollLeft=de.scrollLeft;
		rst.offsetWidth=de.offsetWidth;
		rst.offsetHeight=de.offsetHeight;
	}
	else{
		t=t?t:document.body;
		rst.clientWidth=t.clientWidth;
		rst.clientHeight=t.clientHeight;
		rst.scrollWidth=t.scrollWidth;
		rst.scrollHeight=t.scrollHeight;
		rst.offsetWidth=t.offsetWidth;
		rst.offsetHeight=t.offsetHeight;
	}
	return rst;
};

Graphics.getBody=function(){//根据标准获取body
	if(document.compatMode && document.compatMode!="BackCompat")
		return document.documentElement
	else
		return document.body;
};

Graphics.onError=function(e){//错误处理
	switch(e){
		case 0:alert("对象为空");break;
		default:alert(e);
	};
	return false;
};