<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/SQLConnect.php");

Class Commenter{
	private $site_area_ID;
	private $user_data;

	public function __construct($site_area_ID,$user_data){
		$this->site_area_ID = $site_area_ID;
		$this->user_data = $user_data;
	}
	
	public function getLink(){
		if(PAGE_USES_FACEBOX)
			return '<a href="#s'.$this->site_area_ID.'" rel="facebox" class="comment" onclick="setLastClicked('.$this->site_area_ID.')"><img src="images/comment.gif"><div class="counter" id="counter'.$this->site_area_ID.'">0</div></a>';
		else
			return null;
	}
	public function getSupportingHTML(){
		if(PAGE_USES_FACEBOX){
			require_once($_SERVER['DOCUMENT_ROOT']."/includes/classes/Comments.inc.php");
		?>
			
				<div class="sitearea-container sitearea-container<?=$this->site_area_ID;?>">
					<div class="sitearea" id="s<?=$this->site_area_ID;?>">
						<div id="c<?=$this->site_area_ID;?>">
							<?php
							
							$Comments = new Comments($this->user_data['ID'],$this->site_area_ID,0);
							$comments = $Comments->getComments();
							?>
							<ul class='comments'>
								<?php	
								if(is_array($comments)){
									foreach($comments as $comment){
									?>
										<li>
											<?=stripslashes($comment['body']);?>
											<div class='attribution'>
												<b><?=$comment['first_name'].' '.$comment['last_name'];?></b> - <?=format_datetime($comment['timestamp']);?>
											</div>
										</li>
									<?php
									}
								}
								
								
								?>
							</ul>
							<input type="hidden" class="hidden" value='<?=$this->site_area_ID;?>' id='site_area_ID'>
							<textarea rows="3" id="post"></textarea>
							
							<input type="submit" class="submit" value="Post Comment" id="post">
						</div>
					</div>
				</div>
			
	
			
			<script type="text/javascript">
			
			$(document).ready(function() {			
				$('.comment #counter<?=$this->site_area_ID;?>').html($('#c<?=$this->site_area_ID;?> ul li').size());

			});
	
	
			</script>
	
		<?php
		}
		else
			return null;
	}
	
}
?>