function rotationPicture(img,divId) {
	if (!img) {
		return;
	}
	this._divId = divId;
	this._img = typeof img == "string" ? document.getElementById(img) : img;
	this.r = 1;
	this.addBtn();
	this.bind();
}
rotationPicture.prototype.addBtn = function () {
	this._rRight = document.getElementById(this._divId);
	if (!isIE()) {
		var canvas = document.createElement("CANVAS");
		var ctx = canvas.getContext("2d");
		canvas.setAttribute("width", this._img.width);
		canvas.setAttribute("height", this._img.height);
		ctx.drawImage(this._img, 0, 0);
		this._ghost = this._img;
		this._img.parentNode.replaceChild(canvas, this._img);
		this._img = canvas;
	}
	//this._img.parentNode.insertBefore(this._rRight, this._img);
};
rotationPicture.prototype.bind = function () {
	var _this = this;
	if (window.attachEvent) {
		this._rRight.attachEvent("onclick", rotation);
	} 
	else {
		this._rRight.addEventListener("click", rotation, false);
	}
	function rotation() {
		if (_this.r > 3) {
			_this.r = 0;
		}	
		if (isIE()) {
			_this._img.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(Rotation=" + _this.r + ")";
		} 
		else {
			var ctx = _this._img.getContext("2d");	
			var _width = _this._img.width;
			var _height = _this._img.height;
			switch (_this.r) {
			  case 0:
				_this._img.setAttribute("width", _width);
				_this._img.setAttribute("height", _height);
				ctx.drawImage(_this._ghost, 0, 0);
				break;
			  case 1:
				_this._img.setAttribute("width", _height);
				_this._img.setAttribute("height", _width);
				ctx.rotate(90 * Math.PI / 180);
				ctx.drawImage(_this._ghost, 0, -_height);
				break;
			  case 2:
				_this._img.setAttribute("width", _height);
				_this._img.setAttribute("height", _height);
				ctx.rotate(180 * Math.PI / 180);
				ctx.drawImage(_this._ghost, -_height, -_height);
				break;
			  case 3:
				_this._img.setAttribute("width", _height);
				_this._img.setAttribute("height", _width);
				ctx.rotate(270 * Math.PI / 180);
				ctx.drawImage(_this._ghost, -_height, 0);
				break;
			}
		}
		_this.r++;
	}
};

function isIE() {
	if (window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1) {
		return true;
	} 
	else {
		return false;
	}
}
if (!isIE()) {
	HTMLElement.prototype.__defineGetter__("innerText", function () {
		var anyString = "";
		var childS = this.childNodes;
		for (var i = 0; i < childS.length; i++) {
			if (childS[i].nodeType == 1) {
				anyString += childS[i].innerText;
			} 
			else {
				if (childS[i].nodeType == 3) {
					anyString += childS[i].nodeValue;
				}
			}
		}
		return anyString;
	});
	HTMLElement.prototype.__defineSetter__("innerText", function (sText) {
		this.textContent = sText;
	});
}
function toolTip(imgPath) {
	var image = new Image();
	image.src = imgPath;
	var msgW = image.width;
	var msgH = image.height;
	if (msgW > 600) {
		msgW = 600;
	}
	if (msgW < 150) {
		msgW = 150;
	}
	if (msgH > 500) {
		msgH = 500;
	}
	var msgWH = Math.max(msgW, msgH);
	try {
		var fatherDiv = document.getElementById("fatherDiv");
		if (fatherDiv != null) {
			fatherDiv.parentNode.removeChild(fatherDiv);
		}
		var childDiv = document.getElementById("childDiv");
		if (childDiv != null) {
			childDiv.parentNode.removeChild(childDiv);
		}
	}
	catch (e) {}
	var allheight = getScrollHeight();
	var l = (document.body.clientWidth - msgW) / 2;
	var t = (allheight - msgH) / 2;
	var container = document.createElement("div");
	container.id = "fatherDiv";
	var items = document.createElement("div");
	items.style.cssText = "z-index:5001;cursor:pointer;top:" + t + "px;left:" + l + "px;width:" + msgWH + "px;height:" + msgWH + "px;font-size:12px;font-family:\u5b8b\u4f53;position:absolute;";	
	var imgDiv = document.createElement("div");
	imgDiv.style.cssText = "width:" + msgWH + "px;height:" + msgWH + "px;margin-left: auto;border: 1px #f9c14a solid;text-align: center;";	
	imgDiv.innerHTML = "<img id='showImg' src='" + imgPath + "' width='100%' height='" + msgH + "px'/>";
	var butDiv = document.createElement("div");
	butDiv.style.cssText = "width:" + msgWH + "px;height:50px;margin-left: auto;text-align: center;";	
	butDiv.innerHTML = "<img id='butImg' src='../images/xz.gif'/>&nbsp;<img src='../images/c.gif' onclick='_butno()'/>";
	var texts = document.createElement("div");
	texts.appendChild(butDiv);	
	texts.appendChild(imgDiv);		
	items.appendChild(texts);
	container.appendChild(items);
	var bgDiv = document.createElement("div");
	bgDiv.innerHTML = "<iframe scrolling='no' id='childIframe' frameborder='0' style='background-color: white;z-index:-1;position:absolute;left:2px;width:100%;height:" + allheight + "px;'></iframe>";
	bgDiv.id = "childDiv";
	bgDiv.style.cssText = "z-index:5000;filter:alpha(opacity=50);left:0px;width:100%;position:absolute;top:0px;height:" + allheight + "px;background-color:#BCBCBC;moz-opacity:0.5;opacity:0.5";
	bgDiv.onmouseup = function () {
		return false;
	};
	bgDiv.onmousemove = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.ondblclick = function () {
		return false;
	};
	bgDiv.onclick = function () {
		return false;
	};
	bgDiv.oncontextmenu = function () {
		return false;
	};
	bgDiv.onselectstart = function () {
		return false;
	};
	function _butno() {
		container.style.display = "none";
		bgDiv.style.display = "none";
	}
	document.body.appendChild(container);
	document.body.appendChild(bgDiv);
	new rotationPicture('showImg','butImg');
}

