
function PostArchiveItem(el) {
	this.element = el;
	this.element.style.display = 'none';
	if(this.element) {
		for(var i = 0;i < this.element.childNodes.length;i++) {
			var child = this.element.childNodes[i];
			if(child.nodeName.toLowerCase() == 'li') {
				new PostsArchive(child);
			} 
		}
	}
	this.toggleVisible = function() {
		if(this.element.style.display == 'none') {
			this.element.slideDown({duration: 0.5});
			return true;
		} else {
			this.element.blindUp({duration: 0.5});
			return false;
		}
	}
}

function PostArchiveLink(el, parentArchive) {
	var link = document.createElement('a');
	link.onclick = function() {
		var visible = parentArchive.toggleChildsVisible();
		if(visible) {
			link.innerHTML = '<img src="/lib/plugins/posts_archive/png/minus.png" alt="-" />&nbsp;'+el.nodeValue;
		} else {
			link.innerHTML = '<img src="/lib/plugins/posts_archive/png/plus.png" alt="+" />&nbsp;'+el.nodeValue;
		}
	}
	link.innerHTML = '<img src="/lib/plugins/posts_archive/png/plus.png" alt="+ " />&nbsp;'+el.nodeValue;
	var parentNode = el.parentNode;
	parentNode.insertBefore(link, el);
	parentNode.removeChild(el);
}

function PostsArchive(el) {
	this.element = el;
	if(this.element.nodeName.toLowerCase() == 'li') {
		this.element.style.listStyleType = 'none';
		// this.element.style.listStyleImage = 'url(/lib/plugins/posts_archive/png/plus.png)';
	}
	this.childs = new Array;
	if(this.element) {
		for(var i = 0;i < this.element.childNodes.length;i++) {
			var child = this.element.childNodes[i];
			if(child.nodeName.toLowerCase() == 'ul') {
				this.childs[this.childs.length] = new PostArchiveItem(child);
			}
			if(child.nodeName.toLowerCase() == '#text') {
				PostArchiveLink(child, this);
			}
		}
	}
	var self = this;
	this.toggleChildsVisible = function() {
		var visible = false;
		for(var i = 0;i < self.childs.length;i++) {
			visible = self.childs[i].toggleVisible();
		}
		return visible;
	}
}

