function viewComment( id ) {
	this.id = id;
	
	this.commentObj = document.createElement('div');
	this.commentObj.id = "comment-"+id;
	this.commentObj.className = "commentBox";
	var postObj = document.getElementById("entry-"+this.id);
		postObj.parentNode.insertBefore(this.commentObj, postObj.nextSibling);
	var addBtn = "<div id='insertCursor' class='jsButton' style='width:100px;float:none;'"
				+" onclick='new addComment("+this.id+")'>Add "+commentName+"</div> \n"
				+" <div id='commentBox-"+this.id+"'></div>";
	
	var thisObj = this;
	this.commentGrabber = function(response) {
		thisObj.commentObj.innerHTML = addBtn+response;
		thisObj.finalHeight = thisObj.commentObj.offsetHeight;
		thisObj.animation.setAttribute('height', "0px");
		thisObj.animation.setAttribute('position', "relative");
		
		thisObj.openComments();
	}
	this.init = function () {
		this.animation = new Animation(this.commentObj);
		
		this.animation.setAttribute('position', "absolute");
		this.animation.setAttribute('overflow', 'hidden');
		this.animation.setAttribute('opacity', 0);
				
		this.buttonObj = document.getElementById("view-"+this.id);
		this.commentText = this.buttonObj.innerHTML;
		this.buttonObj.innerHTML = "Loading...";
		this.buttonObj.onclick = null;
		
		shortRequest("/blog/fastComm.php?id="+id+"&owner="+owner , this.commentGrabber );
	}
	
	this.openComments = function () {
		var thisObj = this;
		this.animation.setMovement('height', this.finalHeight+"px");
		this.animation.setMovement('opacity', 1);
		this.animation.setEndFunc( function() { thisObj.animation.setAttribute("height", "auto"); } );
		this.animation.start();
		
		this.buttonObj.innerHTML = "Hide "+commentName;
		this.buttonObj.onclick = function () { thisObj.closeComments( id ) };
	}
	
	this.closeComments = function () {
		this.animation.setAttribute('height', this.animation.obj.offsetHeight+"px");
		this.animation.setEndFunc( null );
		this.animation.setMovement('height', "0px");
		this.animation.setMovement('opacity', 0);
		this.animation.start();
		
		this.buttonObj.innerHTML = this.commentText;
		this.buttonObj.onclick=function () { thisObj.openComments() };
	}
	
	this.init();
}

function addComment(id) {
	this.id = id;
	this.inputMod = null;
	
	this.container = document.getElementById("commentBox-"+id);
	this.newComm = document.createElement("div");
	this.container.insertBefore(this.newComm, this.container.firstChild);
	
	this.saveBtn = document.createElement("div");
	this.saveBtn.className = "jsButton";
	this.saveBtn.innerHTML = "Save";
	
	this.cancelBtn = document.createElement("div");
	this.cancelBtn.className = "jsButton";
	this.cancelBtn.innerHTML = "Cancel";
	
	var thisObj = this;
	this.saveFunc = function () {
		var respondFunc = function (response) { 
			if (response.indexOf("Success") != -1) {
			try {
				var newID = parseInt(response.substr(response.indexOf(":")+2));
				
				thisObj.inputMod.clear(); 
				thisObj.buttons.innerHTML = "Add "+commentName;
				thisObj.buttons.onclick = function () { addComment(newID) };				
				
				document.getElementById("comment--1").id = "comment-"+newID;
				document.getElementById("commentBtns--1").id = "commentBtns-"+newID;
			} catch (e) {alert(e);};
			} else alert(response);
		};
		
		postArray("/blog/fastComm.php?action=addComment&id="+thisObj.id+"&owner="+owner, respondFunc, thisObj.inputMod.getData());
	}
	
	this.respondFunc = function (response) {
		thisObj.newComm.innerHTML = response;	
		thisObj.inputMod = new InputMod(thisObj.newComm);
		
		thisObj.saveBtn.onclick = thisObj.saveFunc;
		thisObj.cancelBtn.onclick = function () {
			thisObj.container.removeChild(thisObj.newComm);
		}
		
		thisObj.buttons = document.getElementById("commentBtns--1");
		thisObj.buttons.onclick = null; thisObj.buttons.innerHTML = "";
		thisObj.buttons.appendChild(thisObj.saveBtn);
		thisObj.buttons.appendChild(thisObj.cancelBtn);
	}
	
	shortRequest("/blog/fastComm.php?action=getEmptyComment&id="+this.id+"&owner="+owner, this.respondFunc);
}
