//--------------------------------------------------------------------------------------------------
// HELPERS
//--------------------------------------------------------------------------------------------------

var Helpers = new Object;
Helpers.getElementsByClass = function (searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
Helpers.generateId = function () {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var randomstring = '';
	var n = 12;
	for (var i=0; i < n; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

Helpers.preloadImage = function (url) {
	var img = new Image(100,25); 
	img.src = url;
}

Helpers.insertArrayItem = function ( arr, item, index ) {
	var arrA = arr.slice(0,index);
	var arrB = arr.slice(index);
	arrB.unshift(item);
	return arrA.concat(arrB);
}

Helpers.getMaxContentHeight = function ( htmlArray, containerClass ) {
	var containerDiv = document.getElementById('helpers-container');
	var div = document.createElement('DIV');
	if (containerDiv) {
		containerDiv.appendChild(div);
	} else {
		document.body.appendChild(div);
	}
	div.className = ( containerClass ? containerClass : '' );
	div.style.position = 'absolute';
	div.style.width = '2000px';
	div.style.left = 10000;
	var maxHeight = 0;
	if ( typeof htmlArray == 'string' ) {
		var temp = htmlArray;
		htmlArray = new Array;
		htmlArray.push( temp );
	}
	for (var i=0; i < htmlArray.length; i++ ) {
		if (typeof htmlArray[i] == 'object') {
			div.innerHTML = htmlArray[i].html;
		} else {
			div.innerHTML = htmlArray[i];
		}
		var h = Element.getHeight(div);
		maxHeight = ( h > maxHeight ? h : maxHeight );
	}
	if (containerDiv) {
		containerDiv.removeChild(div);
	} else {
		document.body.removeChild(div);
	}
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){	
		maxHeight += 8;
	}
	return maxHeight;
 }

Helpers.popup = function ( popupElem, hoverElem, width, hPos, vPos, hOffset, vOffset, strict ) {
	if ( width > 0 ) {
		elem.style.width = width + 'px';
	}
	if (typeof popupElem == 'string'){
		popupElem = $(popupElem);
	}
	if (typeof hoverElem == 'string'){
		hoverElem = $(hoverElem);
	}
	vOffset = ( (vOffset > 0) || (vOffset < 0) ? vOffset : 0 );
	hOffset = ( (hOffset > 0) || (hOffset < 0) ? hOffset : 0 );
	var tlHover = Position.cumulativeOffset(hoverElem);
	var hwHover = Element.getDimensions(hoverElem);
	var hwpopup = Element.getDimensions(popupElem);
	var hwViewport = document.viewport.getDimensions();
	var scrollOffset = document.viewport.getScrollOffsets();
	popupElem.style.position= 'absolute';
	popupElem.style.display = 'block';
	popupElem.style.top = (tlHover.top + hwHover.height + vOffset ) + 'px';
	if (hPos == 'left') {
		popupElem.style.left = ( tlHover.left + hOffset - hwpopup.width) + 'px';
	} else if (hPos=='right') {
		popupElem.style.left = ( tlHover.left + hOffset + hwHover.width) + 'px';
	} else if (hPos=='flush-left') {
		popupElem.style.left = ( tlHover.left + hOffset ) + 'px';
	} else if (hPos=='flush-right') {
		popupElem.style.left = ( tlHover.left + hOffset + (hwpopup.width - hwHover.width) ) + 'px';
	} else if (vPos=='center') {
		popupElem.style.left = ( tlHover.left + hOffset + (hwHover.width/2) - (hwpopup.width/2) ) + 'px';
	}
	if (vPos == 'top') {
		popupElem.style.top = ( tlHover.top + vOffset - hwpopup.height) + 'px';
	} else if (vPos=='bottom') {
		popupElem.style.top = ( tlHover.top + vOffset + hwHover.height) + 'px';
	} else if (vPos=='flush-top') {
		popupElem.style.top = ( tlHover.top + vOffset ) + 'px';
	} else if (vPos=='flush-bottom') {
		popupElem.style.top = ( tlHover.top + vOffset + (hwpopup.height - hwHover.height) ) + 'px';
	} else if (vPos=='center') {
		popupElem.style.top = ( tlHover.top + vOffset + (hwHover.height/2) - (hwpopup.height/2) ) + 'px';
	}
	if ( strict != true ) {
		hwPopup = Element.getDimensions(popupElem);
		var tlPopup = Position.cumulativeOffset(popupElem);
		var hwViewport = document.viewport.getDimensions();
		var scrollOffset = document.viewport.getScrollOffsets();
		var vAdjust = 0
		if ( (tlPopup.top + hwPopup.height) > (hwViewport.height + scrollOffset.top) ) {	// too low?
			vAdjust = (hwViewport.height + scrollOffset.top) - (tlPopup.top + hwPopup.height);
		} else if ( (tlPopup.top) < (scrollOffset.top) ) {	// too high?
			vAdjust = (scrollOffset.top) - (tlPopup.top);
		}
		popupElem.style.top = ( tlPopup.top + vAdjust ) + 'px';
	}
	popupElem.style.zIndex = 4000;
	Helpers.currentHoverElem = hoverElem;
	Helpers.currentPopupElem = popupElem;
	if (! hoverElem.onmouseout) {
		hoverElem.onmouseout = function () {
			Helpers.hidePopup( Helpers.currentPopupElem );
		}
	}
}

Helpers.hidePopup = function ( popupElem ) {
	if (typeof popupElem == 'string'){
		popupElem = $(popupElem);
	}
	if (popupElem) {
		popupElem.style.display = 'none';
	}
}

//--------------------------------------------------------------------------------------------------
// TAB BOX
//--------------------------------------------------------------------------------------------------

var TabBoxContainer = function (id) {
	this.id = id;
	this.panes = new Array;
	this.addPane = function (paneId, tabLabel, paneHTML ) {
		var pane = new TabBoxPane( paneId, tabLabel, paneHTML );
		this.panes.push( pane );
		pane.index = this.panes.length - 1;
		return pane;
	}
	this.setActivePaneById = function ( id ) {
		var pane = this.getPaneById( id );
		if (pane) {
			this.setActivePaneByIndex( pane.index );
		}
	}
	this.getPaneById = function ( id ) {
		for (var i=0; i < this.panes.length; i++ ) {
			if (this.panes[i].id == id) {
				return this.panes[i];
			}
		}
	}
	this.setActivePaneByIndex = function ( i ) {
		var pane = this.getPaneByIndex( i );
		if (pane) {
			var oldPane = this.getPaneByIndex( this.activePaneIndex );
			if (oldPane) {
				if (oldPane.hasRotator) {
					oldPane.rotatorSet.visible = false;
				}
			}
			this.activePaneIndex = pane.index;
		}
		if (this.statusRendered == true) {
			this.render();
			if (pane.hasRotator) {
				pane.rotatorSet.visible = true;
			}
		}
	}
	this.getPaneByIndex = function ( i ) {
		return this.panes[i];
	}
	this.renderTabs = function () {
		this.tabstripContainer.innerHTML = '';
		for (var i=0; i < this.panes.length; i++ ) {
			var tabClass = ( i == this.activePaneIndex ? 'current' : '' );
			tabClass += ( i == 0 ? ' first' : '' );
			tabClass += ( i == this.panes.length - 1 ? ' last' : '' );
			this.tabstripContainer.innerHTML += '<a id="tab-'+this.panes[i].id+'" class="tab '+tabClass+'" href="javascript:void(0);" onmousedown="TabBox.setActivePaneById(\''+this.id+'\',\''+this.panes[i].id+'\');">'+this.panes[i].label+'</a>';
		}
		//this.tabstripContainer.innerHTML += '<div style="clear:both"></div>';
	}
	this.render = function (params) {
		params = ( params ? params : new Object );
		this.params = params;
		if (this.statusInitialized==false){
			this.init();
		}
		if (this.activePaneIndex == -1) {
			if (this.params.randomize==true) {
				this.activePaneIndex = Math.floor(Math.random() * this.panes.length);
			} else {
				if ( this.params.showFirst > 0 ) {
					this.activePaneIndex = this.params.showFirst;
				} else if ( this.params.showFirst )	{
					this.setActivePaneById( this.params.showFirst );
				} else {
					this.activePaneIndex = 0;
				}
			}
		}
		if (this.statusInitialized==true){
			this.renderTabs();
			this.boxContainer.innerHTML = this.panes[this.activePaneIndex].html;
			this.statusRendered = true;
		}
	}
	this.init = function () {
		this.boxContainer = document.getElementById('tabbox-'+this.id);
		this.tabstripContainer = document.getElementById('tabstrip-'+this.id);
		if ( (this.boxContainer) && (this.tabstripContainer)){
			this.statusInitialized = true;
		}
	}
	this.activePaneIndex = -1;
	this.style = new Object;
	this.style.backgroundColor = '#dfdfdf';
	this.style.borderColor = '#ccc';
	this.statusRendered = false;
	this.statusInitialized = false;
}

var TabBoxPane = function (id, label, html) {
	this.id = ( id ? id : Helpers.generateId() );
	this.index = null;
	this.label = (label ? label : 'NO LABEL' );
	this.html = ( html ? html : '' );
	this.setHTML = function ( html ) {
		this.html = html;
	}
}

var TabBox = new Object;
TabBox.boxes = new Array;

TabBox.addBox = function (id) {
	var box = new TabBoxContainer(id);
	this.boxes.push( box );
	return box;
}
TabBox.getBoxById = function (id) {
	for (var i=0; i < this.boxes.length; i++ ) {
		if (this.boxes[i].id == id) {
			return this.boxes[i];
		}
	}
}
TabBox.parseContent = function (boxId) {
	var boxDiv = document.getElementById('tabbox-'+boxId);
	var ul = ( boxDiv ? boxDiv.getElementsByTagName('UL')[0] : '' );
	if ( ! ul ) {
		ul = document.getElementById('tabbox-content-'+boxId);
	}
	var box;
	if (ul) {
		box = TabBox.addBox(boxId);
		var li = ul.getElementsByTagName('LI');
		for (var i=0; i < li.length; i++) {
			var paneHTML = '';
			var label = '';
			var paneId;
			if ( li[i].id ) {
				var re = new RegExp('tabbox-content-'+boxId+'-(.+)','');
				paneId = re.exec(li[i].id)[1];
			} else {
				paneId = Helpers.generateId();
			}
			
			var divs = li[i].getElementsByTagName('DIV');
			for (var ii=0; ii < divs.length; ii++) {
				if (divs[ii].className == 'tab-pane'){
					paneHTML = divs[ii].innerHTML;
				} else if (divs[ii].className == 'tab-label'){
					label = divs[ii].innerHTML;
				}
				if ( (label) && (paneHTML) ) {
					box.addPane( paneId, label, paneHTML );
					break;
				}
			}
		}
		return box;
	}
	return null;
}
TabBox.setActivePaneById = function ( boxId, paneId ) {
	var box = TabBox.getBoxById( boxId );
	box.setActivePaneById( paneId );
}

//var box = TabBox.addBox('spotlight');
//var pane = box.addPane( 'your_biz', 'Your Biz' );
//pane.setHTML('test');
//alert( box.getPaneById('your_biz').html );


//--------------------------------------------------------------------------------------------------
// INPUT GHOST TEXT
//--------------------------------------------------------------------------------------------------

function setGhostValue (id, text, ghostColor, textColor) {
	var elem = document.getElementById(id);
	if ( elem ) {
		elem.dirty = false;
		elem.ghostValue = text;
		elem.value = text;
		elem.style.color = ghostColor;
		elem.textColor = textColor;
		elem.ghostColor = ghostColor;
		elem.onfocus = function () {
			if (this.dirty == false) {
				this.value = '';
				this.style.color = this.textColor;
			}
		}
		elem.onblur = function () {
			if (this.dirty == false) {
				this.value = this.ghostValue;
				this.style.color = this.ghostColor;
			}
		}
		elem.onkeypress = function () {
			this.dirty = true;
		}
	}
}

//--------------------------------------------------------------------------------------------------
// DROPDOWN MENUS
//--------------------------------------------------------------------------------------------------

DropdownMenu = function (id, label, menuElem, hoverElem) {
	this.id = id;
	this.label = label;
	this.menuElem = menuElem;
	this.hoverElem = hoverElem;
	this.params = new Object;
	this.show = function () {
		if (Dropdown.visibleMenu) {
			Dropdown.visibleMenu.hide();
		}
		Dropdown.currentMenu = this;
		Dropdown.visibleMenu = this;
		Helpers.popup( this.menuElem, this.hoverElem, 0, 'flush-left', 'bottom', this.displayOffsetX, this.displayOffsetY, true );
		if (this.params.backgroundColor) {
			this.menuElem.style.backgroundColor = this.params.backgroundColor;
		}
	}
	this.hide = function () {
		this.menuElem.style.display = 'none';
		Dropdown.visibleMenu = null;
		Dropdown.currentMenu = null;
	}
}

Dropdown = new Object;
Dropdown.menus = new Array;
Dropdown.currentMenu = null;
Dropdown.addMenuAsElement = function (id, menuElemId, hoverElemId, displayOffsetX, displayOffsetY, params ) {
	var menuElem = document.getElementById(menuElemId);
	var hoverElem = document.getElementById(hoverElemId);
	id = ( id ? id : Helpers.generateId() );
	var menu = new DropdownMenu( id, '', menuElem, hoverElem );
	menu.displayOffsetX = ( displayOffsetX ? displayOffsetX : 0 );
	menu.displayOffsetY = ( displayOffsetY ? displayOffsetY : 0 );
	menu.params = params ? params : new Object;
	Dropdown.menus.push( menu );
	if (hoverElem) {
		hoverElem.menu = menu;
		hoverElem.hovering = false;
		hoverElem.onmouseover = function () {
			this.hovering = true;
			this.menu.show();
		}
		hoverElem.onmouseout = function () {
			this.hovering = false;
			setTimeout( "Dropdown.hideMenu()", 500 );
		}
	}
	if (menuElem) {
		menuElem.menu = menu;
		menuElem.hovering = false;
		menuElem.onmouseover = function () {
			this.hovering = true;
		}
		menuElem.onmouseout = function () {
			this.hovering = false;
			setTimeout( "Dropdown.hideMenu()", 500 );
		}
	}
}
Dropdown.hideMenu = function () {
	if (Dropdown.currentMenu) {
		if ( (Dropdown.currentMenu.hoverElem.hovering == false) && (Dropdown.currentMenu.menuElem.hovering == false) ) {
			Dropdown.currentMenu.hide();
			Dropdown.currentMenu = null;
		}
	}
}


//--------------------------------------------------------------------------------------------------
// ROTATOR
//--------------------------------------------------------------------------------------------------


var RotatorSlide = function (id, html) {
	this.id = ( id ? id : Helpers.generateId() );
	this.index = null;
	this.html = ( html ? html : '' );
	this.setHTML = function ( html ) {
		this.html = html;
	}
}
var RotatorSet = function (id) {
	this.id = id;
	this.slides = new Array;
	this.addSlide = function (slideId, slideHTML, index ) {
		var slide = new RotatorSlide( slideId, slideHTML );
		if ( index ) {
			this.slides = Helpers.insertArrayItem( this.slides, slide, index );
		} else {
			this.slides.push( slide );
		}
		if (this.activeSlideIndex == -1) {
			this.activeSlideIndex = 0;
		}
		slide.index = this.slides.length - 1;
		return slide;
	}
	this.setActiveSlideById = function ( id ) {
		var slide = this.getSlideById( id );
		if (slide) {
			this.activeSlideIndex = slide.index;
			this.setActiveSlideByIndex( slide.index );
		}
	}
	this.getSlideById = function ( id ) {
		for (var i=0; i < this.slides.length; i++ ) {
			if (this.slides[i].id == id) {
				return this.slides[i];
			}
		}
	}
	this.setActiveSlideByIndex = function ( i ) {
		var slide = this.getSlideByIndex( i );
		if (slide) {
			this.activeSlideIndex = slide.index;
		}
		if (this.statusRendered == true) {
			this.render();
		}
	}
	this.getSlideByIndex = function ( i ) {
		return this.slides[i];
	}
	this.renderControls = function (asOutput) {
		if (this.statusControlImagesLoaded==false) {
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-circle.gif');
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-circle-filled.gif');
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-left.gif');
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-left-disabled.gif');
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-right.gif');
			Helpers.preloadImage('http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-right-disabled.gif');
			this.statusControlImagesLoaded = true;
		}
		var circles = '';
		for (var i=0; i < this.slides.length; i++ ){
			var circleType = ( i == this.activeSlideIndex ? '-filled' : '' );
			circles += '<img src="http://chronicle.augusta.com/images/v4.5/2009/rotator-circle'+circleType+'.gif" style="cursor:pointer;margin-right:4px" onmouseup="Rotator.gotoSlide(\''+this.id+'\','+i+')" />';
		}
		var html = '<div style="float:left;" class="rotator-circles" id="rotator-circles-'+this.id+'">' + circles + '</div>';
		var leftClass = ( this.activeSlideIndex == 0 ? '-disabled' : '' );
		var rightClass = ( this.activeSlideIndex == this.slides.length - 1 ? '-disabled' : '' );
		var leftStyle = ( this.activeSlideIndex == 0 ? ';cursor:pointer' : ';cursor:pointer' );
		var rightStyle = ( this.activeSlideIndex == this.slides.length - 1 ? ';cursor:pointer' : ';cursor:pointer' );
		html +=  '<div style="float:right;" class="rotator-arrows" id="rotator-arrows-'+this.id+'"><img src="http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-left'+leftClass+'.gif"  width="16" height="17" style="'+leftStyle+'" onmouseup="Rotator.previousSlide(\''+this.id+'\')" /><img src="http://chronicle.augusta.com/images/v4.5/2009/rotator-arrow-right'+rightClass+'.gif" width="16" height="17" style="margin-left:6px'+rightStyle+'" onmouseup="Rotator.nextSlide(\''+this.id+'\')" /></div>';
		html += '<div style="clear:both;_height:1px;overflow:hidden"></div>';
		if (asOutput==true)	{
			return html;
		} else {
			this.rotatorControls.innerHTML = html;
		}
	}
	this.render = function ( params ) {
		params = ( params ? params : new Object );
		if (this.statusInitialized==false){
			this.init();
		}
		if (this.statusInitialized==true){
			if ( this.maxContentHeight == 0 ) {
				if (params.contentHeight) {
					this.maxContentHeight = params.contentHeight;
				} else {
					this.maxContentHeight = Helpers.getMaxContentHeight(this.slides, 'block');
				}
			}
//			this.renderControls();
			var html = '<div onmouseover="Rotator.startHover(\''+this.id+'\');" onmouseout="Rotator.stopHover(\''+this.id+'\');" style="height:'+this.maxContentHeight+'px">' + this.slides[this.activeSlideIndex].html + '</div>';
			html += '<div onmouseover="Rotator.startHover(\''+this.id+'\');" onmouseout="Rotator.stopHover(\''+this.id+'\');" id="rotator-controls-'+this.id+'" class="rotator-controls">' + this.renderControls(true) + '</div>';
			this.rotatorContainer.innerHTML = html;
			this.statusRendered = true;
		}
	}
	this.renderInTabBox = function ( boxId, paneId ) {
		if ( this.maxContentHeight == 0 ) {
			this.maxContentHeight = Helpers.getMaxContentHeight(this.slides, 'block');
		}
		var box = TabBox.getBoxById(boxId);
		var pane = box.getPaneById(paneId);
		var html = '<div onmouseover="Rotator.startHover(\''+this.id+'\');" onmouseout="Rotator.stopHover(\''+this.id+'\');" style="height:'+this.maxContentHeight+'px">' + this.slides[this.activeSlideIndex].html + '</div>';
		html += '<div onmouseover="Rotator.startHover(\''+this.id+'\');" onmouseout="Rotator.stopHover(\''+this.id+'\');" id="rotator-controls-'+this.id+'" class="rotator-controls">' + this.renderControls(true) + '</div>';
		pane.setHTML( html );
		pane.hasRotator = true;
		pane.rotatorSet = this;
		box.render();
		this.tabBox = box;
		this.tabBoxPane = pane;
	}
	this.injectAd = function ( adHTML ) {		
		var adIndex = Math.floor(Math.random() * ( this.slides.length - 1 ));
		adHTML = ( adHTML ? adHTML : '' );
		var html = '<div class="container" style="margin:0 0 0 8px;" ><div style="background:#a3a3a3 url(http://chronicle.augusta.com/images/v4.5/2009/spotlight-ad-label.gif) no-repeat;width:349px;margin:8px 0 0 0;height:155px;overflow:hidden;"><div style="background-color:#fff;width:328px;height:155px;margin:0 0 0 21px;">'+adHTML+'</div></div></div>';
		this.addSlide( 'spotlight-ad-slide', html, adIndex );
		
	}
	this.init = function () {
		this.rotatorContainer = document.getElementById('rotator-container-'+this.id);
		this.rotatorControls = document.getElementById('rotator-controls-'+this.id);
		if ( this.rotatorContainer ){
			this.statusInitialized = true;
		}
	}
	this.nextSlide = function () {
		var i = this.activeSlideIndex + 1;
		i = ( i < this.slides.length ? i : 0 );
		this.activeSlideIndex = i;
		if (this.tabBox){
			this.renderInTabBox(this.tabBox.id, this.tabBoxPane.id);
		} else {
			this.render();
		}
	}
	this.previousSlide = function () {
		var i = this.activeSlideIndex - 1;
		i = ( i >= 0 ? i : this.slides.length - 1 );
		this.activeSlideIndex = i;
		if (this.tabBox){
			this.renderInTabBox(this.tabBox.id, this.tabBoxPane.id);
		} else {
			this.render();
		}
	}
	this.gotoSlide = function (slideIndex) {
		if ( (slideIndex >= 0) && (slideIndex < this.slides.length) ) {
			this.activeSlideIndex = slideIndex;
			this.renderInTabBox(this.tabBox.id, this.tabBoxPane.id);
		}
	}
	this.startRotate = function ( ms ) {
		ms = ( ms > 0 ? ms : 7500 );
		this.rotateIntervalId = setInterval("Rotator.nextSlide('"+this.id+"',true)", ms);
		this.rotating = true;
		this.rotateFrequency = ms;
	}
	this.stopRotate = function () {
		clearInterval(this.rotateIntervalId);
		this.rotating = false;
	}
	this.activeSlideIndex = -1;
	this.statusRendered = false;
	this.statusInitialized = false;
	this.statusControlImagesLoaded = false;
	this.maxContentHeight = 0;
	this.hovering = false;
	this.rotating = false;
	this.visible = true;
}

var Rotator = new Object;
Rotator.sets = new Array;
Rotator.addSet= function (id) {
	var set = new RotatorSet(id);
	this.sets.push( set );
	return set;
}
Rotator.getSetById = function (id) {
	for (var i=0; i < this.sets.length; i++ ) {
		if (this.sets[i].id == id) {
			return this.sets[i];
		}
	}
}
Rotator.parseContent = function (setId) {
	var rotatorDiv = document.getElementById('rotator-content-'+setId);
	var slideDivs = ( rotatorDiv ? Helpers.getElementsByClass('rotator-slide',rotatorDiv,'div') : [] );
	var rSet;
	if (slideDivs.length > 0) {
		rSet = Rotator.addSet(setId);
		for (var i=0; i < slideDivs.length; i++) {
			var slideId = Helpers.generateId();
			slideHTML = slideDivs[i].innerHTML;
			if ( slideHTML ) {
				rSet.addSlide( slideId, slideHTML );
			}
		}
		rotatorDiv.innerHTML = '';
		return rSet;
	}
	return null;
}
Rotator.nextSlide = function (setId, auto) {
	var rSet = Rotator.getSetById(setId);
	if (auto != true) {
		rSet.stopRotate();
		rSet.nextSlide();
		rSet.startRotate(rSet.rotateFrequency);
	} else if ( rSet.hovering == false ) {
		if (rSet.visible==true) {
			rSet.nextSlide();
		}
	}
}
Rotator.previousSlide = function (setId) {
	var rSet = Rotator.getSetById(setId);
	rSet.stopRotate();
	rSet.previousSlide();
	rSet.startRotate(rSet.rotateFrequency);
}
Rotator.gotoSlide = function (setId, slideIndex) {
	var rSet = Rotator.getSetById(setId);
	rSet.gotoSlide(slideIndex);
}
Rotator.startHover = function (setId) {
	var rSet = Rotator.getSetById(setId);
	rSet.hovering = true;
}
Rotator.stopHover = function (setId) {
	var rSet = Rotator.getSetById(setId);
	rSet.hovering = false;
}


//--------------------------------------------------------------------------------------------------
// EMBED
//--------------------------------------------------------------------------------------------------

var Video = new Object;
Video.embed = function ( params ) {
	params.type = ( params.type ? params.type : 'ac' );
	if (params.type == 'ac') {
		var defaultPlayerHeight = ( params.height ? params.height : 90 );
		params.id = ( params.id > 0 ? params.id : 0 );
		params.autoPlay = ( params.autoPlay == true ? params.autoPlay = true : params.autoPlay = false );
		params.autoBuffer = ( params.autoBuffer == false ? params.autoBuffer = false : params.autoBuffer = true );
//		params.height = ( params.height > 0 ? (params.height + 33) : defaultPlayerHeight );
//		document.getElementById(params.containerId).style.height = params.height + 'px';
		document.getElementById(params.containerId).style.height = defaultPlayerHeight + 'px';
		var so = new SWFObject('http://chronicle.augusta.com/images/v4.5/2009/vidplayer.swf?x=13', 'vidplayer', '100%', '100%', '8', '#CCCCCC');
		so.addVariable('id', params.id);
		so.addVariable('videoResizeMode', 'fullCrop');
		so.addVariable('resizeMovieHeight', 'true');
		so.addVariable('autoPlay', params.autoPlay);
		so.addVariable('autoBuffer', params.autoBuffer);
		so.addVariable('playerVolume', 100);
		so.addVariable('containerId', params.containerId);
		so.addParam('allowFullScreen','true');
		so.addParam("allowScriptAccess", "always");
		so.addParam("wmode", "transparent");
		so.useExpressInstall('http://apps.augusta.com/DEV/jonathan/video/expressinstall.swf');
		so.write(params.containerId);
		document.getElementById(params.containerId).style.display = 'block';
	 }
}


//--------------------------------------------------------------------------------------------------
// TOP JOB
//--------------------------------------------------------------------------------------------------

var Jobs = new Object;

Jobs.init = function ( params ) {
	params = ( typeof params == 'object' ? params : new Object );
	Jobs.container = ( typeof params.container == 'string' ? $(params.container) : params.container );
	Jobs.jobs = new Array;
	Jobs.itemsPerSet = 3;
}

Jobs.load = function () {
	new Ajax.Request('http://chronicle.augusta.com/includes/v4/unflattened/jobshome.html', {
		method: 'get',
		onSuccess: function(transport, json){
			Jobs.handleLoad(transport);
		}
	});
}

Jobs.getRandomSet = function ( count ) {
	var output = new Array;
	for (var i=0; i < count; i++ ) {
		var r = Math.floor(Math.random() * Jobs.jobs.length);
		output.push( Jobs.jobs[r] );
	}
	return output;
}

Jobs.handleLoad = function (transport) {
	if (Jobs.container) {
		var text = transport.responseText;
		var re = /<td valign\=\"top\">/;
		var a = re.exec( text );
		text = text.substr( a.index + 18 );
		re = /<\/td>/;
		a = re.exec( text );
		text = text.substr( 0, a.index );
		//Change color of links
		text = text.replace( /<a /g, "<a class=\"top-job-more-link\" style=\"color:#000;\" " );
		text = text.replace( /\(Click here for more\)/gi, 'click for more' );
		//Create jobs Array
		Jobs.jobs = text.split( "<br><br>" );
		var html = '';
		var jobset = Jobs.getRandomSet( Jobs.itemsPerSet );
		for (var i=0; i < jobset.length; i++ ) {
			var divClass = '';
			if ((i==jobset.length - 1)) {
				divClass += ' last';
			}
			html += '<div class="top-job'+divClass+'">' + jobset[i] + '</div>';
		}
		var jobsHeight = Helpers.getMaxContentHeight(html);
		Jobs.container.innerHTML = html;
	}
}


