/* 
NAVITIME Dynamic Script Window
Copyright 2007 NAVITIME JAPAN CO.,LTD. All Rights Reserved.
Auther by myoshida@navitime.co.jp
Version1.0.0
*/

NTWindow = function(){};
NTWindow.prototype = {
	initialize: function(){
		this.base = null;
		this.width=0;
		this.height=0;
	},
	loading: document.createElement("img"),
	create: function(){
		this.base = document.createElement("div");
	},
	onload: function(){},
	open: function(){},
	hide: function(){},
	close: function(){
		this.base = null;
	},
	get: function(a){
		if(!a || !a.uri) return;
		if(!this.base) this.create();
		if(this.loading.src==""){
			this.loading.src = "/ETlive/event/img/loading.gif";
			this.loading.style.position = "absolute";
		}
		this.loading.style.left = NTAgis.P(this.width/2-50);
		this.loading.style.top  = NTAgis.P(this.height/2-25);
		this.loading.style.display="block";
		this.base.appendChild(this.loading);

		var uri=a.uri, param="";
		if(typeof a.param=="string"){
			var parameters = a.param.split("&");
			for(var i=0; i<parameters.length; i++){
				var key = parameters[i].split("=")[0], value=parameters[i].split("=")[1];
				if(value.match(/[^a-zA-Z0-9-_%]/)){
					value = EscapeUTF8(value);
				}
				param += (i>0?"&":"") + key + "=" + value;
			}
		}else if(typeof a.param=="object"){
			param = $H(a.param).toQueryString();
		}
		if(a.form){
			param = Form.serialize(a.form);
		}
		this.action = a.uri + "?" + param;
		if(a.func){
			this.onExpandFunc = a.func;
		}
		var options = new Object();
		options.parameters = param;
		options.onComplete = this.expand.bind(this);
		if(a.method && a.method == "post"){
			options.method = "post";
		}else{
			options.method = "get";
		}
		new Ajax.Request(uri,options);
	},
	
	expand: function(response){
		this.content.innerHTML = "";
		this.content.innerHTML = NTWindow.Control.analyzeHTML(response.responseText);
		NTWindow.Control.executeScript(response.responseText, this.action);
		this.loading.style.display="none";
		this.content.scrollTop = 0;
		(this.onExpandFunc||function(){})();
	},
	
	cursor: function(e){
		if(e.target.style.cursor!="pointer"){
			e.target.style.cursor="pointer";
		}else{
			e.target.style.cursor="default";
		}
	},
	wheelscroll: function(e){
		NTAgis.C(e);
		var length=50, delta=0, dom=e.target.parentNode;
		do{
			if((dom.id||"").indexOf("NTWindow")!=-1 && (dom.id||"").indexOf("Content")!=-1) break;
			dom = dom.parentNode;
		}while(dom.parentNode!=null);
		
		if (e.wheelDelta) {
			delta = e.wheelDelta/120; 
			if (NTUserAgent.type==4) delta = -delta;
		} else if (e.detail) {
			delta = -e.detail/3;
		}
		if(delta == 1){
			//scroll up
			dom.scrollTop = dom.scrollTop-length<0 ? 0 : dom.scrollTop-length;
		}
		if(delta == -1){
			//scroll down
			if(dom.offsetHeight + dom.scrollTop + length >= dom.scrollHeight){
				dom.scrollTop = dom.scrollHeight - dom.offsetHeight;
			}else{
				dom.scrollTop += length;
			}
		}
	}
}

