var school = {
    count : 0,
    fileCount : 0,

    init : function() {
        school.count = document.getElementById('district_schools').childNodes.length;
        school.atLeastOneIng();
    },
    atLeastOneIng : function() {
        if(document.getElementById('district_schools').getElementsByTagName('div').length) return;
		school.addIng();
    },
    addIng : function(el) {
        if(el) while(el.className != 'parent-sel') el = el.parentNode;
        var div = school.searchProto();
        el ? el.parentNode.insertBefore(div, el.nextSibling) :
            document.getElementById('district_schools').appendChild(div);
    },
    rmIng : function(el) {
        while(el.className != 'parent-sel') el = el.parentNode;
        el.parentNode.removeChild(el); 
        setTimeout(school.atLeastOneIng, 500);
    },
    searchProto : function() {
        var proto = document.getElementById('schools').firstChild.cloneNode(true);
        var count = school.count++;
        var fileCount = school.fileCount++;
        proto.innerHTML = proto.innerHTML.replace(/\%n/g, count);
        proto.innerHTML = proto.innerHTML.replace(/\%f/g, fileCount);
        return proto;
    },
	

	// define a custom method on the string class to trim leading and training spaces
	trim : function() { 
		return this.replace(/^\s+|\s+$/g, '');
	}


};
eTool.add(window, 'load', school.init, false);