//Simple functions to read categories form an XML file
var xmlFeatureProductsDoc;

function loadFeatureProductsXML(){

	if (window.ActiveXObject){
		
	  	xmlFeatureProductsDoc=new ActiveXObject("Microsoft.XMLDOM")
		xmlFeatureProductsDoc.async="false"
		xmlFeatureProductsDoc.load("lib/xml/featuredproducts.xml")
	  	readFeatureProductsXML();
	}
	else if (document.implementation && document.implementation.createDocument) {
		  
	  	  xmlFeatureProductsDoc= document.implementation.createDocument("","",null);
		  xmlFeatureProductsDoc.load("lib/xml/featuredproducts.xml");
		  xmlFeatureProductsDoc.onload=readFeatureProductsXML;
	}
	else{
		
		document.getElementById('categories').innerHTML = '<li>YOUR BROWSER DOESN\'T SUPPORT XML DOM</li>'
	}
 
}

function readFeatureProductsXML(){
	

	var html =''; //Variable to house the innerHTML for the categories
	
	
	var featureditems = xmlFeatureProductsDoc.getElementsByTagName("featuredproducts")[0];
	var featured = xmlFeatureProductsDoc.getElementsByTagName("featuredproducts")[0].childNodes.length;

	
	
	var hidden_elm = document.getElementById('isfullfeaturedisplay');
	//alert(hidden_elm.value)
	var display_elm = document.getElementById('displaycontent');
	
	//Array to contain all html values that will be randomized later on
	var arrHTML = new Array(featured);
	var arrHTMLtoDisplay 

	html += '<ul id="feature">';
	for(i=0;i<featured;i++){
		
		var company = featureditems.getElementsByTagName("company")[i];
		var company_items = company.childNodes.length;

	 	arrHTML[i] = new Array(company_items);
		for(j=0;j<company_items;j++){
			
			arrHTML[i][j] = '<li><div class="productfeaturetitle">'+company.getElementsByTagName('item')[j].attributes.getNamedItem("name").value+'</div><div class="productfeaturepic"><img src="'+company.getElementsByTagName('imagelocation')[j].firstChild.nodeValue+'" alt="'+company.getElementsByTagName('imagelocation')[j].firstChild.nodeValue+'" title="'+company.getElementsByTagName('item')[j].attributes.getNamedItem("name").value+'"/></div><div class="productfeatureprice">'+company.getElementsByTagName('price')[j].firstChild.nodeValue+'</div></li>';
			
			
			//Lets randomize
			newcompanyindex = (Math.random() * 1);
			newcompanyindex =  parseInt(newcompanyindex, 10);
			newproductindex = (Math.random() * j);
			newproductindex = parseInt(newproductindex, 10);
			
			tempcontainerproduct = arrHTML[i][j];
			arrHTML[i][j] = arrHTML[newcompanyindex][newproductindex];
			arrHTML[newcompanyindex][newproductindex] = tempcontainerproduct;
			if(hidden_elm.value == 1){
				html += arrHTML[newcompanyindex][newproductindex];
			}
		}
		
		

	}
	if(hidden_elm.value == 0){
		
		for(j=0;j<9;j++){
			html += arrHTML[0][j];
			html += arrHTML[1][j];
	
		}
	}
	html += '</ul>';
	
	//alert(arrHTML[0].length);
	display_elm.innerHTML = html;
}



