Object.prototype.nextObject = function() {
	var n = this;
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}
 
Object.prototype.previousObject = function() {
	var p = this;
	do p = p.previousSibling;
	while (p && p.nodeType != 1);
	return p;
}

var COLLAPSABLE_PARENT_NAME = "newspost"; 
var COLLAPSABLE_PARENT_TYPE = "div"; 
var COLLAPSABLE_CHILD_TYPE = "p"; 

var COLLAPSABLE_EXPAND = "more..."; 
var COLLAPSABLE_SHRINK = "...hide"; 

init = function() { 
    if(document.getElementById && document.createTextNode) { 
		// get all the divs in the page
        var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE); 
		// loop through all the divs in the page
        for(i=0;i<entries.length;i++) {
			// if the div class name is the same as the COLLAPSABLE_PARENT_NAME
            if(entries[i].className==COLLAPSABLE_PARENT_NAME) {	
				// then assign a collapse button to it
                assignCollapse(entries[i]); 
			}
		}
    } 
} 

assignCollapse = function (div) { 
    /*var button = document.createElement('a'); 
    button.style.cursor='pointer'; 
    button.setAttribute('more', COLLAPSABLE_EXPAND); 
    button.setAttribute('hide', COLLAPSABLE_SHRINK); 
    button.setAttribute('state', -1); 
    button.innerHTML='more...'; 
	// insert our button before the first paragraph element
    div.insertBefore(button, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]); 
    button.onclick = function(){ 
        var state = -(1*this.getAttribute('state')); 
        this.setAttribute('state', state); 
        this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block'; 
        this.innerHTML = this.getAttribute(state==1?' more...':'hide'); 
    };                    
    button.onclick(); */
	
	// create the "show" link
	var a = document.createElement("a");
	a.style.cursor = "pointer";
	a.appendChild(document.createTextNode(COLLAPSABLE_EXPAND));
	a.id = "show_link";
	a.onclick = function(event) {
		showHide(div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0], this);
	}
	// create the "hide" link
	var b = document.createElement("a");
	b.style.cursor = "pointer";
	b.style.display = "none";
	b.id = "shrink_link";
	b.appendChild(document.createTextNode(COLLAPSABLE_SHRINK));
	b.onclick = function(event) {
		showHide(div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0], this);
	}
	// insert the links
	div.insertBefore(a, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]);
	div.appendChild(b);
	var paragraph = div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0];
	paragraph.style.display = "none";
	
} 

function showHide(element, clicked) {
	if(element.style.display == "none") {
		clicked.style.display = "none";
		element.style.display = "";	
		document.getElementById("shrink_link").style.display = "";
	} else {
		clicked.style.display = "";
		element.style.display = "none";	
		document.getElementById("shrink_link").style.display = "none";
		document.getElementById("show_link").style.display = "";
	}
}

window.onload = init;