NTWindow.Control = {
	sizeList: 0,
	sizeListHide: function(){
		var ret=0;
		for(var i=0; i<this.lists.length; i++){
			ret += this.lists[i].hideIndex?0:1;
		}
		return ret;
	},
	getEmptyHideIndex: function(){
		var hidx = new Array();
		for(var i=0; i<this.lists.length; i++){
			if(this.lists[i].hideIndex) hidx.push(this.lists[i].hideIndex);
		}
		for(var i=1; i<10; i++){
			var isexist = false;
			for(var h=0; h<hidx.length; h++){
				if(i == hidx[h]){
					isexist=true;
					break;
				}
			}
			if(!isexist) return i;
		}
		return hidx.length+1;
	},
	sizeAction: 0,
	
	lists: new Array(),
	actions: new Array(),
	modal: null,
	actWindow: null,
	
	addList: function(a){
		this.sizeList++;
		this.lists[this.lists.length] = a;
	},

	deleteList: function(a){
		var temp = new Array();
		for(var i=0; i<this.lists.length; i++){
			if(a != this.lists[i]){
				temp[temp.length] = this.lists[i];
			}
		}
		this.lists = temp;
		this.sizeList--;
	},

	addAction: function(a){
		this.sizeAction++;
		this.actions[this.actions.length] = a;
	},

	getOpenAction:function(){
		for(var i=0; i<this.sizeAction; i++){
			if(this.actions[i].isOpen){
				return this.actions[i];
			}
		}
		return false
	},

	deleteAction: function(a){
		var temp = new Array();
		for(var i=0; i<this.actions.length; i++){
			if(a != this.actions[i]){
				temp[temp.length] = this.actions[i];
			}
		}
		this.actions = temp;
		this.sizeAction--;
	},
	
	ScriptFragment: '<script[^>]*>([\r\n\s\t]*<\![-]*)?((?:\n|\r|.)*?)(\/\/[\s\t\-]*>)?[\r\n]*</script>',
	analyzeHTML: function(html){
	
		// HTMLタグを返却
		return html.replace(new RegExp(NTWindow.Control.ScriptFragment, 'img'), '');
	},
	executeScript: function(html, action){
		var matchAll = new RegExp(NTWindow.Control.ScriptFragment, 'img');
		var matchOne = new RegExp(NTWindow.Control.ScriptFragment, 'im');
		var scripts = (html.match(matchAll) || []).map(function(scriptTag) {
			return (scriptTag.match(matchOne) || ['','',''])[2];
		});
		scripts.each(function(value,idx){
			try{
				if(value) eval(value);
			}catch(e){
//				alert("スクリプトエラー\n"+e.message + ":" + (e.number & 0xffff) + "\n" + value+"\n");
				var options = new Object();
				options.parameters = "message=" + EscapeUTF8(e.message) + "&script="+EscapeUTF8(value) + "&action=" + EscapeUTF8(action||"") + "&line=" + (e.number & 0xffff);
				options.method="post";
				new Ajax.Request("/pcnavi/mjx/scripterr.jsp", options);
//				throw e;
			}
		});
	},
	
	self: function(a){
		var c = a, f=null;

		do{
			try{
				c = c.parentNode;
				if(c.tagName=="DIV" && c.className=="window-container"){
					f = c;
					break;
				}
			}catch(e){}
		}while(f==null && c.parentNode !=null);
		for(var i=0; i<this.lists.length; i++){
			if(this.lists[i].base.id == f.id) return this.lists[i];
		}
		for(var i=0; i<this.actions.length; i++){
			if(this.actions[i].base.id == f.id) return this.actions[i];
		}
		if(this.modal && this.modal.base.id == f.id) return this.modal;
		return null;
	},

	windowAllClose: function(){
		var isAllClosed = true;
		for(var i=0; i<NTWindow.Control.lists.length; i++){
			if(NTWindow.Control.lists[i].head.style.display != "none" ||
				NTWindow.Control.lists[i].content.style.display != "none"){
				NTWindow.Control.lists[i].hide();
				isAllClosed = false;
			}
		}
		if(isAllClosed){
			var tmpActWindow = NTWindow.Control.actWindow;
			for(var i=0; i<NTWindow.Control.lists.length; i++){
				NTWindow.Control.lists[i].open();
			}
			if(tmpActWindow.base!=null)	tmpActWindow.activate();
		}
	}
};


