function builder() {

}

builder.prototype.load = function(file) {
	$("body").load(file);
}

builder.prototype.build = function(file) {
	// slight pause before loading
	setTimeout(function(){
		// load main file
		$.ajax({
			type: "GET",
			url: file,
			success: function(xml){
				// where to append to
				var main = $("#subbackground");
		
				// get elements		
				$(xml).find("element").each(function(){
					var element = $(this);
					var elementType = element.attr("type");
		
					// block
					if (elementType === "block") {
						// append block to main
						main.append(
							"<div id='" + element.attr("id") + "' "
								+ "class='" + element.attr("class") + "'></div>");
		
						// where to append to
						var block = $("#" + element.attr("id"));
		
						// get inner elements
						$(this).find("innerelement").each(function(){
							var innerElement = $(this);
							var innerElementType = innerElement.attr("type");
		
							// image
							if (innerElementType === "img") {
								var image = 
									"<img "
									+ "class='" + innerElement.attr("class") + "' "
									+ "id='" + innerElement.attr("id") + "' "
									+ "src='" + innerElement.attr("src") + "'>";
								// make into link
								if (innerElement.attr("link") != undefined && innerElement.attr("link") != "") {
									image = "<a href='" + innerElement.attr("link") + "'>" + image + "</a>";
								}
								block.append(image);
							}
							// text
							else if (innerElementType === "text") {
								var text =
									"<div "
									+ "class='" + innerElement.attr("class") + "' "
									+ "id='" + innerElement.attr("id") + "'>"
									+ innerElement.attr("value")
									+ "</div>";
								// make into link
								if (innerElement.attr("link") != undefined && innerElement.attr("link") != "") {
									text = "<a class='" + innerElement.attr("class") + "' "
										+ "href='" + innerElement.attr("link") + "'>" + text + "</a>";
								}
								block.append(text);
							}
							// video
							else if (innerElementType ==="video") {
								var video =
								"<object width='" + innerElement.attr("width") + "' "
								+ "height='" + innerElement.attr("height") + "'>"
								+ "<param name='movie' " + "value='" + innerElement.attr("src") + "&hl=en&fs=1" + "'></param>"
								+ "<param name='allowFullScreen' value='true'></param>"
								+ "<param name='allowscriptaccess' value='always'></param>"
								+ "<embed src=" + innerElement.attr("src") + "&hl=en&fs=1" + " "
								+ "type='application/x-shockwave-flash' "
								+ "allowscriptaccess='always' "
								+ "allowfullscreen='true' "
								+ "width='" + innerElement.attr("width") + "' "
								+ "height='" + innerElement.attr("height") + "'>"
								+ "</embed></object>";

								block.append(video);
							}
							// line break
							else if (innerElementType === "linebreak") {
								block.append("<br>");
							}
						});
					}
					// image
					else if (elementType === "img") {
						var image = 
							"<img "
							+ "class='" + element.attr("class") + "' "
							+ "id='" + element.attr("id") + "' "
							+ "src='" + element.attr("src") + "'>";
						// make into link
						if (element.attr("link") != undefined && element.attr("link") != "") {
							image = "<a href='" + element.attr("link") + "'>" + image + "</a>";
						}
						main.append(image);
					}
					// text
					else if (elementType === "text") {
						var text =
							"<div "
							+ "class='" + element.attr("class") + "' "
							+ "id='" + element.attr("id") + "'>"
							+ element.attr("value")
							+ "</div>";
						// make into link
						if (element.attr("link") != undefined && element.attr("link") != "") {
							text = "<a href='" + element.attr("link") + "'>" + text + "</a>";
						}
						main.append(text);
					}
					// video
					else if (elementType === "video") {
						var video =
						"<object width='" + element.attr("width") + "' "
						+ "height='" + element.attr("height") + "'>"
						+ "<param name='movie' " + "value='" + element.attr("src") + "&hl=en&fs=1" + "'></param>"
						+ "<param name='allowFullScreen' value='true'></param>"
						+ "<param name='allowscriptaccess' value='always'></param>"
						+ "<embed src='" + element.attr("src") + "&hl=en&fs=1" + "' "
						+ "type='application/x-shockwave-flash' "
						+ "allowscriptaccess='always' "
						+ "allowfullscreen='true' "
						+ "width='" + element.attr("width") + "' "
						+ "height='" + element.attr("height") + "'>"
						+ "</embed></object>";

						main.append(video);
					}
					// line break
					else if (elementType === "linebreak") {
						block.append("<br>");
					}
					// add grass to menu
					else if (elementType === "grass") {
						$("#menu").append("<img src='" + element.attr("src") + "'>");
					}
					else {
						alert("Unrecognized element type.");
					}	
				});	
			}
		});
	}, 70);
}