function getScrollTop() {
	var scrollTop = 0;
	if (document.documentElement && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrollTop;
	} 
	else {
		if (document.body) {
			scrollTop = document.body.scrollTop;
		}
	}
	return scrollTop;
}

function toolButTip(imgPath, butIf) {
	var image = new Image();
	image.src = imgPath;
	var msgW = image.width;
	var msgH = image.height;
	if (msgW > 800) {
		msgW = 800;
	}
	if (msgW < 200) {
		msgW = 200;
	}
	if (msgH > 600) {
		msgH = 600;
	}
	try {
		var fatherDiv = document.getElementById("fatherDiv");
		if (fatherDiv != null) {
			fatherDiv.parentNode.removeChild(fatherDiv);
		}
		var childDiv = document.getElementById("childDiv");
		if (childDiv != null) {
			childDiv.parentNode.removeChild(childDiv);
		}
	}
	catch (e) {
	}
	var allheight = getScrollHeight();
	var l = (document.body.clientWidth - msgW) / 2;
	var t = (allheight - msgH) / 2;
	var container = document.createElement("div");
	container.id = "fatherDiv";
	var items = document.createElement("div");
	items.style.cssText = "z-index:5001;cursor:pointer;top:" + t + "px;left:" + l + "px;width:" + msgW + "px;height:" + msgH + "px;font-size:12px;font-family:\u5b8b\u4f53;position:absolute";
	var table = "<table><tr><td align='right'><a onclick='_butno()' style='font-size:20px'>\xd7</a></td></tr>";
	table += "<tr><td align='center'>";
	if (imgPath == null) {
		table += "<img src='../images/loading.gif'/>";
	}
	if (imgPath != null) {
		table += "<img src='" + imgPath + "' width='" + msgW + "px' height='" + msgH + "px'/>";
	}
	table += "</td></tr><tr><td align='center'>";
	if (butIf != "z") {
		table += "<img src='../images/l.gif' onclick='gotoPageTool(0)'/>&nbsp;";
	}
	if (butIf == "z") {
		table += "<img src='../images/l_2.gif'/>&nbsp;";
	}
	if (butIf != "y") {
		table += "<img src='../images/r.gif' onclick='gotoPageTool(1)'/>&nbsp;";
	}
	if (butIf == "y") {
		table += "<img src='../images/r_2.gif'/>&nbsp;";
	}
	table += "<img src='../images/c.gif' onclick='_butno()'/>";
	table += "</td></tr></table>";
	var texts = document.createElement("div");
	texts.innerHTML = table;
	items.appendChild(texts);
	container.appendChild(items);
	var bgDiv = document.createElement("div");
	bgDiv.innerHTML = "<iframe scrolling='no' id='childIframe' frameborder='0' style='background-color: white;z-index:-1;position:absolute;left:2px;width:100%;height:" + allheight + "px;'></iframe>";
	bgDiv.id = "childDiv";
	bgDiv.style.cssText = "z-index:5000;filter:alpha(opacity=50);left:0px;width:100%;position:absolute;top:0px;height:" + allheight + "px;background-color:#BCBCBC;moz-opacity:0.5;opacity:0.5";
	bgDiv.onmouseup = function () {
		return false;
	};
	bgDiv.onmousemove = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.onmousedown = function () {
		return false;
	};
	bgDiv.ondblclick = function () {
		return false;
	};
	bgDiv.onclick = function () {
		return false;
	};
	bgDiv.oncontextmenu = function () {
		return false;
	};
	bgDiv.onselectstart = function () {
		return false;
	};
	document.body.appendChild(container);
	document.body.appendChild(bgDiv);
}
function _butno() {
	try {
		var fatherDiv = document.getElementById("fatherDiv");
		if (fatherDiv != null) {
			fatherDiv.parentNode.removeChild(fatherDiv);
		}
		var childDiv = document.getElementById("childDiv");
		if (childDiv != null) {
			childDiv.parentNode.removeChild(childDiv);
		}
	}
	catch (e) {
	}
}
function getClientHeight() {
	var clientHeight = 0;
	if (document.body.clientHeight && document.documentElement.clientHeight) {
		var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
	} else {
		var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
	}
	return clientHeight;
}
function getScrollHeight() {
	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}


