
$.ajax({
    url: 'attributes.xml?'+Math.random(),
    type: 'GET',
    dataType: 'xml',
    timeout: 3000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(xml){
        $(xml).find('Category').each(function(){
			var thisid = $(this).children('CategoryName').text();
			var cat =  document.getElementById(thisid);
			var categ = $("#projects dt");
			categ.each(function(){
				categ.click(function(){
					$("dt").removeClass("active");
					$("dd").removeClass("active");
					$("dd a.selected").removeClass("selected");
					$(this).addClass("active");
					$(this).next("dd").addClass("active");
					var ss = $("dd.active a:first");
					$(ss).addClass("selected");
				});
			});
			$(this).find('Project').each(function(){
				var item_text = $(this).attr("title");
				var thislink = $('<a href="#"><span>' + item_text + '</span></a>');
				var images = $(this).find('Image');
				var profile = $(this).find('Profile');
				var b = $(this);
				var desc = $(this).find('Description');
				var tech = $(this).find('Tech');
				if(tech.text()==""){
					$("#tech").hide();
				}
				else{
					$("#tech").show();
				}
				var elink = $(this).find('Link');
				thislink.click(function(){ 
					var imago;
					$(".selected").removeClass("selected");
					thislink.addClass("selected");
					imago = b.find('Image:first');
					$("#thumbs").empty();
					$("#proj_img").attr({
						src: imago.attr("path"),
						alt: imago.attr("alt")
					});
					images.each(function(i, n){
						var serial = i+1;
						var v = $(this);
						$('#project p a').text(item_text);
						if(elink.text()!="javascript:void(0)"){
							$("#link").show();
							$("#link").removeClass("design");
							$("#link").attr({
								href: elink.text()		 
							})
						}
						else {
							$("#link").addClass("design");
						};
						if(tech.text()==""){
							$("#tech").hide();
						}
						else{
							$("#tech").show();
						};
						$("#profile").text(profile.text());
						$("#info").text(desc.text());
						$("#tech").text(tech.text());
						var thisthumb = $('<a href="javascript:void(0);">' + serial + '</a>');
						thisthumb.click(function(){
							$("#thumbs a.active").removeClass("active");
							thisthumb.addClass("active");
							var source = v.attr("path");
							var alttext = v.attr("alt");
							$("#load").fadeIn(700);
							setTimeout(function() {
								$("#proj_img").attr({ 
								  src: source,
								  alt: alttext
								})}, 600);

							$("#load").fadeOut(1400);					
						});
						thisthumb.appendTo("#thumbs");
						$("#thumbs a:first").addClass("active");
					});
				});
				thislink.appendTo(cat);
			});
   		 });
    }
});
