//____________________________________________________________________
function i_EditEvent(xEvent,panelsetOwnerObj,EVDBServer,loginScreen_h){
	
	var self				= this;
	var user				= EVDBServer.user;
	
	var XHTML_h;
	var loginScreenContainer_h;
	var panelCover_h;
	
	var panelset			= new Panelset(panelsetOwnerObj);
	panelset.createPanel('details');
	panelset.createPanel('map');
	panelset.createPanel('style');
	
	populateDetailsPanel();
	populateMapPanel();
	populateStylePanel();
	
	createXHTML();
	this.__defineGetter__('XHTML_h',function(){return XHTML_h;});
	
	window.app.updateLoginDisplay 	= updateLoginDisplay;
	window.app.setLoginDisplay		= setLoginDisplay;
	window.app.getUnsavedChangesState = function(){return xEvent.unsavedChanges;};
	
	//----------------------------------------------------------------
	function createXHTML(){
	
		var container_h			= document.createHElement('div',null,'editEventPanelset');
		loginScreenContainer_h 	= container_h.createChild('div','loginScreenContainer');
	
		// create navigation 
		var navigation_h		= container_h.createChild('div',null,'editEventNavigation');
		var detailsNav_h		= createNavItem_h(navigation_h,'Details','details');
		var mapNav_h			= createNavItem_h(navigation_h,'Venue','map');
		var mapNav_h			= createNavItem_h(navigation_h,'Style','style');
		
		// create save indicator
		var saveIndicator_h		= container_h.createChild('div',null,'saveIndicator');
		var saveConfirm_h		= saveIndicator_h.createChild('em',null,null,'changes saved');
		xEvent.addEventListener('successfulSave',displaySaveConfirmation);
		xEvent.bindSaveStateToAttribute(saveIndicator_h,'active');
		
		// create save button
		var save_btn			= new i_Button('saveEVDBButton',null,'');
		container_h.appendChild(save_btn.XHTML_h);
		save_btn.handleClick	= function(){xEvent.saveChanges();};
		xEvent.addEventListener('changesDelta',determineSaveButtonState);
		determineSaveButtonState();
		
		// create logout button
		var logout_btn			= new i_Button('logoutEVDBButton',null,'Logout of Eventful');
		container_h.appendChild(logout_btn.XHTML_h);
		logout_btn.handleClick 	= function(){user.logout();};
		user.addEventListener('login',determineLogoutButtonState);
		user.addEventListener('logout',determineLogoutButtonState);
		determineLogoutButtonState();
		
		// attach and populate panelset
		container_h.appendChild(panelset.XHTML_h);
		XHTML_h					= container_h;
		
		// setup login monitoring
		user.addEventListener('login',updateLoginDisplay);
		user.addEventListener('logout',updateLoginDisplay);
		updateLoginDisplay();
		
		//------------------------------------------------------------
		function determineLogoutButtonState(){
			
			if(user.loggedIn && xEvent.id.value){
				logout_btn.enable();
			}else{
				logout_btn.disable();
			}
		};
		//------------------------------------------------------------
		function displaySaveConfirmation(){
			
			saveIndicator_h.setAttribute('displayConfirmation',true);
			window.setTimeout(function(){saveIndicator_h.setAttribute('displayConfirmation',false)},2000);
		};
		//------------------------------------------------------------
		function determineSaveButtonState(){
			
			if(xEvent.unsavedChanges){
				save_btn.enable();
				var title_str	= 'Save changes';
			}else{
				save_btn.disable();
				title_str		= 'All changes are saved';
			}
			save_btn.XHTML_h.title = title_str;
		};
		//------------------------------------------------------------
		function createNavItem_h(parent_h,label_str,panelName_str){
			
			var navItem_h		= parent_h.createChild('div','editNavButton',null,label_str);
			panelset.panels[panelName_str].createSelector(navItem_h);
			return navItem_h;
		};
	};	//------------------------------------------------------------
	//----------------------------------------------------------------
	function setLoginDisplay(display_bool){
		
		loginScreenContainer_h.setAttribute('active',display_bool);
		display_bool? loginScreenContainer_h.appendChild(loginScreen_h) : null;
	};
	//----------------------------------------------------------------
	function updateLoginDisplay(forceDisplay_bool){
		
		if(forceDisplay_bool){
			var display_bool	= true;
		}else{
			display_bool		= xEvent.id.value && !user.loggedIn;
		}
		setLoginDisplay(display_bool);
	};
	//----------------------------------------------------------------
	function populateStylePanel(){
		
		var parent_h			= panelset.panels.style.XHTML_h;
		var container_h			= parent_h.createChild('div');
		container_h.createChild('p',null,null,'Add a personal touch and customise your event\'s banner.');
		container_h.createChild('p',null,null,'The image you use should be 825px wide and 248px high and its format can be .jpg, .gif or .png.');
		createIInput(container_h,'bannerImgURL',true);
		var thumb_h				= container_h.createChild('img','bannerImgThumb');
		xEvent.bannerImgURL.bindValueToAttribute(thumb_h,'src');
	};
	//----------------------------------------------------------------
	function populateDetailsPanel(){
		
		var parent_h		= panelset.panels.details.XHTML_h;
		
		// create URL container
		var urlContainer_h	= parent_h.createChild('div',null,'eventURL');
		window.app.webpageLink_h = urlContainer_h;
		var urlLabel_h		= urlContainer_h.createChild('div',null,null,'Event webpage: <span id="makeNote">(please make a note of this)</span>');
		var url_h			= urlContainer_h.createChild('a');
		url_h.title			= 'Event webpage';
		url_h.target		= '_blank';
		xEvent.eventsitesURL.bindValueToInnerHTML(url_h);
		xEvent.eventsitesURL.bindValueToAttribute(url_h,'href');
			
		
		createIInput(parent_h,'title',true);
		xEvent.startTimeProp.createInputCell(parent_h);
		createIInput(parent_h,'description',false,true);
		createIInput(parent_h,'flickr_tag',true);
	};	
	//----------------------------------------------------------------
	function createIInput(parent_h,eventProperty_str,longInput_bool,textarea_bool){
		
		var property			= xEvent[eventProperty_str];
		var iInput				= new i_Input(parent_h,property,null,textarea_bool);
		iInput.XHTML_h.id 		= 'edit_'+eventProperty_str;
		if(longInput_bool){
			iInput.XHTML_h.className = iInput.XHTML_h.className+' longInput';
		}
		return iInput;
	};
	//----------------------------------------------------------------
	function createVenueIInput(parent_h,property_str,longInput_bool,textarea_bool){
		
		var property			= xEvent.venue[property_str];
		var iInput				= new i_Input(parent_h,property,null,textarea_bool);
		iInput.XHTML_h.id 		= 'edit_'+property_str;
		if(longInput_bool){
			iInput.XHTML_h.className = iInput.XHTML_h.className+' longInput';
		}
		return iInput;
	};
	//----------------------------------------------------------------
	function populateMapPanel(){
		
		var parent_h			= panelset.panels.map.XHTML_h;
		
		
		// create map (offscreen initially)
		var mapContainer_h		= parent_h.createChild('div','gMap','editingGMap');
		var venueMap			= new VenueMap(xEvent,mapContainer_h);
		panelset.panels.map.addEventListener('select',function(){venueMap.initialise(true);});
		panelset.panels.map.addEventListener('deselect',function(){venueMap.deactivate();});
		
		parent_h.createChild('strong',null,null,'<em>click on and zoom the map to set the location</em><br /><br />');
		
		createVenueIInput(parent_h,'name',true);
//		createVenueIInput(parent_h,'url',true);
		createVenueIInput(parent_h,'address',true,true);
		
		
		var iInput				= new i_Input(parent_h,xEvent.venue.description,'Description / instructions',true);
		iInput.XHTML_h.id		= 'editVenueDescription';
		
		//------------------------------------------------------------
		function handleMapClick(gClick){

			if(xEvent.latitude.editable && xEvent.longitude.editable){
				var gPoint				= gClick.gPoint;
				googleMap.addTemporaryMarker(gClick.gPoint);
				xEvent.latitude.value	= gPoint.y;
				xEvent.longitude.value	= gPoint.x;
			}
		};
	};	//------------------------------------------------------------
};	//________________________________________________________________
//____________________________________________________________________