function callXML(x) {
$.get('projectsxml.php', {q:x, project: 'yes'}, function(data, textStatus) {

	// Set variables
	  var txt = "<table>";
	  txt += "<td id=\"blackbox1\"><img src=\"graphics/trans1px.gif\" width=\"270px\"></td>";
	  var txt2 = "";
	  var all = $('#proj-images');
	  var list = $('#proj-list-text');
	  var listbg = $('#pboxbg');
	  var listhold = $('#pboxHolder');

	// Get the value for each tag you want in the XML file		
		$(data).find("project").each( function(){
				//Basic Info
				id = $(this).attr("id");
				image = $(this).find("image").text();
				link = $(this).find("main_link").text();
				title = $(this).find("title").text();
				// Description text
				category = $(this).find("category").attr("main");
				description = $(this).find("display_desc").text();
				year = $(this).find("year").text();
				runtime_m = $(this).find("runtime_m").text();
				runtime_s = $(this).find("runtime_s").text();
				format = $(this).find("format").text();
				color = $(this).find("color").text();
				sound = $(this).find("sound").text();
				soon = $(this).find("dates[upcoming='yes']").text();
				// video info
				playfile = $(this).find("playfile").text();
				playtext = $(this).find("playtext").text();		
				vimeo = $(this).find("vimeo").text();
				vheight = $(this).find("vimeo").attr("height");
				valbum =  $(this).find("vimeo").attr("album");
				u2b = $(this).find("youtube").text();
				uheight = $(this).find("youtube").attr("height");
				file = $(this).find("file").text();
			
			  // The project div
			  txt += "<td id=\"" + id + "\"";
			  txt += " class=\"" + playfile + " ";
			  if ( category == "other") {
				txt +=  "hidden ";
			  }
			  else {
				txt +=  "";
			  };
			  txt += category;
			  if(soon != "") {
			  	txt += " soon";
			  };
			  txt +="\"";
			  txt += ">";
			  txt += "<div class=\"apurple\">";
			  // the project image 
			  txt += "<a class=\"proj-listing\"";
			  txt += " name=\"" +  id + "\""; 
			  txt += ">";
			  txt += "<img src=\"http://www.balldeep.tv/new_graph/" + image + "\"";
			  txt += " alt=\"" + title + "\""; 
			  txt += " title=\"" + title + "\""; 
			  txt += ">";
			  txt += "</a>";
			  txt += "</div>";
			  
			  // The info
    			if (color == "yes") {
					color = "Color";
				}
				else {
					color = "B&W";
				};
				if ((runtime_m) != undefined && (runtime_m) !="" && (runtime_m) !="0") {
					runtime_m = runtime_m + "m";
				}
				else {
					runtime_m = "";
				};
				if ((runtime_s) != undefined && (runtime_s) !="" && (runtime_s) !="0") {
					runtime_s = runtime_s + "s";
				}
				else {
					runtime_s = "";
				};
				var info = "";
				year = year;
				format = format;
				color = color;
				runtime = runtime_m + runtime_s;
				if(year){
					info +=year + ". "
				};
				if(format){
					info +=format + ". "
				};
				if(runtime!=""){
					info +=runtime + ". "
				};
			  txt +="<div id=\"" + id + "-info\" class=\"p-info\">";
			  	txt +="<div class=\"blackbg small white awhiteb\">";
			  	txt +="<span class=\"bold\">";
			 		 txt += title + "<br/>";
			 	 txt +="</span>";
			  	txt += info;
			  	txt +="<p>";
			  		txt += description;
			  	txt +="</p>";
			  	txt +="<p>";
			  	txt +="<span class=\"fl_left bold\">";
			  if(soon == "") {
			  }
			  else {
			  	txt +="<a id=\"screen-soon\" href=\"#" + id + "\">Screening Soon</a>"; 
			  }; 
			  	txt +="</span>";
			  if (playfile == "playable") {
			  	txt +="<span id=\"" + id + "\" class=\"fl_right bold play\">" + "<a class=\"awhiteb\" href=\"?video=play\">";
			  	if (playtext) {
			  	txt += playtext;
			  	}
			  	else {
			  	txt += "Play Video";
			  	};
			  	txt += "</a>" + "</span>";
			  };
			  	txt +="</p>";
			  	txt +="<div class=\"hidden\" id=\"" + id + "-java\" playfile=\"" + playfile + "\" file=\"" + file + "\" image=\"" + image + "\" vid=\"" + id + "\" vimeo=\"" + vimeo + "\" album=\"" + valbum + "\" u2b=\"" + u2b + "\" vheight=\"" + vheight + "\" uheight=\"" + uheight + "\">";
			  	txt +="</div>";
			  	txt +="</div>";
			  txt +="</div>";
			  
			  // Close the div
			  txt +="</td>";
			  // The project list
				txt2 += "<li";
				txt2 += " class=\"p-link " + playfile + " ";
				if ( category == "other") {
					txt2 +=  "hidden ";
				}
				else {
					txt2 +=  "";
				};
					txt2 += category;
				if(soon != "") {
					txt2 += " soon";
				};
				txt2 +="\"";
				txt2 += ">";
				txt2 += "<a class=\"awhiteb\" href=\"#";
				txt2 += id;
				txt2 += "\"";
				txt2 += ">";
				txt2 += title;
				txt2 +="<\/a>";
				txt2 += "<\/li>";
		});
  	  txt += "<td id=\"blackbox\"><img src=\"graphics/trans1px.gif\" width=\"700px\"></td>";
	  txt +="</table>"
 	  txt2 +="<li id=\"tallblack\"><img src=\"graphics/trans1px.gif\" width=\"240px\" height=\"60\"></li>";
	  all.html(txt);
	  $(".p-info").hide();
	  list.html(txt2);
  	  setFilters();  	 
	  /*first = $("#proj-images td:eq(1)").attr("id");*/
	  if( $('#pbox').is(':hidden') ) {
    	$("#blackbox1").hide();
	  }
	  else {
		  $("#blackbox1 img").width($("#pbox").width() + 15);
	  };
	  if(getHash()) {
			thehash = getHash();
		   	launchProj(thehash, 'yes');
		   	hashid = "#" + thehash
		   /* Handle hidden OTHERS */
		   if($(hashid).is(':hidden')) {
		   		$("#other-x").html("X");
		   		setFilters();
		   		launchProj(thehash);
		   	};
		   	/*if(first==thehash) {
		   		$("#blackbox1").show();
		   		$.scrollTo({top:0, left:300}, {axis:'x'});
		   	};*/
	  }
	  else {
	  	$.scrollTo({top:0, left:0}, {axis:'x'});
	  }; 
	  /* Open External Links in new Tab */
	  $('a[href^="http://"]').live('click',function(){ this.target='_blank'; });
	  /* End code */
 	  $(".proj-listing").click(function (){
	    thisbox = "#" + $(this).attr("name") + "-info";
	    $(".p-info:not('" + thisbox + "')").slideUp("normal");
	  	$(thisbox).slideToggle( "normal" );
	  });
	 $(".play").click(function(){
		 id = $(this).attr('id');
		 launchVid(id);
	 });
});
};

		function launchVid(id) {			
			var playfile = $("#" + id + "-java").attr("playfile");
			if (playfile == "playable") {
				playfile = "yes";
			}
			else {
				playfile = "no";
			};
			var file = $("#" + id + "-java").attr("file");
			var image = $("#" + id + "-java").attr("image");
			var vid = $("#" + id + "-java").attr("vid");
			var vimeo = $("#" + id + "-java").attr("vimeo");
			var valbum = $("#" + id + "-java").attr("album");
			var u2b = $("#" + id + "-java").attr("u2b");
			var vheight = $("#" + id + "-java").attr("vheight");
			var uheight = $("#" + id + "-java").attr("uheight");
			
			//ColorBox
			$(".play").colorbox({transition:"none", speed:"2000", initialWidth:"632px", initialHeight: "536px", width:"800px", height:"600px", href:"video-player.html", overlayClose: "true", onComplete:function(){
				openVid(playfile,file,image,vid,vimeo,valbum,u2b,vheight,uheight)
				}})
		};
		
		function setFilters() {
				var filmx = $("#film-x").html();
				var videox = $("#video-x").html();
				var otherx = $("#other-x").html();
				$(".p-info").slideUp();
				if (filmx == "X") {
					showProj(".film");
				}
				else {
					$(".film").fadeOut('normal');
				};
				if (videox == "X") {
					showProj(".video");
				}
				else {
					$(".video").fadeOut('normal');
				};
				if (otherx == "X") {
					showProj(".other");
				}
				else {
					$(".other").fadeOut('normal');
				};
				/*Handle too few */
				var numbox = ($("#proj-images td:visible").length);
				if (numbox <= 5) {
					$("#tallblack").show();
					window.location.hash = "";
					/*$.scrollTo({top:0, left:375}, {axis:'x'});*/
				}
				else {
					$("#tallblack").hide();
				};
				/* Handle too short window 
				fixShort();*/
		};

		 function setProjOrder(r, l) {
		 	var chronx = $("#chron-x").html();
		 	var alphax = $("#alpha-x").html();
			if (chronx == r) {
				callXML('date ASC');
			}
			else if (chronx == l) {
				callXML('date DESC');
			};
			if (alphax == r) {
				callXML('title ASC');
			}
			else if (alphax == l) {
				callXML('title DESC');
			};
		 };
		 
		 
		 function showProj(type) {
		 	var playablex = $("#playable-x").html();
		 	var screeningx = $("#screening-x").html();
		 	$(type).fadeIn('normal');
		 	//Build the filter
		 	var f = "";
		 	if (playablex == "X") {
			 	$(type).filter('.noplay').hide();
		 	}
		 	else {
			 	$(type).filter('.playable').show();
		 	};
		 	if (screeningx == "X") {
			 	$(type + ':not(.soon)').hide();
		 	}
		 	else {
			 	$(type + ':not(.soon)').show();
			 	if (playablex == "X") {
			 		$(type).filter('.noplay').hide();
		 		};
		 	};		 	
		 };
		 
		 function getHash(excludeQuestionMark) {
				if (typeof excludeQuestionMark == 'undefined') var excludeQuestionMark = true;
				var hash = window.location.hash;
				var stop = hash.indexOf('?');
				// if there was no question mark in the hash, or if excludeQuestionMark is set to false
				if (stop == -1 || !excludeQuestionMark)
				var returner = hash.substring(1); // remove #
				else
				var returner = hash.substring(1,stop); // remove # and exlude everything after '?'
				return returner;
		}
			
		function getQuestion() {
				var hash = window.location.hash;
				var stop = hash.split('?');
				if (stop[1]) {
					return stop[1];
				};
		};
			
		function launchProj(proj, video) {
				 $(".p-info").hide();
				 $("#" + proj + "-info").slideDown("normal");
				 if (video!="yes") {
				 }
				 else {
				 	launchVid(proj);
				 };
		};
		
		function fixShort() {
				var pheight = $("#pbox").height();
				var wheight = $(window).height();
				if (pheight >= wheight) {					
					$("#pboxHolder, #nav-left").addClass("absolute");
					$("#pboxHolder, #nav-left").removeClass("fixed");
					$.scrollTo(0,0, {axis:'xy'});
					$("#pboxLine").hide();
				}
				else {
					$("#pboxHolder, #nav-left").removeClass("absolute");
					$("#pboxHolder, #nav-left").addClass("fixed");
					$("#pboxLine").show();
				};
		};
