
Ext.namespace("Ext.hansub.camping");

Ext.hansub.camping.MyCampingMapPanel = function(config) {
	this.isfirst = true;
	this.config = config;

	var iconUrl = './images/icons/flag_red.png';
	this.iconA = new NIcon(iconUrl, new NSize(16,16))

	var iconUrl = './images/info/campmarksingle.png';
	this.iconB = new NIcon(iconUrl, new NSize(30,24))
	
	
	Ext.hansub.camping.MyCampingMapPanel.superclass.constructor.call(this, this.config);
	
	/**{
		this.config
		
		
		id:this.config.id,
		title:this.config.title,
		region:this.config.region,
		//autoWidth:false,
 		iconCls:'globe',
		layout:'fit',
		//width:500,
		height:800,
		//margins: '10 10 10 10',
		closable:false,
		split: true,
		border:this.config.border,
		defaults: {autoScroll:true}
        
	});
	**/

  this.on('afterRender', this.init, this);
};

Ext.extend(Ext.hansub.camping.MyCampingMapPanel, Ext.Panel, {

	
	init : function(){
		
		if (this.isfirst) {
			this.makeMap();
			this.markMyCamping();
		}
		
		this.isfirst = false;
		
	},
	
	makeMap : function(){
		
		size = this.getSize();
		
		
		
		//opts = {width:size.width, height:size.height, mapMode:1};
		opts = {width:this.config.width, height:this.config.height, mapMode:0};

		this.mapObj = new NMap(document.getElementById(this.getId()),opts);
		this.infowin = new NInfoWindow();
		this.mapObj.addOverlay(this.infowin);

					
		this.mapObj.setCenterAndZoom(new NPoint(405464,464389),this.config.level);
		
			
		zoom = new NZoomControl();
		
		zoom.setAlign("right");
		zoom.setValign("top");
		this.mapObj.addControl(zoom);
		
		
		mapBtns = new NMapBtns();
		mapBtns.setAlign("right");
		mapBtns.setValign("top");
		this.mapObj.addControl(mapBtns);
		
		
		

			
	
	},
	
	
	markMyCamping : function(){
		//alert(this.config.camping_user_uid);	
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
					'class':'Camping',
					'method':'getMyCampinglist',
					isall : this.config.isall,
					camping_user_uid :this.config.camping_user_uid
					},
			waitMsg:'캠핑정보를 로딩중  입니다.',
			scope:this,
			success:function(response, options){
				
				var json = Ext.decode(response.responseText);
				
				if(json.success){
					
		  		//alert(this.config.camping_user_uid);

					for (i = 0; i < json.list.length; i++) {
				    //if(EMAIL != "root@naver.com")
						this.mapObj.addOverlay(this.createMarker(new NPoint(json.list[i].x,json.list[i].y),1,json.list[i].name,json.list[i].uid,json.list[i].isconqueror,json.list[i].camping_list_uid,this.infowin));
						
					}
					
            		
            	}else{
            		Ext.MessageBox.alert('캠핑정보를 로딩 에러', json.msg)
            	}
			},
			failure:function(response, options){
				Ext.MessageBox.alert('캠핑정보를 로딩  에러', '캠핑정보를 로딩 에러가 발생하였습니다.')
			}
			            	
					
		});	
		
	},
	
	
	createMarker:function(pos, count, content, uid, isconqueror,camping_list_uid, infowin) {
		
		var marker;
		if(isconqueror){
			var iconUrl = './images/icons/flag_red.png';
			var size = {w:16,h:16};
			var title = '<div style="background-color:#ffcc33; border:solid 1px #666666;">정복완료 :' + content + '</div>'
  		marker = new NMark(pos, this.iconA);
		}else{
			var iconUrl = './images/info/campmarksingle.png';
			var size = {w:30,h:24};
			//var iconUrl = './images/icons/flower_daisy.png';
			//var size = {w:16,h:16};
			var title = '<div style="background-color:#dddddd; border:solid 1px #666666;">' + content + '</div>'
  		marker = new NMark(pos, this.iconB);
		}
		//var marker = new NMark(pos, new NIcon(iconUrl, new NSize(size.w,size.h)));

		NEvent.addListener(marker, "mouseover", function(pos) {
			
			infowin.set(pos, title);
			
			infowin.showWindow();
		});
		NEvent.addListener(marker, "mouseout", function() {
			infowin.hideWindow();
		});
		NEvent.addListener(marker, "click", function() {
			
			
			if (Ext.getCmp("CampingWrapperPanel_"+uid)) {
				alert("exsited");
				Ext.getCmp('centerCenterPanel').activate("CampingWrapperPanel_"+uid);
			}
			else {
				
				data = {
						camping_list_uid : camping_list_uid,
						x:pos.x,
		 				y:pos.y
		  			};
				
				this.campingDetailPortalPanel = new Ext.hansub.camping.CampingDetailPortalPanel({
													id:"CampingWrapperPanel_"+uid,
													x:pos.x,
									  				y:pos.y,
													name: content,
													camping_uid:camping_list_uid,
													record_data : data
												});
				
				Ext.getCmp('centerCenterPanel').add(this.campingDetailPortalPanel);
				Ext.getCmp('centerCenterPanel').activate(this.campingDetailPortalPanel);
			}
			
			/**
			if (Ext.getCmp("CampingWrapperPanel_"+uid)) {
		
				Ext.getCmp('centerCenterPanel').activate("CampingWrapperPanel_"+uid);
			}else{

	 			//alert("click:"+pos.x);
		  	data = {
				camping_list_uid : camping_list_uid,
				x:pos.x,
 				y:pos.y
  			}
		  
  			this.campingWrapperPanel = new Ext.hansub.camping.CampingWrapperPanel({
  				id:"CampingWrapperPanel_"+uid,
  				x:pos.x,
  				y:pos.y,
  				name:content,
  				'camping_uid':camping_list_uid,
  				record_data : data
  			});
  			Ext.getCmp('centerCenterPanel').add(this.campingWrapperPanel);
  			Ext.getCmp('centerCenterPanel').activate(this.campingWrapperPanel);
      
		}
			
			**/
			
			
			
			
		});
		return marker;
	}
	
	
	
	
});

