
function loadShow(name, baseroot, xmlThing, ww, hh){ 
	
	var mainImg;
	var landing;
	var instance;
	var base;
	var contentXml;
	var basePath;
	var xmlPath;
	var xmlData;
	var _width;
	var _height;
	var showDiv;
	var testtxt;
	var showLength;
	var showArray;
	var currentLoc;
	var loadInc;
	var counter;
	var curtain;
	var curtain2;
	var backToIntro;
	var prevBtn;
	var prevBtn2;
	var nextBtn;
	var nextBtn2;
	var beginTxt;
	var landingDek;
	var landingDek2;
	var loading;
	var loadingLine;
	var loaderTimer;
	var loaderNumber;
	var loaderInc;
	var colorArray;
	var bodyDek;
	var locked;
	var landingOn;
	var xPos;
	var yPos;
	var navtext;
	
	
	jQuery(document).ready(function(){
		
		jQuery.ajax({
			type: "GET",
			url: xmlThing,
			data: "",
			dataType: "xml",
			success: xmlLoaded,
			error: fail
  			});
		});

	function fail(result){
		/*
		if (result.status == 200 && result.statusText == "OK") {
			//this is here only because chrome breaks on this method only for no reason whatsoever.
			//chrome sees the request as failed, but everything happens fine...
			var t = jQuery(result.responseText);
			xmlLoaded(t);
			}
		else{
			var t = jQuery(result.responseText);
			xmlLoaded(t);
			}
		*/
		}

	function xmlLoaded(xml){
		
		instance = name;
		basePath = baseroot;
		xmlPath = xmlThing;
		xmlData = xml;
		_width = ww;
		_height = hh;
		currentLoc = 0;
		loadInc = 0;
		showArray = new Array();
		colorArray = new Array();
		locked = false;
		landingOn = true;
		
		base = document.getElementById(instance);
		base.style.background = "#ffffff";
		base.style.width = _width+"px";
		base.style.height = _height+"px";
		base.style.position = "relative";
		
		//test text
		/*
		testtxt = document.createElement("div");
		base.appendChild(testtxt);
		testtxt.style.position = "absolute";
		testtxt.id = ai("testtxt");
		testtxt.className = "thing";
		testtxt.style.top = 120+"px";
		testtxt.style.left = 666+"px";
		testtxt.style.width = 300+"px";
		testtxt.style.fontFamily = "Times New Roman";
		testtxt.style.textAlign = "left";
		testtxt.style.color = "#ff0000";
		testtxt.style.fontSize = 22+"px";
		*/
		//text text
		
		navtext = document.createElement("div");
		navtext.id = "navtext";
		navtext.style.position = "absolute";
		navtext.style.left = 2+"px";
		navtext.style.top = (_height-40)+"px";
		navtext.style.fontFamily = "arial,verdana";
		navtext.style.fontSize = 10+"px";
		base.appendChild(navtext);
		navtext.style.color = "#999999";
		//navtext.style.border = "solid";
		var navtexttext = document.createTextNode("browse by thumbnail");
		navtext.appendChild(navtexttext);
			
		loading = document.createElement("div");
		base.appendChild(loading);
		loading.style.position = "absolute";
		loading.id = ai("loading");

		var radius = 32;
		loaderNumber = 16;
		loaderInc = 0;
		var spacing = 2 * Math.PI / loaderNumber;
		var j = 0;
		colorArray = ["#ffa000","#efefef","#eeeeee","#eeeeee","#eeeeee","#eeeeee","#eeeeee","#eeeeee","#eeeeee","#dddddd","#cccccc","#aaaaaa","#999999","#777777","#555555","#333333"];
		
		for(i=0; i < 2 * Math.PI; i += spacing){
			var dot = document.createElement("div");
			dot.id = j+ai("dot");
			dot.style.position = "absolute";
			dot.style.fontSize = 36+"px";
			dot.style.color = "#eeeeee";
			
			dot.style.left = Math.cos(i)*radius+"px";
			dot.style.top = Math.sin(i)*radius+"px";
			dot.innerHTML = "°";
			document.getElementById(ai("loading")).appendChild(dot);
			j++;
			}
			
		loading.style.left = (((_width-loading.offsetWidth)/2)-13)+"px";
		loading.style.top = (((_height-loading.offsetHeight)/2)-44)+"px";
		jQuery("#"+ai("loading")).hide();
		
		showLength = xml.getElementsByTagName("slide").length;
		
		for(i=0; i<showLength; i++){
			showArray.push("/"+xml.getElementsByTagName("slide")[i].getAttribute("img_src"));
			}
			
		
		
		showDiv = document.createElement("div");
		base.appendChild(showDiv);
		showDiv.id = ai("showDiv");
		showDiv.style.position = "absolute";
		//jQuery(showDiv).hide();
		
		mainImg = document.createElement("img");
		showDiv.appendChild(mainImg);
		mainImg.style.position = "absolute";
		mainImg.style.top = 25+"px";
		mainImg.id = ai("mainImg");
		jQuery("#"+ai("mainImg")).bind("load", function (){
			imgLoaded();
			});	
		//onImageLoad(document.getElementById(ai("mainImg")), assetLoaded);
		mainImg.onmouseup = nextFunc;
		mainImg.onmouseover = hit_over;
		mainImg.onmouseout = hit_out;

		
		
		xPos = 2;
		yPos = _height-25;
		_i = 0;
		jQuery(xml).find("slide").each(function(){	
			
			button = document.createElement("div");
			base.appendChild(button);
			button.style.position = "absolute";
			button.appendChild(document.createElement("div"));
			button.id = ai("button"+_i);
			button.style.background = "#999999";
			button.style.width = 10+"px";
			button.style.height = 10+"px";
			button.style.left = xPos+"px";
			button.style.top = yPos+"px";
			button.onmouseup = jump;
			button.onmouseover = hit_over;
			button.onmouseout = hit_out;
			button.name = _i;
			xPos += 12;
			
			if(xPos>(_width-110)){
				xPos = 2;
				yPos += 12;
				}
			_i++;
			
			});
		
		prevBtn = document.createElement("img");
		showDiv.appendChild(prevBtn);
		prevBtn.style.position = "absolute";
		prevBtn.style.top = 4+"px";
		prevBtn.style.left = (_width-100)+"px";
		prevBtn.id = ai("prevBtn");
		//onImageLoad(document.getElementById(ai("prevBtn")), assetLoaded);
		jQuery("#"+ai("prevBtn")).bind("load", function (){
			prevLoaded();
			});
		prevBtn.onmouseup = prevFunc;
		prevBtn.onmouseover = hit_over;
		prevBtn.onmouseout = hit_out;
		//prevBtn.src = baseroot+"_images/prev.png";
		
		nextBtn = document.createElement("img");
		showDiv.appendChild(nextBtn);
		nextBtn.style.position = "absolute";
		nextBtn.style.top = 4+"px";
		nextBtn.style.left = (_width-40)+"px";
		nextBtn.id = ai("nextBtn");
		//onImageLoad(document.getElementById(ai("nextBtn")), assetLoaded);
		jQuery("#"+ai("nextBtn")).bind("load", function (){
			nextLoaded();
			});
		nextBtn.onmouseup = nextFunc;
		nextBtn.onmouseover = hit_over;
		nextBtn.onmouseout = hit_out;
		//nextBtn.src = baseroot+"_images/next.png";
		
		prevBtn2 = document.createElement("img");
		showDiv.appendChild(prevBtn2);
		prevBtn2.style.position = "absolute";
		prevBtn2.style.top = (_height-18)+"px";
		prevBtn2.style.left = (_width-100)+"px";
		prevBtn2.id = ai("prevBtn2");
		//onImageLoad(document.getElementById(ai("prevBtn2")), assetLoaded);
		jQuery("#"+ai("prevBtn2")).bind("load", function (){
			prev2Loaded();
			});
		prevBtn2.onmouseup = prevFunc;
		prevBtn2.onmouseover = hit_over;
		prevBtn2.onmouseout = hit_out;
		//prevBtn2.src = baseroot+"_images/prev.png";
		
		nextBtn2 = document.createElement("img");
		showDiv.appendChild(nextBtn2);
		nextBtn2.style.position = "absolute";
		nextBtn2.style.top = (_height-18)+"px";
		nextBtn2.style.left = (_width-40)+"px";
		nextBtn2.id = ai("nextBtn2");
		//onImageLoad(document.getElementById(ai("nextBtn2")), assetLoaded);
		jQuery("#"+ai("nextBtn2")).bind("load", function (){
			next2Loaded();
			});
		nextBtn2.onmouseup = nextFunc;
		nextBtn2.onmouseover = hit_over;
		nextBtn2.onmouseout = hit_out;
		//nextBtn2.src = baseroot+"_images/next.png";
		
		bodyDekBg = document.createElement("div");
		showDiv.appendChild(bodyDekBg);
		bodyDekBg.id = ai("bodyDekBg");
		bodyDekBg.appendChild(document.createElement("div"));
		bodyDekBg.style.position = "absolute";
		bodyDekBg.style.background = "#eeeeee";
		jQuery("#"+ai("bodyDekBg")).fadeTo(0, 0.7);
		
		bodyDek = document.createElement("div");
		showDiv.appendChild(bodyDek);
		bodyDek.id = ai("bodyDek");
		bodyDek.className = "bodyDek";
		bodyDek.style.position = "absolute";
		bodyDek.style.border = "1px solid #333333";
		bodyDek.style.padding = "5px";
		bodyDek.style.width = (_width-54)+"px";
		
		counter = document.createElement("div");
		counter.id = ai("counter");
		counter.style.position = "absolute";
		counter.style.left = 2+"px";
		counter.style.top = 5+"px";
		counter.style.width = 50+"px";
		showDiv.appendChild(counter);
		counter.style.color = "#000000";
		
		
		curtain = document.createElement("div");
		base.appendChild(curtain);
		curtain.id = ai("curtain");
		curtain.style.position = "absolute";
		curtain.appendChild(document.createElement("div"));
		curtain.style.background = "#ffffff";
		curtain.style.width = _width+"px";
		curtain.style.height = _height+"px";
		//jQuery("#"+ai("curtain")).fadeTo(0, 0.5);
		
		loadingLine = document.createElement("div");
		curtain.appendChild(loadingLine);
		loadingLine.id = ai("loadingLine");
		loadingLine.appendChild(document.createElement("div"));
		loadingLine.style.position = "absolute";
		loadingLine.style.background = "#333333";
		loadingLine.style.width = 1+"px";
		loadingLine.style.height = 1+"px";
		loadingLine.style.left = ((_width-loadingLine.offsetWidth)/2)+"px";
		loadingLine.style.top = ((_height+100)/2)+"px";
		
		landing = document.createElement("img");
		base.appendChild(landing);
		landing.style.position = "absolute";
		landing.id = ai("landing");
		landing.style.top = 100+"px";
		landing.style.left = (_width-247)/2+"px";
		jQuery("#"+ai("landing")).bind("load", function (){
			landingLoaded();
			});
		//onImageLoad(document.getElementById(ai("landing")), assetLoaded);
		landing.onmouseup = hideLanding;
		landing.onmouseover = hit_over;
		landing.onmouseout = hit_out;
		landing.src = baseroot+"gallery_assets/landing_title.jpg";
		
		
		}
		
	function landingLoaded(){
		assetLoaded();
		var landing = document.getElementById(ai("landing"));
		var mid = (_height-landing.offsetHeight)/2;
		landing.style.left = (_width-landing.offsetWidth)/2+"px";
		jQuery("#"+ai("loadingLine")).animate({opacity:0.0},0);
		jQuery("#"+ai("landing")).animate({opacity:0},0);
		jQuery("#"+ai("loadingLine")).animate({opacity:1.0},500);
		jQuery("#"+ai("landing")).animate({top:mid,opacity:1.0},500,nextStep);	
		}		

	function nextStep(){		
		document.getElementById(ai("mainImg")).src = showArray[currentLoc];
		}

	function mainImgLoaded(){
		assetLoaded();
		document.getElementById(ai("prevBtn")).src = baseroot+"gallery_assets/prev.png";
		}
		
	function prevLoaded(){
		assetLoaded();	
		document.getElementById(ai("nextBtn")).src = baseroot+"gallery_assets/next.png";
		}
		
	function nextLoaded(){
		assetLoaded();	
		document.getElementById(ai("prevBtn2")).src = baseroot+"gallery_assets/prev.png";
		}
		
	function prev2Loaded(){
		assetLoaded();	
		document.getElementById(ai("nextBtn2")).src = baseroot+"gallery_assets/next.png";
		}
		
	function next2Loaded(){
		assetLoaded();
		}
		
	function assetLoaded(){
		
		loadInc++;
		
		//document.getElementById(ai("loadingLine")).style.width = ((300/6)*loadInc)+"px";
		//document.getElementById(ai("loadingLine")).style.left = ((_width-loadingLine.offsetWidth)/2)+"px";
		
		jQuery("#"+ai("loadingLine")).animate({opacity:1.0},500);
		
		//document.getElementById(ai("testtxt")).innerHTML += loadInc+" ";
		if(loadInc>=6){
			//jQuery("#"+ai("loadingLine")).show();
			var landing = document.getElementById(ai("landing"));
			jQuery("#"+ai("landing")).animate({opacity:0.0},2000, hideLanding);
			
			
			jQuery("#"+ai("loadingLine")).animate({opacity:0.0},2000);
			
			checkText();
			//loadImage();
			//hideLanding();
			}
		}

	function goLoader(){
		window.clearInterval(loaderTimer);
		loaderTimer = window.setInterval(loadTimer, 100);
		jQuery("#"+ai("loading")).show();
		}

	function loadTimer(){
		for(i = 0; i<loaderNumber; i++){
			document.getElementById(i+ai("dot")).style.color = colorArray[i];
			}
		
		var end = colorArray.pop();
		colorArray.splice(0,0,end);
		}

	function parse(s){
		//document.getElementById(ai("testtxt")).innerHTML = "";
		s = s.split("<freightitalic>").join("<div class='freightitalic'>");
		s = s.split("</freightitalic>").join("</div>");
		s = s.split("<freightitalic2>").join("<div class='freightitalic2'>");
		s = s.split("</freightitalic2>").join("</div>");
		s = s.split("<freight>").join("<div class='freight'>");
		s = s.split("</freight>").join("</div>");
		s = s.split("<arial18>").join("<div class='arial18'>");
		s = s.split("</arial18>").join("</div>");
		s = s.split("<arial12>").join("<div class='arial12'>");
		s = s.split("</arial12>").join("</div>");
		
		var newString = "";
		for(i=0; i<s.length; i++){
			newString += s[i];
			}

		return s;
		}
		
	function jump(){
		var num = this.name;
		currentLoc = num;
		loadImage();
		}
		

		
	function onImageLoad(ele, func){
			
			_ele = ele;
			_func = func;
		
			if (_ele.addEventListener) {
				_ele.addEventListener("load", _func, false);
				
				}
			else if (_ele.attachEvent) {
				_ele.attachEvent("onload", _func);
				} 
			else {
				_ele.onLoad = _func;
				}
			//document.getElementById(ai("testtxt")).innerHTML = ele;
		}
		
	function hideLanding(){
		landingOn = false;
		jQuery("#"+ai("curtain")).fadeOut(500);
		jQuery("#"+ai("landing")).fadeOut(500);
		jQuery("#"+ai("showDiv")).show();
		}
		
	function showCurtain(){
		currentLoc = 0;
		loadImage();
		jQuery("#"+ai("curtain")).hide();
		}
		
	function prevFunc(){
		if(!locked){
			locked = true;
			currentLoc--;
		
			if(currentLoc==-1){
				currentLoc = showLength-1;
				}
			loadImage();
			}
		}
		
	function nextFunc(){
		if(!locked){
			locked = true;
			currentLoc++;
			
			if(currentLoc==showLength){
				currentLoc = 0;
				}
			loadImage();
			}
		}
		
	function loadImage(){

		jQuery("#"+ai("mainImg")).hide();
		document.getElementById(ai("mainImg")).src = showArray[currentLoc];
		/*jQuery("#"+ai("mainImg")).bind("load", function (){
			imgLoaded();
			});
		*/
		//onImageLoad(document.getElementById(ai("mainImg")), imgLoaded);
		goLoader();
		document.getElementById(ai("counter")).innerHTML = "<div class='arial12'>"+(currentLoc+1)+" of "+showLength+"</div>";
		checkText();
		
		logTraffic();
		}
	

		
	function checkText(){
		var textOn = xmlData.getElementsByTagName("images")[0].attributes.getNamedItem("slidecopy").nodeValue.toString().toUpperCase();
		
		if(textOn == "TRUE"){
			setText();
			}
		else{
			hideText();
			}
		}
		
	function logTraffic(){
	
		urchinTracker(instance);

		jsFunc(instance);
		
		}
		
	function imgLoaded(){
		jQuery("#"+ai("loading")).hide();
		window.clearInterval(loaderTimer);
		jQuery("#"+ai("mainImg")).fadeIn(500);
		locked = false;
		
		var mainImg = document.getElementById(ai("mainImg"));
		mainImg.style.left = ((_width-mainImg.width)/2)+"px";
		mainImg.style.top = (((_height-mainImg.height)/2)-10)+"px";
		
		document.getElementById(ai("button"+currentLoc)).style.background = "#333333";
		if(landingOn){
			mainImgLoaded();
			//jQuery(showDiv).hide();
			}
		
		}
	function hideText(){
		jQuery("#"+ai("bodyDek")).hide();
		jQuery("#"+ai("bodyDekBg")).hide();
		}
	
	function setText(){
		var bDek = document.getElementById(ai("bodyDek"));
		var bDekBg = document.getElementById(ai("bodyDekBg"));
		

			
		var textStr = xmlData.getElementsByTagName("title")[currentLoc].childNodes[0].data.toString();
		jQuery("#"+ai("bodyDek")).show();
		jQuery("#"+ai("bodyDekBg")).show();	
		if(textStr.length > 0){
	
			bDek.innerHTML = textStr;
				
			bDek.style.left = ((_width-bDek.offsetWidth)/2)+"px";
			bDek.style.top = ((_height-(bDek.offsetHeight))-45)+"px";
			
			
			bDekBg.style.width = bDek.offsetWidth+"px";
			bDekBg.style.height = bDek.offsetHeight+"px";
			bDekBg.style.left = bDek.offsetLeft+"px";
			bDekBg.style.top = bDek.offsetTop+"px";
			
			//document.getElementById(ai("testtxt")).innerHTML = ">>>> "+bDek.offsetWidth+" "+_width+" "+(_width-(bDek.offsetWidth)/2);
			
			jQuery("#"+ai("bodyDek")).hide();
			jQuery("#"+ai("bodyDek")).fadeIn(500);
			jQuery("#"+ai("bodyDekBg")).hide();
			jQuery("#"+ai("bodyDekBg")).fadeIn(500);
			}
		else{
			jQuery("#"+ai("bodyDek")).hide();
			jQuery("#"+ai("bodyDekBg")).hide();
			}
		}
	
	function hit_over(){
		this.style.cursor = "pointer";
		}
		
	function hit_out(){
		this.style.cursor = "default";
		}
		
		
	function ai(s){
		s = instance+"_"+s;
		return s;
		}
		
	//####################################// feature code, do not edit! //####################################//

	}
