var globalScope = null;

function printTextSequentially(text,elementId, mlSecs) {
	this.text = text;
	this.element = document.getElementById(elementId);
	this.charCtr = -1;
	this.delay = mlSecs
	this.interval = null;
	this.timeout = null;
    this.init();  
}

printTextSequentially.prototype = {
	init: function() {
        //bypass IE
        if(document.all) {
            globalScope = this;
            this.interval = window.setInterval(this.render,this.delay);
        }    
        else {
            this.interval = window.setInterval(this.render,this.delay,this);
        }
	},
    render: function(oThis) {
        if(!oThis) {
            oThis = globalScope;
        }
        oThis.charCtr++;
		  if(oThis.charCtr <= oThis.text.length) {
			 oThis.updateText();
		  }
		  else {	
            oThis.pause();
		  }		
	},
	updateText: function() {
		this.element.innerHTML = this.text.substr(0,this.charCtr);
	},
	pause: function() {
	   window.clearInterval(this.interval);
	   this.timeout = window.setTimeout(this.swipe,this.delay * 7,this);
    },
    blink: function(oThis) {
        if(!oThis) {
            oThis = globalScope;
        }
        window.clearTimeout(oThis.timeout);
        oThis.element.innerHTML = oThis.element.innerHTML.blink();        
        if(!globalScope) {
            oThis.timeout = window.setTimeout(oThis.swipe,oThis.delay * 7,oThis);
        }
        else {
            oThis.timeout = window.setTimeout(oThis.swipe,oThis.delay * 7);
        }
    },
	swipe: function(oThis) {
        if(!oThis) {
            oThis = globalScope;
        }
		window.clearTimeout(oThis.timeout);		
		if(!globalScope) {
            oThis.interval = window.setInterval(oThis.swipeStep, oThis.delay/oThis.text.length, oThis);
        }
        else {
            oThis.interval = window.setInterval(oThis.swipeStep, oThis.delay/oThis.text.length);
        }         
		
	},
	swipeStep: function(oThis) {
        if(!oThis) {
            oThis = globalScope;
        }
		oThis.charCtr--;
		if(oThis.charCtr == -1) {
			oThis.element.innerHTML = '';
			window.clearInterval(oThis.interval);
			oThis.init();
		}
		else {
			oThis.updateText();
		} 
	}	
}

 