//____________________________________________________________________
function i_Core(xEvent,EVDBServer){
	
	var self					= this;
	var user					= EVDBServer.user;
	
	var newEventBtnTooltip_str	= 'Create new event';
	var logoTitle_str			= 'Home';
	
	var logoId_str				= 'logo';
	var bannerImgId_str			= 'bannerImg';
	var bannerFrameId_str		= 'bannerFrame';
	var contentId_str			= 'content';
	var containerId_str			= 'contentContainer';
	var newEventBtnId_str 		= 'createNewEventButton';
	var bannerContainerId_str	= 'bannerContainer';
	var logoSrc_str				= '/_components/images/logo.png';
	var bannerFrameSrc_str		= '/_components/images/photo_frame.png';
	var advertisingId_str		= 'advertising';
	var bodyId_str				= 'contentBody';
	var bodyLinerId_str			= 'bodyLiner';
	var bodyCoverId_str			= 'bodyCover';
	var largeWhiteBordersPath_str 	= '/_components/images/borders/large_white/';
	var largeWhiteClassname_str	= 'largeWhite';
	
	var container_h;
	var loginScreen_h;
	var content_h;
	var footer_h;
	var bodyLiner_h;
	var bodyCover_h;
	var advertising_h;
	var XHTML_h;
	var bodyEnabled_bool		= true;
	
	var newEvent_btn;
	var storedHeight_int		= 0;

	// create panelset
	var panelset 				= new Panelset(this);
	var frontpagePanel			= panelset.createPanel('frontpage');
	var eventPanel				= panelset.createPanel('event');
	var contactPanel			= panelset.createPanel('contact');
	
	// generate XHTML structure
	createXHTML();
					
	// populate panels
	populateFrontpagePanel();
	populateContactPanel();
	populateEventPanel();
	window.app.redraw();
	
	// setup accessor methods
	this.__defineGetter__('XHTML_h',function(){return XHTML_h;});	
	this.__defineGetter__('bodyEnabled',function(){return bodyEnabled_bool;});
	this.__defineGetter__('loginScreen_h',function(){return loginScreen_h;});
	
	//----------------------------------------------------------------
	function populateEventPanel(){
		
		var iEvent 				= new i_Event(xEvent,EVDBServer,eventPanel,loginScreen_h);
		eventPanel.XHTML_h.appendChild(iEvent.XHTML_h);
	};
	//----------------------------------------------------------------
	function createXHTML(){
		
		// create document container
		container_h				= document.createHElement('div',null,containerId_str);
		window.app.content_h	= container_h;
		
		// create login screen
		createLoginScreen();
		
		// create widescreen image and frame
		var bannerContainer_h	= container_h.createChild('div',null,bannerContainerId_str);
		var protoBanner_h		= container_h.createChild('img',null,'prototypeBanner');
		protoBanner_h.src		= '/_components/images/prototype_banner.png';
		
		self.bannerImg_h		= bannerContainer_h.createChild('img',null,bannerImgId_str);
		xEvent.bannerImgURL.bindValueToAttribute(self.bannerImg_h,'src');
		var bannerFrame_h		= bannerContainer_h.createChild('img',null,bannerFrameId_str);
		bannerFrame_h.src		= bannerFrameSrc_str;
		
		var protoLink_h			= container_h.createChild('div',null,'prototypeLink');
		protoLink_h.title		= 'Prototype website: read more';
		protoLink_h.addEventListener('click',function(){window.location.href = '/about.htm';},false);		
		// generate logo 
		var logo_h				= bannerContainer_h.createChild('img',null,logoId_str);
		logo_h.title			= 'Home';
		logo_h.src				= logoSrc_str;
				
		// create content and subcontainers
		content_h				= container_h.createChild('div',null,contentId_str);
		var body_h				= content_h.createChild('div',null,bodyId_str);
		advertising_h			= content_h.createChild('div',null,advertisingId_str);
		bodyLiner_h				= body_h.createChild('div',null,bodyLinerId_str);		
		bodyLiner_h.appendBorders(largeWhiteBordersPath_str,largeWhiteClassname_str);

		// generate 'create new event' button
		newEvent_btn			= new i_Button(newEventBtnId_str,null,newEventBtnTooltip_str);
		advertising_h.appendChild(newEvent_btn.XHTML_h);
		window.app.newEvent_btn	= newEvent_btn;

		// add mashup links to advertising
		var links_h				= advertising_h.	createChild('div');
		links_h.innerHTML		= '<div class="mashupImg webkitchenImg"><a href="http://www.webkitchen.co.uk"><img src="/_components/images/webkitchen_logo_small.gif" title="Webkitchen" /></a></div><div class="mashupImg"><a href="http://evdb.com"><img src="/_components/images/evdb_logo.gif" title="EVDB" /></a></div><div class="mashupImg"><a href="http://www.google.com/apis/maps/"><img src="/_components/images/google_maps.gif" title="Google maps" /></a></div><div class="mashupImg"><a href="http://www.flickr.com"><img src="/_components/images/flickr_logo_beta.gif" title="flickr" /></a></div>'
				
		// append content
		bodyLiner_h.appendChild(panelset.XHTML_h);
		
		// append footer
		footer_h				= container_h.createChild('div',null,'footer');
		var webkitchenLink_h	= footer_h.createChild('a',null,'webkitchen_link','');
		webkitchenLink_h.href	= 'http://www.webkitchen.co.uk';
		webkitchenLink_h.title	= 'Developed by webkitchen.co.uk';
		var contactLink_h		= footer_h.createChild('a',null,'contact_link','contact');
		contactLink_h.href		= '/?page=contact';
		var divider_h			= footer_h.createChild('span',null,null,' | ');
		var aboutLink_h			= footer_h.createChild('a',null,'about_link','about eventsites');
		aboutLink_h.href		= '/about.htm';
		
		// add navigation handlers
		newEvent_btn.handleClick = function(){window.app.navigate('newEvent');};

		logo_h.addEventListener('mousedown',function(){window.location.href = '/';},false);
		
		// setup height polling
		window.setInterval(pollBodyHeight,500);
		
		XHTML_h					= container_h;;
	};
	//----------------------------------------------------------------
	function createLoginScreen(){
		
		// create structure
		loginScreen_h			= document.createHElement('div',null,'loginScreen');
		loginScreen_h.appendBorders(largeWhiteBordersPath_str,largeWhiteClassname_str);
		var loginLiner_h		= loginScreen_h.createChild('div',null,'loginLiner');
		user.bindConnectionStateToAttribute(loginLiner_h,'connected');
	
		// create cancel button
		var cancel_btn			= new i_Button('cancelButton',null,'Cancel login');
		loginLiner_h.appendChild(cancel_btn.XHTML_h);
		cancel_btn.handleClick	= function(){window.app.setLoginDisplay(false);};
		
		// create title
		loginLiner_h.createChild('h1',null,'loginTitle','Login');
		
		// inputs container
		var inputsContainer_h	= loginLiner_h.createChild('div',null,'eventfulLoginContainer');
		var userInput			= new i_Input(inputsContainer_h,null,'Eventful username');
		var passwordInput		= new i_Input(inputsContainer_h,null,'Password');
		passwordInput.input_h.type = 'password';
		passwordInput.addEventListener('returnPress',executeLogin);
		
		// execute button
		var login_btn			= new i_Button('loginButton',null,'Login');
		inputsContainer_h.appendChild(login_btn.XHTML_h);
		login_btn.handleClick 	= executeLogin;
		
		// forgotten password link and get a password link
		var forgottenLink_h		= inputsContainer_h.createChild('a',null,'forgottenPasswordLink','Forgotten your password?');
		forgottenLink_h.href	= 'http://eventful.com/forgot?';
		forgottenLink_h.target	= '_blank';
		
		// get a password link
		var getPassword_h		= inputsContainer_h.createChild('a',null,'getPasswordLink','Create an account (it\'s free)');
		getPassword_h.href		= 'http://eventful.com/register';
		getPassword_h.target	= '_blank';
		
		// add screen remover
		user.addEventListener('login',handleLogin);
		//------------------------------------------------------------
		function handleLogin(){
			
			passwordInput.input_h.value = '';
			loginScreen_h.parentNode? loginScreen_h.parentNode.removeChild(loginScreen_h) : null;
		};
		//------------------------------------------------------------
		function executeLogin(){
			
			user.login(userInput.input_h.value,passwordInput.input_h.value);
		};
	};	//------------------------------------------------------------
	//----------------------------------------------------------------
	function populateContactPanel(){
		
		var parent_h			= contactPanel.XHTML_h;
		parent_h.innerHTML 		= '<div id="contactInfo"><h1>Contact</h1><p>I hope the site has been of use and of interest to you and would welcome any thoughts you might have on how to improve it.</p><p>Good or bad you can get it touch with me by mailing: <em><a href="mailto:events@webkitchen.co.uk">events@webkitchen.co.uk</a></em> or you can Skype me at <em><a href="skype:petenixey">petenixey</a></em>.</p><p>If you\'d like to know more about eventsites and how and why it was built you can read the introduction in the <a href="/about.htm">about</a> section or follow the articles on it at my personal site, <a href="http://www.webkitchen.co.uk">webkitchen.co.uk</a>.</p></div>';
	};
	//----------------------------------------------------------------
	function populateFrontpagePanel(){
		
		var parent_h			= frontpagePanel.XHTML_h;
		
		// create interview panela
		var orgPanel_h			= parent_h.createChild('div','featurePanel');
		orgPanel_h.createChild('h1',null,null,'Are you organising...');
		orgPanel_h.createChild('p',null,null,'a dinner?');
		orgPanel_h.createChild('p',null,null,'a meetup?');
		orgPanel_h.createChild('p',null,null,'a game of football?');
		
		// crate offer panel
		var offerPanel_h		= parent_h.createChild('div','featurePanel','offerPanel');
		offerPanel_h.createChild('h1',null,null,'Would you like...');
		offerPanel_h.createChild('p',null,'signupOffer','a website?');
		offerPanel_h.createChild('p',null,'mapOffer','a map?');
		offerPanel_h.createChild('p',null,'photoOffer','a photo page?');
		
		// create lead panel
		var leadPanel_h			= parent_h.createChild('div','featurePanel');
		leadPanel_h.appendBorders(largeWhiteBordersPath_str,largeWhiteClassname_str);
		leadPanel_h.createChild('h1',null,null,'...try eventsites');
		leadPanel_h.createChild('p',null,null,'it\'s quick');
		leadPanel_h.createChild('p',null,null,'it\'s free');
		leadPanel_h.createChild('p',null,null,'it\'s easy');
		var startButton			= new i_Button('startButton',null,'Create a new event');
		startButton.handleClick	= function(){window.app.navigate('newEvent');};
		leadPanel_h.appendChild(startButton.XHTML_h);
		
		// create example events
		var previousEvents_h	= parent_h.createChild('div',null,'previousEvents');
		previousEvents_h.createChild('h2',null,null,'See events other people have created:');
		var pizza_h				= previousEvents_h.createChild('a','exampleEvent',null,'Pizza on Rails');
		pizza_h.href			= '/evdb/events/E0-001-000854086-8';
		var webApps_h			= previousEvents_h.createChild('a','exampleEvent',null,'Future of Web Apps Summit');
		webApps_h.href			= '/evdb/events/E0-001-000935917-5';
		
		// create about section
		var about_h				= parent_h.createChild('div',null,'aboutPanel','.');
		
		// add behaviours
		frontpagePanel.addEventListener('select',handleSelectionEvent);
		frontpagePanel.addEventListener('deselect',handleSelectionEvent);
		handleSelectionEvent();
		
		//------------------------------------------------------------
		function handleSelectionEvent(){
			
			setAdVisibility(!frontpagePanel.selected);
		};	
	};	//------------------------------------------------------------
	//----------------------------------------------------------------
	function pollBodyHeight(){
	// stops the window resizing and causing the view to jump around when 	
	// elements are removed from view
	
		var liveHeight_int		= parseInt(getComputedStyle(document.body,null).height);
		if(liveHeight_int > storedHeight_int){
			storedHeight_int	= liveHeight_int;
			document.body.style.minHeight = liveHeight_int+'px';
			var str = liveHeight_int+'px';
		}
	};
	//----------------------------------------------------------------
	function setAdVisibility(visibility_bool){
		
		container_h.setAttribute('advertising',visibility_bool);
	};
	//________________________________________________________________
	this.setAdVisibility = setAdVisibility;
};	//________________________________________________________________
//____________________________________________________________________