﻿if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest()
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
xhttp.open("GET","../portfolio.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;

var x=xmlDoc.getElementsByTagName("project");
var xthumb=xmlDoc.getElementsByTagName("thumb");


var xprofile=xmlDoc.getElementsByTagName("myprofile");
var xfooter=xmlDoc.getElementsByTagName("footertext");

var myTestClass = Class.create({
initialize:function()
{makeDiv();}
// Is called when the page has finished loading by the Event.observe code below
});
// Global variable for the instance of the class
var myTest;
// Creating an instance of the class if the page has finished loading
Event.observe(window, 'load', function() {
myTest = new myTestClass();
});



function makeDiv(){

var expcnt=0;
var cmccnt=0;
var cntnum=0;




for(t=0; t<x.length; t++){
	if(x[t].getAttribute("tag")=="experiment"){
	expcnt++;
	} else{
	cmccnt++;
	}
}



var expid=0;
var cmcid=0;
var uid=0;

var type;
for(i=0; i<x.length; i++){

if(x[i].getAttribute("tag")=="experiment"){
type = 0;
cntnum = expcnt;
expid++;
uid = expid;
} else {
type = 1;
cntnum = cmccnt;
cmcid++;
uid = cmcid;
}

var a = new Element('a', { 'class': 'foo', href: '../projects/'+xthumb[i].childNodes[0].nodeValue+'.html?pid='+i+'='+type+'='+cntnum+'='+uid}).update(x[i].childNodes[0].nodeValue);


var my_div = new Element('div', { 'class': 'generate' });

var alink = '../projects/'+xthumb[i].childNodes[0].nodeValue+'.html?pid='+i+'='+type+'='+cntnum+'='+uid;


var img_div = new Element('div', { 'class': 'genImg', onclick :"location.href='"+alink+"'"});
img_div.setStyle({
backgroundImage:"url(../pbimages/thumbs2/"+xthumb[i].childNodes[0].nodeValue+".jpg)"
, cursor:"pointer"});

if(x[i].getAttribute("tag")=="experiment"){
document.getElementById("exp").appendChild(a);
} else {
document.getElementById("cmc").appendChild(a);
}
my_div.appendChild(img_div);
a.wrap(my_div);

}


document.getElementById("aboutme").innerHTML = xprofile[0].childNodes[0].nodeValue;

document.getElementById("footer").innerHTML = xfooter[0].childNodes[0].nodeValue;


}




