// e4eTicker v1.4 // &copy; Stuart Elmore (c/o Bluestone Creative) // 09/02/2010
	
	$.fn.e4eTicker = function(){
	        if($(this).length === 0) return;
	        var thisTicker = this, options = arguments[0] || {};
	        this.defaults = {
	                pauseTime: 5000,
	                speed: 25,
	                loading: false,
	                preHTML: '',
	                postHTML: '',
	                animation: false // fade | slide
	        };
	        this.tickerElem = $(this);
	        this.dataArr = [];
	        this.tickerCounter = 0;
	        this.tickerChar = 0;
	        this.partHTML = false;
	        this.isLink = false;
	        this.isB = false;
	        this.isStrong = false;
	        this.isI = false;
	        this.isEm = false;
	        $.extend(this.defaults, options);
	        if(this.tickerElem.children('li').length === 0){
		        return thisTicker.tickerElem;
	        }
	        this.tickerElem.children('li').each(function(){
	                thisTicker.dataArr.push($(this).html());
	        });
	        this.tickerRotator = function(){
	                thisTicker.tickerElem.html($('<li />').append('&nbsp'));
	                if(thisTicker.tickerCounter == thisTicker.dataArr.length) thisTicker.tickerCounter = 0;
	                thisTicker.tickerChar = 0;
	                thisTicker.writeOut(thisTicker.dataArr[thisTicker.tickerCounter]);
	        };
	        this.writeOut = function(dataString){
	                var writeChar = dataString.substr(thisTicker.tickerChar, 1), writeOut = '';
	                if(writeChar == '<'){
		                thisTicker.partHTML = true;
		        }else if(writeChar == '>'){
			        thisTicker.partHTML = false;
			}
	                if(dataString.substr(thisTicker.tickerChar, 2) == '<a'){
		                thisTicker.isLink = true;
		        }
		         if(dataString.substr(thisTicker.tickerChar, 2) == '<A'){
		                thisTicker.isLink = true;
		        }
	                if(thisTicker.isLink === true){
		                if(dataString.substr(thisTicker.tickerChar, 3) == '</a' || dataString.substr(thisTicker.tickerChar, 3) == '</A') thisTicker.isLink = false;
	                }
	                if(dataString.substr(thisTicker.tickerChar, 2) == '<b' || dataString.substr(thisTicker.tickerChar, 2) == '<B'){
		                thisTicker.isB = true;
		        }
	                if(thisTicker.isB === true){
		                if(dataString.substr(thisTicker.tickerChar, 3) == '</b' || dataString.substr(thisTicker.tickerChar, 3) == '</B') thisTicker.isB = false;
	                }
	                if(dataString.substr(thisTicker.tickerChar, 7) == '<strong' || dataString.substr(thisTicker.tickerChar, 7) == '<STRONG'){
		                thisTicker.isStrong = true;
		        }
	                if(thisTicker.isStrong === true){
		                if(dataString.substr(thisTicker.tickerChar, 3) == '</strong' || dataString.substr(thisTicker.tickerChar, 8) == '</STRONG') thisTicker.isStrong = false;
	                }
	                if(dataString.substr(thisTicker.tickerChar, 2) == '<i' || dataString.substr(thisTicker.tickerChar, 2) == '<I'){
		                thisTicker.isI = true;
		        }
	                if(thisTicker.isI === true){
		                if(dataString.substr(thisTicker.tickerChar, 3) == '</i' || dataString.substr(thisTicker.tickerChar, 3) == '</I') thisTicker.isI = false;
	                }
	                if(dataString.substr(thisTicker.tickerChar, 3) == '<em' || dataString.substr(thisTicker.tickerChar, 3) == '<EM'){
		                thisTicker.isEm = true;
		        }
	                if(thisTicker.isEm === true){
		                if(dataString.substr(thisTicker.tickerChar, 3) == '</em' || dataString.substr(thisTicker.tickerChar, 4) == '</EM') thisTicker.isEm = false;
	                }
	                thisTicker.tickerChar++
	                writeOut = (thisTicker.defaults.preHTML == '' ? '&nbsp;' : '');
	                 if(thisTicker.partHTML === false){
				if(thisTicker.defaults.animation === false){
			                writeOut += thisTicker.defaults.preHTML + dataString.substr(0, thisTicker.tickerChar);
		                }else{
			                writeOut = '<span class="e4eTicker_preAnimate">' + writeOut + thisTicker.defaults.preHTML + (dataString.substr(0, (thisTicker.tickerChar -1))) + '</span><span class="e4eTicker_animate" style="display:none;">' + (dataString.substr((thisTicker.tickerChar -1), 1)  == ' ' ? '&nbsp;' : dataString.substr((thisTicker.tickerChar -1), 1)) + '</span>';
		                }
		        }
	                writeOut += (thisTicker.tickerChar < dataString.length ? (thisTicker.defaults.loading !== false ? thisTicker.defaults.loading : '') : '');
	                if(thisTicker.partHTML === false){
		                if(thisTicker.isLink === true){
			                if($.browser.msie){
				                writeOut += '</A>';
			                }else{
				                writeOut += '</a>';
				        }
		                }
	                }
	                if(thisTicker.partHTML === false){
		                if(thisTicker.isB === true){
			                writeOut += '</b>';
		                }
	                }
	                if(thisTicker.partHTML === false){
		                if(thisTicker.isStrong === true){
			                writeOut += '</strong>';
		                }
	                }
	                if(thisTicker.partHTML === false){
		                if(thisTicker.isI === true){
			                writeOut += '</i>';
		                }
	                }
	                if(thisTicker.partHTML === false){
		                if(thisTicker.isEm === true){
			                writeOut += '</em>';
		                }
	                }
	                writeOut += thisTicker.defaults.postHTML;
	                 if(thisTicker.partHTML === false){
				if(thisTicker.defaults.animation !== false){
					writeOut += '<span class="e4eTicker_postAnimate"></span>';
				}
			}
	                $('li',thisTicker.tickerElem).html(writeOut);
	                if(thisTicker.tickerChar < (dataString.length + 1)){
	                        if(thisTicker.partHTML === true){
	                                thisTicker.writeOut(dataString)
	                        }else{
			                if(thisTicker.defaults.animation === false){
		                                window.setTimeout(function(){
		                                        thisTicker.writeOut(dataString);
		                                }, thisTicker.defaults.speed)
			                }else{        
				                if(thisTicker.defaults.animation == 'slide'){
					                $('li .e4eTicker_preAnimate', thisTicker.tickerElem).css({display:'block', float:'left'});
					                $('li .e4eTicker_postAnimate', thisTicker.tickerElem).css({display:'block', clear:'both'});
					                $('li .e4eTicker_animate', thisTicker.tickerElem).css({float:'left'}).slideDown(thisTicker.defaults.speed, function(){
						                thisTicker.writeOut(dataString);
					                });
				                }else{
					                $('li .e4eTicker_animate', thisTicker.tickerElem).css({opacity:0}).show().animate({opacity:1},thisTicker.defaults.speed, function(){
						                thisTicker.writeOut(dataString);
					                });
				                }
		                        }
	                        }
	                }else{
	                        thisTicker.tickerChar = 0;
	                        thisTicker.tickerCounter++;
	                        window.setTimeout(function(){
	                                thisTicker.tickerRotator();
	                        },thisTicker.defaults.pauseTime);
	                }
	        };
	        this.tickerRotator();
	};
