 Sherlock = {
 	start:function(){
 		
 		this.scrambledContainer = glow.dom.get('.sl-cypher-encoded');
 		if(this.scrambledContainer.length==0) return;
 		
 		glow.dom.get('.sl-cypher-solution').addClass('sl-js'); 		
 		
 		this.addSolutionTrigger();
 		
 		
 	},
 	addSolutionTrigger:function(){
 		var h = '<a id="sl-cypher-trigger" href="#">Show Solution</a>';
 		glow.dom.get('.sl-cypher-solution').before(h);
		
		var t = this;
		var listener = glow.events.addListener('#sl-cypher-trigger',  'click', function () {
			glow.dom.get(this).remove();
			t.descramble();	
		});
		
 	},
 	descramble:function(){

 		
 		this.scrambledString = this.scrambledContainer.text();
 		 		
 		this.solutionString = glow.dom.get('.sl-cypher-solution-text').text();
 		
 		glow.dom.get('.sl-cypher-solution').css('display','block');
 		
 		
 		this.step = 1;
 		this.maxStep = this.solutionString.length+1;
 		
 		var t = this;
 		clearInterval(this.interalId);
 		this.interalId = setInterval ( function(){ t.descrambleStep(); }, 80 );


 	},
 	descrambleStep:function(){
 		var solvedString = this.solutionString.substring(0,this.step);
 		var unsolvedString = this.scrambledString.substring(this.step);
 		this.scrambledContainer.text(solvedString + unsolvedString);
 		
 		this.step++;
 		
 		if(this.step>=this.maxStep) clearInterval(this.interalId);
 	}
 }
  
