/*
	Live Post using Sjax.
	http://www.lab4games.net/zz85/blog
*/

var cache = Array(); 

// this js function is to expand story and display comments
function livepost_expand(id){
	
	var mydata = 'p=' + id + '&lp=1';
	var ele = 'post-'+ id;
	var livepost_ajax = new sack(livepost_link+'?'+mydata); //alert(link);
	
	// Save current content of div
	cache[id] =  document.getElementById(ele).innerHTML;
	
	// Get new content
	livepost_ajax.method = "GET";
	livepost_ajax.runAJAX('');
	
	// Display loading messages
	//var status = document.getElementById(ele); //
	var status = document.getElementById('livepost_link'+id);
	status.innerHTML = '[&]Opening Post.!';
	livepost_ajax.onLoaded = function (){ status.innerHTML = '[-]Loaded!' ; };
	livepost_ajax.onLoading = function (){ status.innerHTML = '[|]Loading!' ; };
	livepost_ajax.onInteractive = function() { status.innerHTML = '[*]Geting Data!' ; };
	livepost_ajax.onCompletion = function (){ 
		status.innerHTML = '[%]Completed!'; 
		content = livepost_ajax.response;
		
		start = content.indexOf('livepost{{{');
		end = content.indexOf('}}}livepost');
		content = content.substring(start+11,end);
		
		document.getElementById(ele).id = ele + 'b';
		
		// Add link to contract posts
		document.getElementById(ele+ 'b').innerHTML
		= '<div id="LivePost" style="border: solid 1px #0909AF; background: rgb(209,231,249); -moz-border-radius: 20px;   padding: 5px 5px 5px 5px;margin: 2px 2px 2px 2px; ">' + 
		'<a href="javascript:livepost_contract('+id+');" id="livepost_link'+id+'" title="Minimise Live Post: WYSIWYG Editors">[-] Close Live Post</a>' + content
		+'</div>'; //** 
		
		// jump to anchor
		location.hash= "#"+ele;
	};
	

}



// called to revert to summarised story or to hide comments
function livepost_contract(id) {
	// can chose to cache data
	// replace save sumarised data
	
	var ele = 'post-'+ id+ 'b';
	document.getElementById(ele).innerHTML = cache[id] ;
	document.getElementById(ele).id = 'post-'+ id; 
}