NTWindow.List = Class.create();
NTWindow.List.prototype = Object.extend(new NTWindow(), {
	initialize: function(param){
		if(NTWindow.Control.lists.length == 5){
			alert("同時會啟動的視窗數最多為5個。");
			return null;
		}
		this.history = new Array();
		this.title = (param.title||null);
		this.width = (param.width||250);
		this.height = (param.height||350);
		this.base_x = (param.x||0);
		this.base_y = (param.y||0);
		this.data = (param.data||null);
		this.onLoadFunc  = (param.onLoad|| function(){});
		this.onOpenFunc  = (param.onOpen|| function(){});
		this.onHideFunc  = (param.onHide|| function(){});
		this.onCloseFunc = (param.onClose|| function(){});
		this.onActivateFunc  = (param.onActive|| function(){});
		this.onDeactivateFunc = (param.onDeactive|| function(){});
		this.create(param);
	},
	create: function(param){
		for(var i=0; i<NTWindow.Control.lists.length; i++){
			NTWindow.Control.lists[i].deactivate();
		}
		
		this.base = document.createElement("div");
		var st = this.base.style;
		st.width = (this.width+2)+"px";
		st.height = (this.height+2)+"px";
		st.position = "absolute";
		st.zIndex = "3001"
		st.left = NTAgis.P(this.base_x);
		st.top = NTAgis.P(this.base_y);
		st.overflow="hidden";
		this.base.className = "window-container";
		this.base.id = "NTWindowList"+Math.random(50000);
		$('list-window').appendChild(this.base);
		NTEvent.add(this.base, "mousedown", this.activate.bind(this));
		
		this.icon = NTAgis.Object.Util.createPng("/ETlive/event/img/map/window.png",{width:40,height:40});
		this.icon.id = "listicon" + Math.floor(Math.random(10000)*10000);
		st = this.icon.style;
		st.left="0px";
		st.zIndex = "3003"
		st.display="none";
		st.position="relative";
		this.base.appendChild(this.icon);
		NTEvent.add(this.icon, "click", this.open.bind(this));
		NTEvent.add(this.icon, "mouseover", this.iconOver.bind(this));
		NTEvent.add(this.icon, "mouseout",  this.iconOut.bind(this));
		
		if(this.title){
			this.msg = document.createElement("div");
			this.msg.style.position = "absolute";
			this.msg.appendChild(NTAgis.Object.Util.createPng("/ETlive/event/img/map/msgh.png",{width:100,height:10}));
			this.msg_text = document.createElement("div");
			st = this.msg_text.style;
			st.fontSize="75%";
			st.borderLeft = "1px #f19149 solid";
			st.borderRight = "1px #f19149 solid";
			st.backgroundColor = "#fff45c";
			st.width = "94px";
			st.padding = "2px";
			st.textAlign = "left";
			this.msg_text.innerHTML = this.title;
			this.msg.appendChild(this.msg_text);
			this.msg.appendChild(NTAgis.Object.Util.createPng("/ETlive/event/img/map/msgf.png",{width:100,height:15}));
			this.base.appendChild(this.msg);
			st = this.msg.style;
			//**************************
			//控制視窗縮小之後的訊息位置
			//**************************
			st.left="-30px";
			st.top = -(this.msg_text.offsetHeight+25)+"px";
			st.zIndex = 3002;
			
			this.msg.style.display="none";
		}

		this.bg = document.createElement("div");
		st = this.bg.style;
		st.width=this.width+"px";
		st.height=this.height+"px";
		st.backgroundColor="#35A";
		
		st.left="0px";
		st.top="0px";
		st.position = "absolute";
		st.border = "1px #126 solid";
		NTAgis.Object.Util.setAlpha(this.bg,85);
		this.base.appendChild(this.bg);
		
		this.head = document.createElement("div");
		st = this.head.style;
		st.textAlign="right";
		st.height="25px";
		st.position="relative";

		this.head_panel = document.createElement("div");
		if(this.title){
			this.head_panel.innerHTML = this.title;
			st = this.head_panel.style;
			st.position = "absolute";
			st.left="1px";
			st.top="4px";
			st.paddingLeft="2px";
			st.width = (this.base.offsetWidth-46)+"px"
			st.height = "1.1em";
			st.textAlign="left";
			st.color = "#FFF";
			st.fontWeight = "bold";
			st.overflow = "hidden";
		}

		this.button_close = document.createElement("img");
		st = this.button_close.style;
		st.margin="3px 1px 0px 0px";
		st.width="19px";
		st.height="19px";
		this.button_close.src="/ETlive/event/img/map/windowrclose.png";
		st.position = "relative";
		NTEvent.add(this.button_close, 'click', this.hide.bind(this));
		NTEvent.add(this.button_close, "mouseover", this.buttonCloseOver.bind(this));
		NTEvent.add(this.button_close, "mouseout", this.buttonCloseOut.bind(this));
		NTEvent.add(this.button_close, "mouseup", this.buttonCloseOut.bind(this));

		this.button_remove = document.createElement("img");
		this.button_remove.src="/ETlive/event/img/map/windowremove.png";
		this.button_remove.style.margin="3px 4px 0px 0px";
		this.button_remove.style.width="19px";
		this.button_remove.style.height="19px";
		this.button_remove.style.position = "relative";
		NTEvent.add(this.button_remove, 'click', this.close.bind(this));
		NTEvent.add(this.button_remove, "mouseover", this.buttonRemoveOver.bind(this));
		NTEvent.add(this.button_remove, "mouseout", this.buttonRemoveOut.bind(this));
		
		this.content = document.createElement("div");
		this.content.id = "NTWindowListContent"+Math.random(50000);
		st = this.content.style;
		st.position="relative";
		st.overflow="auto";
		st.backgroundColor="#FFF";
		st.margin="0px 4px 4px 3px";
		st.borderTop = "2px #249 solid";
		st.borderLeft = "2px #249 solid";
		st.width = (this.base.offsetWidth-10)+"px";
		st.height = (this.base.offsetHeight-32)+"px";
		st.textAlign="left";
		NTEvent.add(this.content, "DOMMouseScroll", this.wheelscroll.bind(this));
		NTEvent.add(this.content, "mousewheel",     this.wheelscroll.bind(this));

		this.mover = new NTAgis.Mover(this.base, {interval:-1});
		this.sizer = new NTAgis.Resizer(this.base, {interval:-1});
		this.transparencer = new NTAgis.Transparencer(this.bg, {interval:-1});

		this.sizer.setOption({speed:3, startx:1,starty:1,endx:this.base.offsetWidth, endy: this.base.offsetHeight, func:this.onload.bind(this)});
		this.sizer.run();
		
		var option = new Object();
		option.trigger = this.head_panel;
		option.area = [-this.base.parentNode.offsetLeft - (this.width-50),-this.base.parentNode.offsetTop,,];
		option.ondrag = this.activate.bind(this);
		new NTAgis.Object.DragDrop(this.base,option);
		
		// #5285
		NTWindow.Control.addList(this);
	},

	onload: function(){
		this.base.appendChild(this.head);
		this.head.appendChild(this.head_panel);
		this.head.appendChild(this.button_close);
		this.head.appendChild(this.button_remove);
		this.base.appendChild(this.content);
		if(this.data){
			this.data.func = this.onLoadFunc;
			this.get(this.data);
		}
		this.activate();
	},
	
	iconOver: function(e){
		this.cursor(e);
		if(this.title && this.msg){
			this.msg.style.display = "block";
		}
	},
	
	iconOut: function(e){
		this.cursor(e);
		if(this.title && this.msg){
			this.msg.style.display = "none";
		}
	},
	
	open: function(){
		if(this.hideIndex!=0 && this.lastpos){
			this.bg.style.display = "block";
			this.base.style.overflow="hidden";
			this.icon.style.display="none";
	
			this.mover.setOption({left:this.lastpos.x, top: this.lastpos.y});
			this.mover.run();
			this.sizer.setOption({endx:this.width, endy:this.height, func:this.onopen.bind(this)});
			this.sizer.run();
			this.transparencer.setOption({from: 20, to:70});
			this.transparencer.run();

			this.hideIndex = 0;
			this.lastpos = null;
		}
		this.activate();
	},
	
	onopen: function(){
		this.head.style.display="block";
		this.base.style.overflow="hidden";
		this.bg.style.display = "block";
		this.content.style.display="block";
		this.onOpenFunc();
	},
	
	hide: function(){
	
		this.lastpos = {x:NTAgis.S(this.base,"left"), y:NTAgis.S(this.base,"top")};
		this.head.style.display="none";
		this.content.style.display="none";
		//**************************
		//控制視窗縮放座標基準點
		//**************************
		this.mover.setOption({left:(485-(42*(NTWindow.Control.getEmptyHideIndex()))),top:350});
		this.mover.run();

		this.sizer.setOption({endx:40,endy:40, func:this.onhide.bind(this)});
		this.sizer.run();

		this.transparencer.setOption({from: 70, to:20});
		this.transparencer.run();

		this.hideIndex = NTWindow.Control.getEmptyHideIndex();
		
	},
	onhide: function(){
		this.bg.style.display="none";
		this.icon.style.display="block";
		this.base.style.overflow="visible";
		this.onHideFunc();
	},

	close: function(){
		NTWindow.Control.deleteList(this);
		NTAgis.Object.Util.removeElement(this.base);
		this.base=null;
		this.bg=null;
		this.content=null;
		this.data = null;
		this.onCloseFunc();
	},

	activate: function(){
		for(var i=0; i<NTWindow.Control.lists.length; i++){
			NTWindow.Control.lists[i].deactivate();
		}
		this.base.style.zIndex=3011;
		if(this.msg) this.msg.style.zIndex=3012;
		this.icon.style.zIndex=3013;
		this.bg.style.backgroundColor="#35A";
		this.head_panel.style.color="#FFF";
		this.onActivateFunc();
		NTWindow.Control.actWindow = this;
	},
	
	deactivate: function(){
		this.base.style.zIndex=3001;
		if(this.msg) this.msg.style.zIndex=3002;
		this.icon.style.zIndex=3003;
		this.bg.style.backgroundColor="#666";
		this.head_panel.style.color="#CCC";
		this.onDeactivateFunc();
	},

	move: function(a){
		new NTAgis.Mover(this.base, {endx:a.x, endy:a.y});
	},
	
	setTitle: function(a){
		this.title = a;
		this.head_panel.innerHTML = a;
		this.msg_text.innerHTML = a;
	},
	
	buttonCloseOver: function(e){
		this.button_close.src="/ETlive/event/img/map/windowrclose_ov.png";
	},

	buttonCloseOut: function(e){
		this.button_close.src="/ETlive/event/img/map/windowrclose.png";
	},

	buttonRemoveOver: function(e){
		this.button_remove.src="/ETlive/event/img/map/windowremove_ov.png";
	},

	buttonRemoveOut: function(e){
		this.button_remove.src="/ETlive/event/img/map/windowremove.png";
	}

	
});

