/**
 *  custom script for Neptune dept 10 page "shop online"
 * hack to make it look better
 */

// global vars for now - not really necessary except for testing
var navDept, containerTbl, featuredTbl;
var deptTbl = new Array();
 
 function fixTables(){
	var tmpTbl;	// garbage var 

	navDept = document.getElementById('navDept');	// get surrounding div
	containerTbl = cleanUp(navDept.childNodes)[0];		// get main table that holds all the content
	
	// get next level tables inside main table
	tmpTbl = cleanUp(containerTbl.childNodes)[0];
	tmpTbl = cleanUp(tmpTbl.childNodes);
	
	// grab 'featured products' table - first one
	featuredTbl = tmpTbl[0];
	
	// remove all 'spacer' tables and grab only department tables with content - loop goes through and grabs every other table
	var tmpCount = true;	
	for(var i = 2; i < tmpTbl.length; i++){
		if(tmpCount){
			deptTbl.push(tmpTbl[i]);
			tmpCount = false;
		}else{
			tmpCount = true;
		}
	}
	
	// now grab only 2 ahref tags - one that has the department image&link and the title of the department and add it to a new cell
	for(var i = 0; i < deptTbl.length; i++){
		var tmpLinks = new Array();
		tmpLinks = deptTbl[i].getElementsByTagName('a');
		var tmpTd = document.createElement('td');
		tmpTd.align = "center";
		tmpTd.appendChild(tmpLinks[0]);
		tmpTd.appendChild(document.createElement('br'));
		tmpTd.appendChild(tmpLinks[1]);
		deptTbl[i].innerHTML = "";
		deptTbl[i].appendChild(tmpTd);
	}

 }
 
 /* more for firefox - filter out all textnodes and crap - returns just elements */
function cleanUp(dirtyRows){
	var cleanRows = new Array();
	// grab only element nodes
	for(var i = 0; i<dirtyRows.length;i++){
		if(dirtyRows[i].nodeType == 1){
			cleanRows.push(dirtyRows[i]);
		}
	}
	return cleanRows;
}

