/**
 * Media Browser  v. 1.0
 * @author info@reddesigngroup.com
 */

window.onload=loadXML;

function loadXML() {

	if (cacheXML) {
	xmlPath = xmlPath;
	} else {
	xmlPath = xmlPath;
	}
	// code for IE
	if (window.ActiveXObject) {
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(xmlPath);
	parseMedia();
	}
	
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		useXMLHttpRequest(); 
    } else {
		alert(errorMsg);
	}
}

function useXMLHttpRequest() {
xmlhttp=null;
     if (window.XMLHttpRequest) {
     xmlhttp=new XMLHttpRequest();
     }
     
     if (xmlhttp!=null) {
     	xmlhttp.onreadystatechange= state_Change;
     	xmlhttp.open("GET",xmlPath ,true);
     	xmlhttp.send(null);
     } else {
     	alert(errorMsg);
     }
}

function state_Change()  {
     if (xmlhttp.readyState==4)  {
          if (xmlhttp.status==200)  {
          	xmlDoc=document.implementation.createDocument("","",null);          
          	xmlDoc=xmlhttp.responseXML;
          	parseMedia();
          }  else  {
          	alert("Problem retrieving XML data:" + xmlhttp.statusText)
          }
     }
}

var media;

function parseMedia() {
	
	// XML source
    var xmlSrc = xmlDoc;
	
	// Object for our media
    var media = new Object();
    
    // first our phone list, an array of objects
    media.photo = new Array();
    
     var mediaCollection = xmlSrc.getElementsByTagName("image");
     var imgSet = null;  
	   
	 	for (h=0; h<mediaCollection.length; h++) {
        	var newImage = new Object;
       		newImage.name = mediaCollection[h].getAttribute("name");
        	newImage.src = mediaCollection[h].getAttribute("src");
			newImage.thumbSrc = mediaCollection[h].getAttribute("thumbSrc");
			newImage.category = new Array();
			newImage.category = mediaCollection[h].getAttribute("category").split(',');
        	
			
			
			if (mediaCollection[h].getElementsByTagName("description")[0].hasChildNodes()) {
				var description = mediaCollection[h].getElementsByTagName("description")[0].childNodes[0].nodeValue;
			} else {
				var description = "";
			}
		newImage.description = description;
       	
		media.photo.push(newImage);
        }
	
	buildThumbs(media.photo);
}