NTWindow.Action = Class.create();
NTWindow.Action.prototype = Object.extend(new NTWindow(), {
	initialize: function(param){
	
		this.width = (param.width||270);
		this.height = (param.height||450);
		this.isOpen = false;
		this.base = document.createElement("div");
		this.base.id = "NTWindowAction"+Math.random(50000);
		var st=this.base.style;
		st.width = this.width+"px";
		st.height = this.height+"px";
		st.position = "absolute";
		st.zIndex = "2001"
		st.left = (param.x||0)+"px";
		st.top = (param.y||0)+"px";
		st.overflow = "hidden";
		$('action-window').appendChild(this.base);
		
		this.bg = document.createElement("div");
		st = this.bg.style;
		st.width=this.base.style.width;
		st.height=this.base.style.height;
		st.backgroundColor="#A82";
		st.left="0px";
		st.top="0px";
		st.position = "absolute";
		st.border = "1px solid";
		NTAgis.Object.Util.setAlpha(this.bg,70);
		this.base.appendChild(this.bg);
		
		this.head = document.createElement("div");
		st = this.head.style;
		st.textAlign="right";
		st.height="10px";
		st.borderBottom = "1px #777 solid";
		st.position="relative";

		this.button_close = NTAgis.Object.Util.createPng("/ETlive/event/img/map/action_close.png",{width:60,height:15});
		st = this.button_close.style;
		st.position = "absolute";
		st.left = (Math.floor(this.width/2)-30)+"px";
		st.top = (this.height-12)+"px";
		st.margin="0px";
		st.zIndex="2002";
		NTEvent.add(this.button_close, 'click', this.close.bind(this));
		NTEvent.add(this.button_close, "mouseover", this.cursor.bind(this));
		NTEvent.add(this.button_close, "mouseout",  this.cursor.bind(this));

		this.content = document.createElement("div");
		this.content.id = "NTWindowActionContent"+Math.random(50000);
		st = this.content.style;
		st.position="relative";
		st.overflow="auto";
		st.backgroundColor="#FFF";
		st.margin="4px";
		st.width = (this.base.offsetWidth-10)+"px";
		st.height = (this.base.offsetHeight-27)+"px";

		NTEvent.add(this.content, "DOMMouseScroll", this.wheelscroll.bind(this));
		NTEvent.add(this.content, "mousewheel",     this.wheelscroll.bind(this));

		if(param.source){
			this.source = param.source;
			this.source.style.visibility="visible";
			this.content.appendChild(this.source);
		}
		st.textAlign="left";	

		this.base.appendChild(this.head);
		this.head.appendChild(this.button_close);
		this.base.appendChild(this.content);
		this.base.style.display = "none";
		this.sizer = new NTAgis.Resizer(this.base,{interval:-1});
		
		NTWindow.Control.addAction(this);
	
	},
	open: function(data){
		if(this.isOpen) return;
		try{
			// まず開いているAction Windowをclose()する
			NTWindow.Control.getOpenAction().close(this.onAtherClose.bind(this));
		}catch(e){
			// 開かれてるAction Windowがない場合自身をopen()する
			this.onAtherClose(data);
		}
	},
	onAtherClose: function(data){
		this.base.style.display = "block";
		this.data = (data||null);
		this.sizer.setOption({speed:3, startx:this.width,starty:1,endx:this.width, endy:this.height, func:this.onopen.bind(this)})
		this.sizer.run();
		this.isOpen = true;
	},
	onopen: function(){
		if(this.data){
			this.get(this.data);
		}
		if(this.source){
			this.source.style.display="block";
		}
	},
	close: function(func){
		this.onCloseFunc = func;
		this.sizer.setOption({speed:3, startx:this.width,starty:this.height,endx:this.width, endy:1, func:this.onclose.bind(this)})
		this.sizer.run();
		this.isOpen = false;
	},
	onclose: function(){
		this.base.style.display = "none";
		if(typeof this.onCloseFunc=="function") this.onCloseFunc();
	}
});

