Info = function(element, articleHref){
		this.imageSrc    = element.children('img').attr('src')
		this.header      = element.children('h2').html()
		this.content     = element.children('p').html()
		this.articleHref = articleHref
	}
	
	
	MediaSelector = function(element, rotator){
		this.element = element
		a = element.children('a')
		articleLink = a.attr('href')
		a.removeAttr('href')
		this.info = new Info(element.children('div.info'), articleLink)
		this.element.click(
			{
				rotator:rotator,
				info:this.info,
				self:this
			},
			function(e){
				e.data.rotator.select(e.data.self, e.data.info, true)
			}
		)
	}
		MediaSelector.prototype.activate = function(){
			this.element.addClass('active')
		}
		MediaSelector.prototype.deactivate = function(){
			this.element.removeClass('active')
		}
	
	MediaSelectorList = function(element, rotator){
		this.element = element
		this.selectors = []
		listItems = element.children('li.media_selector').get()
		for(var i in listItems){
			this.selectors.push(new MediaSelector($(listItems[i]), rotator))
		}
		this.activeSelector = this.selectors[0]
		this.activeSelector.activate()
	}
		MediaSelectorList.prototype.activate = function(selector){
			this.activeSelector.deactivate()
			selector.activate()
			this.activeSelector = selector
		}
		MediaSelectorList.prototype.getNext = function(){
			var iToActivate = undefined
			for(var i = 0; i < this.selectors.length; i++){
				if(this.selectors[i] == this.activeSelector){
					iToActivate = i+1
				}
			}
			return this.selectors[iToActivate % this.selectors.length]
		}
	
	InfoPane = function(element){
		this.element     = element
		this.header      = element.children('h2')
		this.body        = element.children('p')
		this.articleLink = element.children('a')
		
	}
		InfoPane.prototype.load = function(info){
			this.element.slideUp(
				0, 
				function(self, info){
					return function(){
						self.header.html(info.header)
						self.body.html(info.content)
						self.articleLink.attr('href', info.articleHref)
						self.element.slideDown(300)
					}
				}(this, info)
			)
		}
	
	MediaRotator = function(element){
		this.element = $(element)
		this.infoPane = new InfoPane(element.children('div.info_pane'))
		this.selectors = new MediaSelectorList(element.children('ul'), this)
		this.stopRotation = false
		setTimeout(
			function(self){
				return function(){self.rotate()}
			}(this),
			8000
		)
	}
	
		MediaRotator.prototype.select = function(selector, stopRotation){
			stopRotation = stopRotation||false
			this.element.css('background', "url('" + selector.info.imageSrc + "')")
			this.infoPane.load(selector.info)
			this.selectors.activate(selector)
			this.stopRotation = stopRotation
		}
		
		MediaRotator.prototype.rotate = function(delay){
			if(!this.stopRotation){
				var selector = this.selectors.getNext()
				this.select(selector)
				setTimeout(
					function(self){
						return function(){self.rotate()}
					}(this),
					8000
				)
			}
		}

