// JavaScript Document

var newComment = new Array();
newComment['content_title']= '';
newComment['username']= '';
newComment['comment']= '';
newComment['link']= '';
newComment['id']= '';

var lastComment = new Array();
lastComment['id']= '';

var slidingDiv = '';

function slideComment() {
		
	var stopPosition = 0;

	if (parseInt(slidingDiv.style.top) < stopPosition ){
		slidingDiv.style.top = parseInt(slidingDiv.style.top) + 1 + "px";
		setTimeout("slideComment()", 1);
	} else {
		divs = slidingDiv.getElementsByTagName('div');
		tmp = '';
		for (var i=0; i<3; i++){
			tmp += '<div class="right_box_comment">' + divs[i].innerHTML + '</div>';
		}
		//slidingDiv.innerHTML = tmp;
	}
}


function refreshComments() {
	
	callAjax("mainComments", "Get", this, false, false, "parseJson", "json");
	
}


function parseJson(data){
    slidingDiv = document.getElementById('comment_container');

	if(data){
		var obj = jQuery.parseJSON(data);
		
		if(lastComment['id'] != obj[0].id) {
		
			newComment['id']= obj[0].id;
			newComment['content_title']= obj[0].content_title;
			newComment['username']= obj[0].username;
			newComment['comment']= obj[0].comment;
			newComment['link']= obj[0].link;


			commentDiv ='<div class="right_box_comment"><div style="font-weight:bold; color:#b8b7b7;">'+newComment['content_title']+'</div><i>'+newComment['username']+'</i>: '+newComment['comment']+' <a href="'+newComment['link']+'"><img src="/images/dotdotdot.png" alt="..." title="..."/></a></div>';

			slidingDiv.innerHTML = commentDiv + slidingDiv.innerHTML;

			slidingDiv.style.top =  "-89px";

			slideComment();

			lastComment['id'] = newComment['id'];
		}
		
	}
	
	setTimeout("refreshComments()", 60000);
}
