function ideasPoster() {

	var mySelf = this;

	this.addIdeaDiv = null;
	this.addProjectDiv = null;
	this.expandedProjects = new Array();

	//public functions
	//----------------------------------
	this.addIdea = addIdea;
	this.addProject = addProject;
	this.closeDiv = closeDiv;
	this.submitIdea = submitIdea;
	this.changeIdeaState = changeIdeaState;
	this.deleteIdea = deleteIdea;

	this.submitProject = submitProject;
	this.toggleProject = toggleProject;
	this.addSection = addSection;
	this.deleteSection = deleteSection;
	//----------------------------------


	//shows an addIdea box with a text box.
	function addIdea(pid) {
	    if (mySelf.addIdeaDiv == null) {
	        mySelf.addIdeaDiv = createPopupDiv((document.body.offsetWidth/2)-150, (document.body.offsetHeight/2)-150, 300, 300);
	        document.body.appendChild(mySelf.addIdeaDiv);
	        addPhpToDiv(mySelf.addIdeaDiv, 'includes/ajaxPages/addIdea.php?pid='+pid, true);
	        fadePageOn();
	    }
	}

	function addProject() {
	    if (mySelf.addProjectDiv == null) {
	        mySelf.addProjectDiv = createPopupDiv((document.body.offsetWidth/2)-150, (document.body.offsetHeight/2)-30, 300, 60);
	        document.body.appendChild(mySelf.addProjectDiv);
	        addPhpToDiv(mySelf.addProjectDiv, 'includes/ajaxPages/addProject.php', true);
	        fadePageOn();
	    }
	}

	//add a "section" (project) to a project with id
	function addSection(id) {
	    if (mySelf.addProjectDiv == null) {
	        mySelf.addProjectDiv = createPopupDiv((document.body.offsetWidth/2)-150, (document.body.offsetHeight/2)-30, 300, 60);
	        document.body.appendChild(mySelf.addProjectDiv);
	        addPhpToDiv(mySelf.addProjectDiv, 'includes/ajaxPages/addSection.php?pid='+id, true);
	        fadePageOn();
	    }
	}

	function closeDiv() {
		if (mySelf.addIdeaDiv != null) {
	        document.body.removeChild(mySelf.addIdeaDiv);
	        mySelf.addIdeaDiv = null;
	        fadePageOff();
	    }
	    else if (mySelf.addProjectDiv != null) {
	        document.body.removeChild(mySelf.addProjectDiv);
	        mySelf.addProjectDiv = null;
	        fadePageOff();
	    }
	}

	//if id is not set, then we assume we are creating a top level project,
	//else, create a project (or 'section') underneath the project with id
	function submitProject(id) {
		var url = '../includes/submits/projectSubmit.php?title='+document.getElementById('projectTitle').value;
		if (typeof(id) != "undefined")
			url += "&pid="+id;

		var errorDiv = document.getElementById('addProjectErrorDiv');
		var successFunction = '';
		if (typeof(id) != "undefined") {
			//id is defined, so add a Section
			successFunction = function() {	
				//addPhpToDiv(document.getElementById('content'), '../includes/postIdeaPage.php', true);
				addPhpToDiv(document.getElementById('pid'+id), '../includes/ajaxPages/getAllItemsInProject.php?pid='+id, true);				
				ideaMaker.closeDiv();
			};
		}
		else {
			//id not defined, so add to top level
			successFunction = function() {	
				addPhpToDiv(document.getElementById('content'), '../includes/postIdeaPage.php', true);
				collapseAllProjects();
				ideaMaker.closeDiv();
			};
		}
		submitToPhp(url, errorDiv, successFunction, '');
	}

	//add an idea to a project (or 'section') with id
	function submitIdea(pid) {
		var poststr = "ideaTitle=" + encodeURI( document.getElementById('ideaTitle').value )+"&ideaText=" + encodeURI( document.getElementById('ideaText').value ) + "&projectId=" + encodeURI(pid);
		var query = "../includes/submits/ideaSubmit.php";
		var errorDiv = document.getElementById('addIdeaErrorDiv');
		var successFunction = function() {
			addPhpToDiv(document.getElementById('children'+pid), '../includes/ajaxPages/getProjectIdeas.php?pid='+pid, true);
			ideaMaker.closeDiv();
		};
		submitToPhp(query, errorDiv, successFunction, poststr);		
	}


	function changeIdeaState(id, state) {
		var successFunction = function() {
			addPhpToDiv(document.getElementById('content'), '../includes/postIdeaPage.php', true);
		}
		var queryText = '../includes/submits/ideaStateChangeSubmit.php?id='+id+'&state='+state;
		addPhpToDiv(document.getElementById('sid'+id), queryText, true);
	}

	function deleteIdea(id) {
		if (confirm("Delete this idea?")) {
			var successFunction = function() {
				var rowToDelete = document.getElementById('sid'+id);
		    	rowToDelete.parentNode.removeChild(rowToDelete);
			}
			var queryText = '../includes/submits/ideaDeleteSubmit.php?id='+id;
			submitToPhp(queryText, document.getElementById('projectErrorDiv'), successFunction, '')
		}
	}

	function deleteSection(id) {
		if (confirm("Delete this select and all items within it?")) {
			var successFunction = function() {
				var rowToDelete = document.getElementById('entire'+id);
		    		rowToDelete.parentNode.removeChild(rowToDelete);
			}
			var queryText = '../includes/submits/projectDeleteSubmit.php?pid='+id;
			submitToPhp(queryText, document.getElementById('projectErrorDiv'), successFunction, '')
		}
	}

	function collapseAllProjects() {
		for (var i = 0; i < mySelf.expandedProjects.length; i++) {
			if (mySelf.expandedProjects[i] != null)
				mySelf.expandedProjects[i] = false;
		}
	}

	function toggleProject(id) {
		//find the current state of this project (if any), and switch it
		if (this.expandedProjects[id] == null)
			this.expandedProjects[id] = true; //not found, so open this project
		else
			this.expandedProjects[id] = !this.expandedProjects[id]; //found, so toggle the project

		outputDiv = document.getElementById('pid'+id);
		imageDiv = document.getElementById('i'+id);
		controlPanelDiv = document.getElementById('cp'+id);
		if (this.expandedProjects[id]) {
			outputDiv.innerHTML = '<blockquote>Loading...</blockquote>';
			addPhpToDiv(outputDiv, '../includes/ajaxPages/getAllItemsInProject.php?pid='+id, true);
			controlPanelDiv.style.display = '';
			imageDiv.src = 'images/minus.jpg';
		}
		else {
			outputDiv.innerHTML = '';
			controlPanelDiv.style.display = 'none';
			imageDiv.src = 'images/plus.jpg';
		}
	}

}