function rotator(id, tabStyle, rotateDuration, transitionDuration, slideClick) {
	
	if (!e) {
		var e = window.event;
	}

	/* Main */
	this.id = id;
	this.element = document.getElementById(id);
	this.tabStyle = tabStyle;
	this.animationAdjustment = 0;
	
	/* slide numbers */
	this.currentSlide = 1;
	this.nextSlide = 2;
	this.maxSlides = getElementsByClassName('rotator-slide','div',document.getElementById(id)).length;
	
	/* intervals */
	this.rotateTimeout = null;
	this.rotateDuration = rotateDuration;
	this.transitionTimeout = null;
	this.transitionDuration = transitionDuration;
	
	/* controls */
	this.paused = true;
	this.rotating = false;
	this.arrows = false;
	this.slideClick = slideClick;
	
	/* initialize the control */
	this.initialize = function() {
		
		/* let CSS know javascript is active */
		addClass(this.element, 'rotator-js');
		
		/* if there is more than one slide make arrows
		if (this.maxSlides=='a'){// > 1) {
			this.arrows = true;
			nav = this.element.getElementsByClassName('rotator-tabs')[0];
			el = document.createElement('li');
			el.setAttribute('class', 'rotator-direction rotator-left');
			el.innerHTML = '<span data-slide-number="' + this.maxSlide + '" title="Back">«</span>';
			nav.insertBefore(el, nav.firstChild);
			el = document.createElement('li');
			el.setAttribute('class', 'rotator-direction rotator-right');
			el.innerHTML = '<span data-slide-number="' + this.nextSlide + '" title="Forward">»</span>';
			nav.appendChild(el);
		}*/
		
		
		/* create the throbber */
		el = document.createElement('div');
		el.setAttribute('class','rotator-throbber');
		el.innerHTML = '<div class="rotator-throbber-needle"></div>';
		this.element.insertBefore(el,this.element.childNodes[0]);
		
		
		/* create the control thing */
		el = document.createElement('a');
		el.setAttribute('class', 'rotator-control');
		el.setAttribute('title', 'Click to Pause');
		el.setAttribute('href', '#pause');
		el.setAttribute('onclick', 'return false;');
		el.innerHTML = '||';
		if(el.addEventListener){
			el.addEventListener('click', function(e) {
				if (this.paused === true){
					this.play();
				} else if (this.paused === false){
					this.pause();
				}
			}.bind(this), false);
		} else if(el.attachEvent){
			el.attachEvent('onclick', (function(e) {
				if (this.paused == true){
					this.play();
				} else if (this.paused == false) {
					this.pause();
				}
			}).bind(this));
		}
		this.element.insertBefore(el,this.element.childNodes[0]);
			
		/* strip anchors out of tabs and add the click event listener to scroll rotator*/
		els = this.element.getElementsByTagName('nav')[0].getElementsByTagName('li');
		thisLength = els.length;
		for (i = 0; i < thisLength; i++) {
			//if (els[i].lastChild.nodeName.toLowerCase() === 'a') { els[i].removeChild(els[i].lastChild); }
			link = els[i].getElementsByTagName('a')[0].href;
			//els[i].getElementsByTagName('a')[0].setAttribute('href','#slide-'+parseInt(i+1));
			els[i].getElementsByTagName('a')[0].setAttribute('onclick','return false;');
			//newAnchor = document.createElement('a');
			//newAnchor.setAttribute('href',link);
			//newAnchor.setAttribute('class','overlay_link');
			//els[0].parentNode.parentNode.parentNode.getElementsByClassName('rotator-content')[0].getElementsByClassName('rotator-slide')[i].appendChild(newAnchor);
			els[i].getElementsByTagName('a')[0].setAttribute('data-ignore-ajax','true');
			if (window.addEventListener) {
				els[i].getElementsByTagName('a')[0].addEventListener('click', function(e) {
					if (this.rotating === false) {
						this.pause();
						slide = 1;
						if(e.target){
							if (e.target.nodeName.toLowerCase() === 'li') slide = e.target.getElementsByTagName('span')[0].getAttribute('data-slide-number');
							else (slide = e.target.getAttribute('data-slide-number'));
						} else if(e.srcElement){
							if (e.srcElement.nodeName.toLowerCase() === 'li') slide = e.srcElement.getElementsByTagName('span')[0].getAttribute('data-slide-number');
							else (slide = e.srcElement.getAttribute('data-slide-number'));
						}
						this.rotate(slide);
					}
				}.bind(this), false);
			} else if(els[i].attachEvent) {
				els[i].getElementsByTagName('a')[0].attachEvent('onclick', function(e) {
					this.pause();
					slide = 1;
					if(e.target){
						if (e.target.nodeName.toLowerCase() === 'li') slide = e.target.getElementsByTagName('span')[0].getAttribute('data-slide-number');
						else (slide = e.target.getAttribute('data-slide-number'));
					} else if(e.srcElement){
						if (e.srcElement.nodeName.toLowerCase() === 'li') slide = e.srcElement.getElementsByTagName('span')[0].getAttribute('data-slide-number');
						else (slide = e.srcElement.getAttribute('data-slide-number'));
					}
					this.rotate(slide);
				}.bind(this));
			}
		}
	
		/* play */
		//addClass(this.element.getElementsByClassName('rotator-slide')[0], 'current');
		//addClass(this.element.getElementsByClassName('rotator-tab')[0], 'current');
		this.animationAdjustment += 5;
		setTimeout(this.play, 5);
	};
	
	/* pause the rotator */
	this.pause = function() {
		if (this.paused === true) return;
		removeClass(getElementsByClassName('rotator-throbber-needle-active','div',document.getElementById(id))[0], 'rotator-throbber-needle-active');
		clearTimeout(this.rotateTimeout); this.rotateTimeout = null;
		removeClass(this.element, 'rotator-playing');
		addClass(this.element, 'rotator-paused');
		getElementsByClassName('rotator-control','a',document.getElementById(id))[0].innerHTML = '►';
		getElementsByClassName('rotator-control','a',document.getElementById(id))[0].setAttribute('title', 'Click to Play');
		getElementsByClassName('rotator-control','a',document.getElementById(id))[0].setAttribute('href', '#play');
		this.paused = true;
	}.bind(this);
	
	/* resume the rotator */
	this.play = function() {
		if (this.element == undefined) {
			this.animationAdjustment += 5;
			setTimeout(this.play, 5);
			return;
		}
		if (this.paused === true) {
			removeClass(this.element,'rotator-paused');
			addClass(this.element, 'rotator-playing');
			getElementsByClassName('rotator-control','a',document.getElementById(id))[0].innerHTML = '||';
			getElementsByClassName('rotator-control','a',document.getElementById(id))[0].setAttribute('title', 'Click to Pause');
			getElementsByClassName('rotator-control','a',document.getElementById(id))[0].setAttribute('href', '#pause');
			this.paused = false;
			this.loop();
		}
	}.bind(this);
	
	this.loop = function() {
		addClass(getElementsByClassName('rotator-throbber-needle','div',document.getElementById(id))[0], 'rotator-throbber-needle-active');
		this.rotateTimeout = setTimeout(this.advance, this.rotateDuration - this.animationAdjustment);
		this.animationAdjustment = 0;
	};

	
	/* advance the rotator one slide */
	this.advance = function() {
		this.rotate(parseInt(this.currentSlide) + 1);
	}.bind(this);
	
	/* show specified slide */
	this.rotate = function(slide) {
		if(!document.getElementById(this.id)){
			this.paused = true;
			return false;
		}
		if (this.rotating === false) {
			this.rotating = true;
			/* resolve the next slide to show*/
			if (slide > this.maxSlides) { slide = 1; }
			this.nextSlide = slide;
			
			/* update arrows 
			if (this.arrows === true) { 
				slide = parseInt(this.nextSlide) - 1;
				if (slide === 0) { slide = this.maxSlides; }
				this.element.getElementsByClassName('rotator-left')[0].getElementsByTagName('span')[0].setAttribute('data-slide-number', slide);
				slide = parseInt(this.nextSlide) + 1;
				if (slide > this.maxSlides) { slide = 1; }
				this.element.getElementsByClassName('rotator-right')[0].getElementsByTagName('span')[0].setAttribute('data-slide-number', slide);
			}*/
			
			/* trigger slide transition */
			removeClass(this.oCurrentTab(), 'current');
			removeClass(this.oCurrentSlide(), 'current');
			addClass(this.oNextTab(), 'current');
			addClass(this.oNextSlide(), 'current');
			
			/* complete rotation */
			removeClass(getElementsByClassName('rotator-throbber-needle','div',document.getElementById(id))[0], 'rotator-throbber-needle-active');
			this.transitionTimeout = setTimeout(this.completeRotation, this.transitionTimeout); 
		}
	};
	
	/* Trigger the CSS for hiding the current slide */
	this.completeRotation = function() {
		this.currentSlide = this.nextSlide;
		this.rotating = false;
		clearTimeout(this.transitionTimeout); this.transitionTimeout = null;
		clearTimeout(this.rotateTimeout); this.rotateTimeout = null;
		if (this.paused === false) this.loop();
	}.bind(this);
	
	/* get the current/next slides/tabs as objects */
	this.oCurrentTab = function() { return getElementsByClassName('rotator-tab','li',document.getElementById(id))[this.currentSlide - 1]; }
	this.oCurrentSlide = function() { return getElementsByClassName('rotator-slide','div',document.getElementById(id))[this.currentSlide - 1]; }
	this.oNextTab = function() { return getElementsByClassName('rotator-tab','li',document.getElementById(id))[this.nextSlide - 1]; }
	this.oNextSlide = function() { 	return getElementsByClassName('rotator-slide','div',document.getElementById(id))[this.nextSlide - 1]; }
}

