function collectMainCategories(className) {
var increment=0;
var collection = [];
var liChild=null;
var needleclass = new RegExp('\\b'+className+'\\b');
var elements = document.getElementsByTagName('li');
for (var i = 0; i < elements.length; i++) {
var testclass = elements[i].className;
if (needleclass.test(testclass)) { 
collection.push(elements[i]);
liChild=elements[i].firstChild;
liChild.id="main"+increment;
liChild.style.cursor="pointer";
increment++;
liChild.onclick=function() { return hideOnOff(this.id); };
if (elements[i].getAttribute('child')!="active") {
liChild.style.background="url(/wp-content/themes/grifon/images/plus.png) no-repeat left top";
}
else
{
liChild.style.background="url(/wp-content/themes/grifon/images/minus.png) no-repeat left top";
}
}
}
return collection;
}

function hideSubCategories(collection) {
var sub=null;
var first2collapse=new Array();
for(var i=0; i<collection.length; i++) {
sub=collection[i].getElementsByTagName('ul');
first2collapse[i]=sub[0];
if (collection[i].getAttribute('child')!="active") sub[0].style.display="none";
}
return first2collapse;
}

function hideOnOff(id){
var getid=id.replace("main", "");
if (subCategories[getid].style.display=="none") {
subCategories[getid].style.display="";
collection[getid].firstChild.style.backgroundImage="url(/wp-content/themes/grifon/images/minus.png)";
}
else {
subCategories[getid].style.display="none";
collection[getid].firstChild.style.backgroundImage="url(/wp-content/themes/grifon/images/plus.png)";
}
}

window.onload = function() {
collection=collectMainCategories("MainCategory");
subCategories=hideSubCategories(collection);
}