NTWindow.Modal = Class.create();
NTWindow.Modal.prototype = Object.extend(new NTWindow, {
	initialize: function(option){
		this.onLoadFunc  = (option.onLoad|| function(){});
		this.onCloseFunc  = (option.onClose|| function(){});
		this.create(option);
		
	},
	create: function(option){
		this.width = (option.x||400);
		this.height = (option.y||400);
		this.base = document.createElement("div");
		this.base.className = "window-container";
		this.base.id = "NTWindowModal"+Math.random(50000);
		$('mainframe').appendChild(this.base);
		var st = this.base.style;
		st.display="none";
		st.position="absolute";
		st.zIndex=10000;
		st.width = NTAgis.P(this.width);
		st.height = NTAgis.P(this.height+20);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_1.png",{width:10,height:25});
		img.style.position="absolute";
		img.style.left=NTAgis.P(0);
		this.base.appendChild(img);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_2.png",{width:10,height:25});
		img.style.position="absolute";
		img.style.left=NTAgis.P(this.width-10);
		this.base.appendChild(img);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_bg.png",{width:(this.width-20),height:25});
		img.style.position="absolute";
		img.style.left="10px";
		this.base.appendChild(img);

		if(option.source){
			this.content = NTAgis.Object.copy(option.source);
			this.content.style.display ="block";
		}else{
			this.content = document.createElement("div");
			this.content.style.backgroundColor="#FFF";
			this.content.style.overflow = "auto";
			this.content.style.width = NTAgis.P(this.width);
			this.content.style.height = NTAgis.P(this.height);
		}
		this.content.id = "NTWindowModalContent"+Math.random(50000);
		this.content.style.position="absolute";
		this.content.style.top="25px";
		NTEvent.add(this.content, "DOMMouseScroll", this.wheelscroll.bind(this));
		NTEvent.add(this.content, "mousewheel",     this.wheelscroll.bind(this));
		this.base.appendChild(this.content);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_3.png",{width:10,height:10});
		img.style.position="absolute";
		img.style.left=NTAgis.P(0);
		img.style.top=NTAgis.P(this.height+25);
		this.base.appendChild(img);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_4.png",{width:10,height:10});
		img.style.position="absolute";
		img.style.left=NTAgis.P(this.width-10);
		img.style.top=NTAgis.P(this.height+25);
		this.base.appendChild(img);

		var img = NTAgis.Object.Util.createPng("/ETlive/event/img/map/modal_bg.png",{width:(this.width-20),height:10});
		img.style.position="absolute";
		img.style.left="10px";
		img.style.top=NTAgis.P(this.height+25);
		this.base.appendChild(img);

		this.button_remove = document.createElement("img");
		this.button_remove.src="/ETlive/event/img/map/windowremove.png";
		this.button_remove.style.position = "absolute";
		this.button_remove.style.left=NTAgis.P(this.width-26);
		this.button_remove.style.top=NTAgis.P(5);
		this.button_remove.style.width="19px";
		this.button_remove.style.height="19px";
		NTEvent.add(this.button_remove, 'click', this.close.bind(this));
		NTEvent.add(this.button_remove, "mouseover", this.buttonRemoveOver.bind(this));
		NTEvent.add(this.button_remove, "mouseout", this.buttonRemoveOut.bind(this));
		this.base.appendChild(this.button_remove);
		if(option.data){
			option.data.func = this.open.bind(this);
			this.get(option.data);
		}
	},
	open: function(){
		NTWindow.Control.modal = this;
		
		NTWindow.Control.lists.each(function(value,idx){
			value.base.style.visibility = "hidden";
		});
		if(NTWindow.Control.getOpenAction()) NTWindow.Control.getOpenAction().base.style.display="none";
		
//		NTWindow.Modal.bg.style.top = NTAgis.P(NTAgis.Object.Util.scroll());
		new NTAgis.Transparencer(NTWindow.Modal.bg, {from:20, to:60, speed:3, func:this.onLoadFunc.bind(this)});
		NTWindow.Modal.bg.style.display="block";

		var st = this.base.style;
		st.display="block";

		st.left = NTAgis.P(Math.floor((NTAgis.Object.Util.windowSize().windowWidth/2)-(this.content.offsetWidth/2)));
		st.top  = NTAgis.P(Math.floor((NTAgis.Object.Util.windowSize().windowHeight/2)-(this.content.offsetHeight/2))+NTAgis.Object.Util.scroll());
		
	},
	close: function(){
		NTWindow.Control.modal = null;
		this.base.style.display="none";
		new NTAgis.Transparencer(NTWindow.Modal.bg, {from:50, to:20, speed:3, func:this.onclose.bind(this)});
		NTWindow.Control.lists.each(function(value,idx){
			value.base.style.visibility = "visible";
		});
		if(NTWindow.Control.getOpenAction()) NTWindow.Control.getOpenAction().base.style.display="block";

		NTAgis.Object.Util.removeElement(this.base);
		this.base=null;
		this.content=null;
	},
	onclose: function(){
		this.onCloseFunc();
		NTWindow.Modal.bg.style.display="none";
	},
	buttonRemoveOver: function(e){
		this.button_remove.src="/ETlive/event/img/map/windowremove_ov.png";
	},

	buttonRemoveOut: function(e){
		this.button_remove.src="/ETlive/event/img/map/windowremove.png";
	}
});


