;(function($){
	ep.theway = new function() {
		this.snowInt,
		this.textInt,
		this.start = function() {
			ep.game.init();
			this.setBackground('intro');
			$('#loading').hide();
			$('#text').show();
			$('#instructions').fadeIn(300);
			// this.startLights();
		},
		this.drums = function() {
			$('#instructions').fadeOut(1000);
		},
		this.verse1 = function() {
			// this.stopLights();
			this.setBackground('verse1');
			var text = "i didn't know i was a felon i didn't know till you cried i didn't know till your side withdrew ";
			this.addText(text,'verse1',300);
		},
		this.verse2 = function() {
			this.setBackground('verse2');
			var text = "i didn't know i was your terror i didn't know till you shouted i didn't know till you shouted it was true ";
			this.replaceText(text,'verse2', 300);
		},
		this.chorus1_a = function() {
			var text = "now i'm a vulture picking on our own remains ";
			this.replaceText(text,'chorus1_a', 100);
			this.setBackground('chorus1');
		},
		this.chorus1_b = function() {
			// this.startLights();
		},
		this.post_chorus1 = function() {
			// this.stopLights();
		},
		this.verse3 = function() {
			this.setBackground('verse3');
			var text = "i didn't know you'd be a mirror in which i see myself in which i see i am so cruel ";
			this.replaceText(text,'verse3', 200);
		},
		this.verse4 = function() {
			this.setBackground('verse4');
			var text = "a single word will make you shiver a single word will do and i keep saying it to you ";
			this.replaceText(text,'verse4', 400);
		},
		this.chorus2 = function() {
			this.setBackground('chorus2');
			var text = "how terribly natural the way that we bend and dent like a paperclip in a six year old's hands like a soda can or a very old man ";
			this.replaceText(text,'chorus2', 300);
		},
		this.chorus3 = function() {
			this.setBackground('chorus3');
			var text = "how terribly terribly natural the way that we bend and dent like a paperclip in a six year old's hands like a soda can or a very old man ";
			this.replaceText(text,'chorus3', 250);
		},
		this.ending_a = function() {
			this.startLights();
			$('#text').fadeOut(2000);
		},
		this.ending_b = function() {
			//
		},
		this.end = function() {
			//
		},
		this.stop = function() {
			clearInterval(this.textInt);
			clearInterval(this.snowInt);
			this.stopLights();
		},
		this.functions = function() {
			//
		},
		this.startLights = function()
		{
			var self = this;
			var y = 0;
			var x = 0;
			$('#snow').fadeIn(500);
			this.snowInt = setInterval(function() {
				$('#snow').css({'background-position':x + 'px ' + y + 'px'});
				y = (y < 1280) ? y+320 : 0;
				x = (x < 1023) ? x+341 : 0;
			}, 100);	
			
			self.lights = true;
		},
		this.stopLights = function()
		{	
			$('#snow').fadeOut(500);
			clearInterval(this.lightInt);
		},
		this.addText = function(text,className,speed) {
			clearInterval(this.textInt);

			this.textInt = setInterval(function() {
				var spanCount = $('#text span').size();

				if(spanCount<20) {
					$('#text').append('<span class="'+className+'">'+text+'</span>');
				}
			}, speed);
		},
		this.replaceText = function(text,className,speed) {
			clearInterval(this.textInt);
			var self = this;
			textSpans = $('#text span').size();
			var i=0;
			this.textInt = setInterval(function() {
				if(i<textSpans) {
					$('#text span:eq('+i+')').removeClass().addClass(className).text(text);
					i=i+1;
				} else {
					self.addText(text,className,speed);
				}
			}, speed);
		},
		this.setBackground = function(part) {
			$('#lightning').removeClass().addClass('matte '+ part);
		},
		this.createTextBox = function(id, text, optionsArray) {
			html = '<div id="' + id + '" class="text"><p>' + text + '</p>';
			html += '<ul class="options">';
			for (var i=0; i < optionsArray.length;i++) {
				html += '<li><a href="#" class="';
				html += optionsArray[i]['className'];
				html += '">' + optionsArray[i]['optionText'];
				if (i != optionsArray.length-1) {
					html += '</a> ** </li>';
				} else {
					html += '</a></li>';
				}
			}
			html += '</ul></div>';
			
			return html;
		},
		this.editTextBox = function(id, text, optionsArray) {
			html = '<ul class="options">';
			for (var i=0; i < optionsArray.length;i++) {
				html += '<li><a href="#" class="';
				html += optionsArray[i]['className'];
				html += '">' + optionsArray[i]['optionText'];
				if (i != optionsArray.length-1) {
					html += '</a> ** </li>';
				} else {
					html += '</a></li>';
				}
			}
			html += '</ul>';			
			
			$('p', id).html(text);
			$('ul', id).remove();
			$(id).append(html);
		};
	};
})(jQuery);
