/*
 * ACCIDENT GALLERY.COM
 *
 * Class: artistmenu.js
 * Version: 1.0.0
 * Desc:	The class responsible for all
 *		artist page functions. Defines
 *		loading operations of all artist
 *		subpages.
 */
var ArtistMenu = function() {
	var xmlhttp = null;
	var xmlDoc = null;
	var artist = null;
	var clickable = null;

	function init() {
		artist = document.getElementById("artist_page");
		allowClick();
	}
	function suspend() {
		artist = null;
		preventClick();
	}
	function xmlGetRequest() {
		if(window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			if(window.XMLHttpRequest) {
				xmlhttp = new XMLHttpRequest();
			} else {
				alert("failed to create XMLHttpRequest");
			}
		}
	}
	function xmlGetResponse() {
		return xmlhttp.responseText;
	}
	function xmlAttachEvents() {
		xmlhttp.onreadystatechange = xmlChange;
	}
	function xmlChange() {
		if(xmlhttp.readyState == 4 && xmlDoc == null) {
			xmlDoc = xmlGetResponse();
			xmlResult();
			xmlRevealResult();
		}
	}	
	function xmlLoadFile(xDoc, sFlag) {
		xmlhttp.open("GET", xDoc, sFlag);
		xmlhttp.send(null);
	}
	function xmlResult() {
		artist.innerHTML = xmlDoc;
	}
	function xmlRevealResult() {

		var fadeIn = 20;

		var anim = new Animator();

		var obj1 = new MovingObject(artist);
			obj1.loadMotionA(new Tween(	0,
							100,
							0,
							fadeIn,
							new Spline(fadeIn,
								[	{x: 0.00,  y: 0.00,  c: 1.00,  m:null},
									{x: 0.00,  y: 0.00,  c: 1.00,  m:null},
									{x: 0.40,  y: 0.20,  c: 0.50,  m:null},
									{x: 0.60,  y: 0.80,  c: 0.50,  m:null},
									{x: 1.00,  y: 1.00,  c: 1.00,  m:null},
									{x: 1.00,  y: 1.00,  c: 1.00,  m:null}	]),
								function(){ cleanUp() }));
		var objArray = [obj1];
		anim.init(0, 60);
		anim.importList(objArray);
		anim.initScene();
		anim.animate();
	}
	function enter(i) {
		if(clickable) {
			preventClick();

			var fadeOut = 20;
		
			var anim = new Animator();

			var obj1 = new MovingObject(artist);
				obj1.loadMotionA(new Tween(	100,
							0,
								0,
								fadeOut,
								new Spline(fadeOut,
									[	{x: 0.00,  y: 0.00,  c: 1.00,  m:null},
										{x: 0.00,  y: 0.00,  c: 1.00,  m:null},
										{x: 0.40,  y: 0.20,  c: 0.50,  m:null},
										{x: 0.60,  y: 0.80,  c: 0.50,  m:null},
										{x: 1.00,  y: 1.00,  c: 1.00,  m:null},
										{x: 1.00,  y: 1.00,  c: 1.00,  m:null}	]),
									function(){ load(i) }));
			var objArray = [obj1];
			anim.init(0, 60);
			anim.importList(objArray);
			anim.initScene();
			anim.animate();
		}
	}
	function load(i) {
		xmlGetRequest();
		xmlAttachEvents();
		xmlDoc = null;

		if(xmlhttp) {
			if(i == 0) {	
				xmlLoadFile("xml/phyllis_barba.xml", true);
			}
			if(i == 1) {
				xmlLoadFile("xml/ananda_oliveri.xml", true);
			}
			if(i == 2) {
				xmlLoadFile("xml/made_in_china.xml", true);
			}
			if(i == 3) {
				xmlLoadFile("xml/natalie_craig.xml", true);
			}
			if(i == 4) {
				xmlLoadFile("xml/eric_furman.xml", true);
			}
			if(i == 5) {
				xmlLoadFile("xml/scott_hemphill.xml", true);
			}
			if(i == 6) {
				xmlLoadFile("xml/james_hildebrandt.xml", true);
			}
			if(i == 7) {
				xmlLoadFile("xml/jeff_hunter.xml", true);
			}
			if(i == 8) {
				xmlLoadFile("xml/kristen_hunter.xml", true);
			}
			if(i == 9) {
				xmlLoadFile("xml/georgia_long.xml", true);
			}
			if(i == 10) {
				xmlLoadFile("xml/jose_nunez.xml", true);
			}
			if(i == 11) {
				xmlLoadFile("xml/qwaizang.xml", true);
			}
			if(i == 12) {
				xmlLoadFile("xml/blake_reagan.xml", true);
			}
			if(i == 13) {
				xmlLoadFile("xml/rachel_schlueter.xml", true);
			}
			if(i == 14) {
				xmlLoadFile("xml/seth_smith.xml", true);
			}
			if(i == 15) {
				xmlLoadFile("xml/marceau_verdiere.xml", true);
			}
			if(i == 16) {
				xmlLoadFile("xml/david_white.xml", true);
			}
		}
	}

	function allowClick() {
		clickable = true;
	}
	function removeAlpha() {
		artist.style.opacity = "";
		artist.style.filter = "";
	}
	function cleanUp() {
		removeAlpha();
		allowClick();
	}
	function preventClick() {
		clickable = false;
	}

	this.enter = enter;
	this.init = init;
	this.suspend = suspend;
}