// JavaScript Document

function assignMenuArrow() {
	var url = location.pathname;
	urlsplit = url.split("/")
	
	for(i = 0; i < urlsplit.length; ++i ) {
		if( i+1 != urlsplit.length ) var result = urlsplit[i];
	}
	//alert(result); 
	
	var list = document.getElementById("SideCategoryList");
	for(i = 0; i< list.childNodes.length; i++) {
		//alert(list.childNodes[i]);
	}
	//for( i = 0; i < list.length; i++ ) alert(list[i]);
}

function replacePagination() {
	
	//get current page the user is viewing and init other vars
	var pul = document.getElementById('CategoryPagingTop').getElementsByTagName('ul');
	var uls = pul[0].getElementsByTagName('li');
	var activepage, totalpages = 0;
	for(i = 0; i < uls.length; i++) {
		//alert(uls[i]);
		if( uls[i].getAttribute('class') == "ActivePage" ) { activepage = uls[i].innerHTML; }
		if( uls.length == (i+1) ) { totalpages = i }
	}
	
	//find top pagination container to insert new elements
	//assign classes to other divs, and clone divs to insert into bottom pagination box
	var el = document.getElementById('CategoryPagingTop').getElementsByTagName('div');
	var inserttop = "";
	var foundtop = false;
	var pclones = new Array();
	for(i = 0; i < el.length; i++) {
		if( el[i].nodeName.toString() == "DIV" && foundtop ) { 
			el[i].setAttribute('id', 'CategoryPaginationdiv' + i);
			el[i].removeAttribute('class');
			
		}
		if( el[i].getAttribute('class') == "CategoryPagination" ) { 
			inserttop = el[i];
			foundtop = true;
			continue;
		}
		pclones[i] = el[i].cloneNode(true);
	}
	
	//insert new elements on top
	var cur_bot = document.createElement('div');
	var cur_top = document.createElement('div');
	cur_top.setAttribute('id','pageposition-top');
	cur_bot.setAttribute('id','pageposition-bottom');
	cur_top.innerHTML = "Page " + activepage + " of " + totalpages;
	cur_bot.innerHTML = "Page " + activepage + " of " + totalpages;
  	inserttop.appendChild(cur_top);
	
	//insert new elements on bottom
	var insertbottom = document.getElementById('CategoryPagingBottom');
	//insertbottom.appendChild(pclones[0]);
	for( i = 1; i < pclones.length; i++ ) { insertbottom.appendChild(pclones[i]); }
	insertbottom.appendChild(cur_bot);
	
	//remove bottm pagination, add our custom one
	//var botpag = document.getElementById('CategoryPagingBottom');
	//botpag.appendChild(newdiv1);
	//botpag.removeChild(botpag.childNodes[0]);
	
	//alert(ieltop instanceof Array);
	//clone ieltop, change id's and insert at bottom of product list as well
	/*var cpdivclone = ieltop.cloneNode(true);
	if(cpdivclone.firstChild) { // check for children
   		var oChild = cpdivclone.firstChild;
		var c = 0;
   		while(oChild) { // run over them
     		if(oChild.nodeType==1) { // element
       			oChild.setAttribute('id', 'paginationbottom-' + c);
				c++;
     		}
     		oChild = oChild.nextSibling;
   		}
	}*/
	//alert(ielbottom.childNodes.length);
	//for( i = 0; i < ielbottom.childNodes.length; i++ ) {
		//ielbottom.removeChild(ielbottom[i]);
	//}
	//eilbottom.appendChild(cpdivclone);
	//alert(cpdivclone);
	//var newdiv2 = document.createElement('div');
	//newdiv2.setAttribute('id','pageposition-bottom');
	//newdiv2.innerHTML = "Page " + activepage + " of " + totalpages;
	//ielbottom.appendChild(newdiv2);
	//alert(iel.innerHTML);
	
	//set original pagination links to no display
	pul[0].style.display = "none";
}
