// JavaScript Document
function createFunction(instance, method) {	//创建无参数函数
    return function() {
        return method.apply(instance, arguments);
    }
}	

Tab = function (eid) {
	this._element = document.getElementById (eid);
	this._head = this._element.getElementsByTagName("div")[0];
	this._con = this._element.getElementsByTagName("div")[1];
	this._activeIndex = null;
	this.initialize ();
}

Tab.prototype = {
	initialize: function () {
		var as = this._head.getElementsByTagName ("a");
		for (var i=0; i<as.length; i++) {
			var _self = this;
			as[i].onmouseover = function () {
				_self.set_index(this);
			}
		}
		this.set_index(as[0]);
	},
	set_index: function (a) {
		if (this._activeIndex !== null) {
			document.getElementById("tab-con-" + this._activeIndex).style.display = "none";
			document.getElementById("tab" + this._activeIndex).className = "";
		}
		this._activeIndex = a.getAttribute("id").replace("tab", "");
		document.getElementById("tab-con-" + this._activeIndex).style.display = "block";
		a.className = "cur";
	}
}

ImgViewer = function Maxwin$ctrls$imgViewer (imgs, box, URL) {
	this._imgArr = imgs;
	this._box = box;
	this._url = URL;
	this._imgBox = null;
	this._img = null;
	this._timer = null;
	this._cnt = imgs.length;
	this._index = 0;
	this._delay = 5000;
	this._width = 0;
	this._height = 0;

	this.initialize();
}
ImgViewer.prototype = {
	initialize: function () {
		this._imgBox = document.createElement("div");
		this._imgBox.className = "img";
		this._box.appendChild (this._imgBox);
		var a = document.createElement("a");
		a.setAttribute ("href", this._url);
	
		this._img = document.createElement("img");
		a.appendChild (this._img);
		this._imgBox.appendChild (a);
		
		var w = this._box.offsetWidth;
		var h = this._box.offsetHeight;
		this._width = w-2-10;
		this._height = h;
		this.set_index(0);
	},
	set_index: function (value) {
		value = value%this._cnt;
		this._imgBox.className = "imgAlpha";
		var _self = this;
		this._index = value;
		this._img.setAttribute ("src", this._imgArr[value]);

		var eventHandler = createFunction(this, this.nextImg);
		this._timer = setTimeout (eventHandler, this._delay);
		this._img.onload = function () {
			this.removeAttribute ("width");
			this.removeAttribute ("height");
			this.removeAttribute ("style");

			if (this.width > _self._width) {
				var p = _self._width/this.width;
				this.width = this.width * p;
			//	this.height = this.height * p;	
				
			}
			if (this.height > _self._height) {
				var p = _self._height/this.height;
				this.height = this.height * p;
			//	this.width = this.width * p;
			}
//			this.style.marginTop = parseInt ((_self._height-this.height)/2) + "px";
			setTimeout(function () {
				_self._imgBox.className = "img";
			},200);
		}

	},
	nextImg: function () {
		this.set_index (this._index+1);
	}
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	window.open (selObj.options[selObj.selectedIndex].value);
//  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