NTEvent.add(window, "load", function(){
	
	if($('drive')) NTWindow.CarWindow = new NTWindow.Action({x:531, y:20, source:$('drive'), height: 572});//選單擺放的位置
	if($('gourmet')) NTWindow.GourmetWindow = new NTWindow.Action({x:531, y:20, source:$('gourmet'), height: 572});
	if($('totalnavi')) NTWindow.NaviWindow = new NTWindow.Action({x:531, y:5, source:$('totalnavi'), height: 535});
	if($('totalnavi_f')) NTWindow.FreeNaviWindow = new NTWindow.Action({x:580, y:195, source:$('totalnavi_f'), height: 424});

	NTWindow.Modal.bg = document.createElement("div");
	NTWindow.Modal.bg.style.backgroundColor="#000";
	NTWindow.Modal.bg.style.position="absolute";
	$('mainframe').appendChild(NTWindow.Modal.bg);

	NTWindow.Modal.bg.style.width = NTAgis.P(NTAgis.Object.Util.windowSize().windowWidth);
	NTWindow.Modal.bg.style.height = NTAgis.P(NTAgis.Object.Util.windowSize().pageHeight);
	NTWindow.Modal.bg.style.left = "0px";
	NTWindow.Modal.bg.style.top = "0px";
	NTWindow.Modal.bg.style.zIndex = 9990;
	NTWindow.Modal.bg.style.display="none";
	
});

NTPoiStatus = function(){};
NTPoiStatus.prototype = {
	name:null,
	address:null,
	tel:null,
	note:null,
	id:null,
	categoryId:null,
	categoryName:null,
	provId:null,
	spotId:null,
	groupId:null,
	vics:null,
	note:null,
	advId:null,
	catchCopy:null,
	img:null,
	navi:false,
	reset: function(){
		this.name=null;
		this.address=null;
		this.tel=null;
		this.note=null;
		this.id=null;
		this.categoryId=null;
		this.categoryName=null;
		this.provId=null;
		this.spotId=null;
		this.groupId=null;
		this.vics=null;
		this.note=null;
		this.advId=null;
		this.catchCopy=null;
		this.img=null;
		this.navi=false;
	}
}

var NTPoiCurrent = new NTPoiStatus();
var NTPoiInitial = new NTPoiStatus();
