/*	
 * quest
 * @version 2009122301
 * @techract
*/	
//document.domain = "oobang.com";
var qtce = new Hash({});
var qt = new Hash({});
var QuestCate = function(id, name, waitNum){
	this.id = id;
	this.name = name;
	this.waitNum = waitNum;
	this.questNum = 0;
}
QuestCate.prototype.incWm = function(){
	this.waitNum ++;
}
QuestCate.prototype.incQm = function(){
	this.questNum ++;
}

var Quest = function(id, name, cateId, desc, guide, target, reward, status, forwardUrl){
	this.id = id;
	this.name = name;
	this.cateId = cateId;
	this.desc = desc;
	this.guide = guide;
	this.target = target;
	this.reward = reward;
	this.status = status;
	this.forwardUrl = forwardUrl;
}
Quest.prototype.setStatus = function(status){
	this.status = status;
}
MUI.Moment = new Class({
	Extends: MUI.Window,
	displayNewWindow: function(){
		this.windowEl.setStyle('opacity', 0);
		setTimeout(MUI.focusWindow.pass(this.windowEl, this), 10);
	}
});
var QuestWindow = new Class({
	Implements: [Events, Options],
	initialize: function(userId, target){
		this.userId = userId;
		this.target = target;
		this.winid = "questWindow";
		this.target.addEvent("click", function(){this.display();}.bind(this));
	},
	display: function(){
		new Asset.css('/css/quest/quest-window.css?'+new Date().getTime());
		if(!this.frameWindow){
			this.frameWindow = new Element("div", {id:":questfw"}).setStyles({
				position:"absolute", top:0, right:0, border: "3px solid #787878", opacity:0,
				filter: "alpha(opacity = 0)", "background-color":"rgb(248, 163, 44)",
				"z-index":150, height:0, width:0}).inject(document.body);
		}
		this.getData();
		var me = new Fx.Morph(':questfw', {
			duration: 500, 
			transition: Fx.Transitions.Sine.easeOut,
			onComplete: function(el){
				this.frameWindow.setStyles({"display":"none"});
                this.displayWindow();
			}.bind(this)
		});
		me.start({
			'height': $(this.winid).getCoordinates().height,
			'width': $(this.winid).getCoordinates().width,
			'top':$(this.winid).getCoordinates().top,
			'left':$(this.winid).getCoordinates().left,
			opacity: 0.8
		});
	},
	getData: function(){
		var t = "<img src='http://bangimg.oobang.com/images/common/hidden.gif' style='background:transparent url(http://bangimg.oobang.com/guide/guide_icons_3.gif) no-repeat -403px -82px; width:70px; height:21px;'/><img src='http://bangimg.oobang.com/images/common/hidden.gif' style='background:transparent url(http://bangimg.oobang.com/guide/guide_icons_3.gif) no-repeat -403px -60px; width:77px; height:21px;'/>"
		new MUI.Moment({
            id: this.winid,
            title: t,
            loadMethod: 'xhr',
            contentURL: '/QuestGetDatas.tr?userId='+this.userId+"&timestamp="+new Date().getTime(),
           	headerStartColor: [254, 199, 44],
			headerStopColor: [248, 163, 44],
			useCanvasControls: false,
            width: 685,
            height: 450,
			headerHeight: 30,
			footerHeight:8,
			resizable: true,
			evalResponse: true,
			onClose: function(){this.reset();}.bind(this)
		});
		
		this.target.className = 'newtask';
	},
	displayWindow: function(){
		if($(this.winid)) $(this.winid).setStyle('opacity', 1);
		else setTimeout('this.displayWindow()', 10);
	},
	reset: function(){
		if($(this.winid)){
			$(this.winid).fade(0);
			this.frameWindow.setStyles({"display":"block", "height":$(this.winid).getCoordinates().height, "width":$(this.winid).getCoordinates().width, "top":$(this.winid).getCoordinates().top, "left":$(this.winid).getCoordinates().left});
			$(this.winid).retrieve('instance').close();
		}
		var me = new Fx.Morph(':questfw', {
			duration: 500, 
			transition: Fx.Transitions.Sine.easeOut,
			onComplete: function(el){
				
			}
		});
		me.start({
			'height': this.target.getCoordinates().width*this.frameWindow.getSize().y/$(this.winid).getCoordinates().width,
			'width': this.target.getCoordinates().width,
			'top':this.target.getCoordinates().top,
			'left':this.target.getCoordinates().left,
			opacity: 0
		});
	},
	reload: function(){
		if($(this.winid)){
			$(this.winid).retrieve('instance').close();
			(function(){this.display()}.bind(this)).delay(600);
		}
	}, 
	award: function(){
		this.target.className = 'newaward';
		this.reload();
	}
});
