var JumpWinClass = {
	DataObj: '',
	SizeSet: [300, 114],
	BtnBlock: 10,
	FuncsSet: {},
	MsgSet: 'JumpWin',
	Closeable: true,
	getWin: '',
	getMsg: '',
	getBC: '',
	getClose: '',
	getOverLay: '',
	//method
	BtnClickAction: function(Type) {
		switch (Type) {
			case 'On':
				//$$('html')[0].style.overflow = 'hidden';
				$$('select').each(function(getSelect) {getSelect.style.visibility = 'hidden';});
				
				this.getMsg.innerHTML = this.MsgSet;
				
				var PageSize = getPageSize();
				var PageScroll = getPageScroll();
				this.getOverLay.style.height = PageSize[1] + 'px';
				this.getWin.style.left = Math.floor(PageSize[0]/2 - this.SizeSet[0]/2) + 'px';
				this.getWin.style.top = Math.floor(PageSize[3]/2 - this.SizeSet[1]/2) + PageScroll[1] + 'px';
				Element.show(this.getOverLay);
				
				//BtnsContainer
				var BSWSet = 0;
				for (var i in this.FuncsSet) BSWSet += this.FuncsSet[i].offsetWidth + this.BtnBlock;
				this.getBC.style.width = BSWSet - this.BtnBlock + 'px';
				break;
			default:
				//$$('html')[0].style.overflowY = 'scroll';
				$$('select').each(function(getSelect) {getSelect.style.visibility = 'visible';});
				this.getWin.style.left = '-1000px';
				Element.hide(this.getOverLay);
		}//end switch
	},
	ResizeEvent: function() {
		var PageSize = getPageSize();
		var PageScroll = getPageScroll();
		JumpWinClass.getOverLay.style.height = PageSize[1] + 'px';
		if (parseInt(JumpWinClass.getWin.style.left, 10) != -1000) JumpWinClass.getWin.style.left = Math.floor(PageSize[0]/2 - JumpWinClass.SizeSet[0]/2) + 'px';
		JumpWinClass.getWin.style.top = Math.floor(PageSize[3]/2 - JumpWinClass.SizeSet[1]/2) + PageScroll[1] + 'px';
	},
	Trigger: function(DataObj) {
		//Turn off FBWin
		if (typeof(WGForumClass) != 'undefined' && WGForumClass.getFBWin.Opacity == 100) WGForumClass.VaryAction('Off');
		
		this.DataObj = DataObj;
		this.MsgSet = (!this.DataObj.Msg || this.DataObj.Msg.length == 0) ? 'JumpWin2' : this.DataObj.Msg;
		if (!this.DataObj.Events) for (var i in this.FuncsSet) this.FuncsSet[i].onclick = function() { JumpWinClass.BtnClickAction(); }; 
		else {
			var ActiveBtns = [];
			for (var i=0; i<this.DataObj.Events.length; i++) {
				var getEvent = this.DataObj.Events[i];
				if (!this.FuncsSet[getEvent.id]) continue;
				ActiveBtns.push(getEvent.id);
				//Subject
				this.FuncsSet[getEvent.id].getValue.innerHTML = (getEvent.Subject) ? getEvent.Subject : getEvent.id;
				//Action
				if (!getEvent.Action) this.FuncsSet[getEvent.id].onclick = function() { JumpWinClass.BtnClickAction(); };
				else {
					this.FuncsSet[getEvent.id].Action = getEvent.Action;
					this.FuncsSet[getEvent.id].onclick = function() { JWASet[this.Action]();	};
				}//end if
				Element.show(this.FuncsSet[getEvent.id]);
			}//end for
			for (var i in this.FuncsSet) if (ActiveBtns.indexOf(i) == -1) Element.hide(this.FuncsSet[i]);
		}//end if
		//BtnClose
		this.Closeable = (this.DataObj.Closeable == undefined) ? true : (typeof(this.DataObj.Closeable) != 'boolean') ? true : this.DataObj.Closeable;
		if (this.Closeable) {
			Element.show(this.getClose);
			this.getOverLay.onclick = function() { JumpWinClass.BtnClickAction(); };
		} else {
			Element.hide(this.getClose);
			this.getOverLay.onclick = '';
		}//end if
		this.BtnClickAction('On');
	},
	BtnCreater: function() {
		var BtnSet = document.createElement('div');
		BtnSet.className = 'JWBtnOutSet';
		BtnSet.onmouseover = function() { this.className = (this.className.indexOf('Out') != -1) ? 'JWBtnOverSet' : 'JWBtnOutSet'; };
		BtnSet.onmouseout = function() { this.className = (this.className.indexOf('Out') != -1) ? 'JWBtnOverSet' : 'JWBtnOutSet'; };
		
		var BtnLPSet = document.createElement('div');
		BtnLPSet.className = 'LeftPart';
		BtnSet.appendChild(BtnLPSet);
		
		var BtnMPSet = document.createElement('div');
		BtnMPSet.className = 'MainPart';
		BtnSet.appendChild(BtnMPSet);
		BtnSet.getValue = BtnMPSet;
		
		var BtnRPSet = document.createElement('div');
		BtnRPSet.className = 'RightPart';
		BtnSet.appendChild(BtnRPSet);
		
		return BtnSet;
	},
	Constructor: function() {
		var JumpWin = document.createElement('div');
		JumpWin.id = 'JumpWinSet';
		JumpWin.style.left = '-1000px';
		JumpWin.style.width = this.SizeSet[0] + 'px';
		JumpWin.style.height = this.SizeSet[1] + 'px';
		$$('body')[0].appendChild(JumpWin);
		this.getWin = JumpWin;
		
		//MsgSection
		var MsgSection = document.createElement('div');
		MsgSection.className = 'MsgSection';
		JumpWin.appendChild(MsgSection);
		this.getMsg = MsgSection;
		
		//BtnSection
		this.getBtns = [];
		var BtnSection = document.createElement('div');
		BtnSection.className = 'BtnSection';
		JumpWin.appendChild(BtnSection);
		
		//BtnSection - BtnsContainer
		var BtnsContainer = document.createElement('div');
		BtnsContainer.className = 'JWBtnsContainer';
		BtnSection.appendChild(BtnsContainer);
		this.getBC = BtnsContainer;
		
		//BtnSection - BtnsContainer - BtnConfirm
		var BtnConfirm = this.BtnCreater();
		BtnConfirm.getValue.innerHTML = 'Confirm';
		BtnsContainer.appendChild(BtnConfirm);
		this.FuncsSet.Confirm = BtnConfirm;
		
		//BtnSection - BtnsContainer - BtnCancel
		var BtnCancel = this.BtnCreater();
		BtnCancel.style.marginLeft = this.BtnBlock + 'px';
		BtnCancel.getValue.innerHTML = 'Cancel';	
		BtnsContainer.appendChild(BtnCancel);
		this.FuncsSet.Cancel = BtnCancel;
		
		var BSWSet = 0;
		for (var i in this.FuncsSet) BSWSet += this.FuncsSet[i].offsetWidth + this.BtnBlock;
		BtnsContainer.style.width = BSWSet - this.BtnBlock + 'px';
		
		//BtnClose
		var BtnClose = document.createElement('div');
		BtnClose.className = 'BtnClose';
		BtnClose.onmouseover = function() { this.style.backgroundPosition = '-17px 0px'; };
		BtnClose.onmouseout = function() { this.style.backgroundPosition = '0px 0px'; };
		BtnClose.onclick = function() { JumpWinClass.BtnClickAction(); };
		JumpWin.appendChild(BtnClose);
		this.getClose = BtnClose;
		
		//OverLay
		var JWOverLaySet = document.createElement('div');
		JWOverLaySet.id = 'JWOverLaySet';
		JWOverLaySet.onclick = function() { JumpWinClass.BtnClickAction(); };
		$$('body')[0].appendChild(JWOverLaySet);
		this.getOverLay = JWOverLaySet;
		Element.hide(JWOverLaySet);
		
		//ResizeEvent
		if (typeof(CurrentStatus) != 'undefined' && typeof(CurrentStatus.ResizeEvent) == 'function') {
			var OriginalFunc = CurrentStatus.ResizeEvent;
			Object.extend(CurrentStatus, {
							ResizeEvent: function() {
								OriginalFunc();	
								JumpWinClass.ResizeEvent();
							}
			});
		} else {
			if (typeof(CurrentStatus) == 'undefined') CurrentStatus = {};
			CurrentStatus.ResizeEvent = function() { JumpWinClass.ResizeEvent(); };
		}//end if
		Event.observe(window, "resize", CurrentStatus.ResizeEvent, false);
	}
};

function JWClassInit() {
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
	
	JumpWinClass.Constructor();
}

addLoadListener(JWClassInit);