var fadetime = 250;
var slidetime = 750;
var rotatetime = 2000;
var tabwidth = 88;
var totalwidth = 941;
var slidenames =['agriculture', 'construction', 'energy', 'manufacturing', 'service', 'public', 'transportation'];
var slides = [];
var slidecount = slidenames.length;
var slidewidth = 0;
var banner = -1

function bannersetup(){
 var hsedit = ($('div#hsnav').length > 0)? true : false;

 banner = $('div#banner');
 for(var i in slidenames){
  var slide = $('div#banner > div#' + slidenames[i])
  slides.push(slide);
  var r = tabwidth * (slidecount - slides.length)
  slide.css({'right' : r + 'px', 'z-index' : slidecount - slides.length}); 
  if(!hsedit){
   slide.click(show)
   slide.mouseover(show)
  }
 }
 slidewidth = slides[0].width()
 if(!hsedit){
  banner.mouseover(bannerstop)
  banner.mouseout(bannergo)
  banneradvance();
  bannergo()
 }

}

var $shown = -1;
var bannertimer = false;
function bannergo(){
  bannertimer = setInterval(banneradvance, rotatetime)
}
function bannerstop(){
  if(bannertimer) clearInterval(bannertimer);
}
function banneradvance(){
  if($shown == -1){
    slides[0].click()
  }else{
    if($shown.nextAll().length == 0){
	  slides[0].click()
	}else{
	  $shown.next().click()
	}
  }
}

function show(){
 $this = $(this);
 if($shown != -1){
  if($shown.is($this)) return;
  $('div.bg.color', $shown).stop(true, true).fadeOut(fadetime);
  $('div.text', $shown).stop(true, true).fadeOut(fadetime);
 }
 
 var title = $('h2', $this).text()
 var before = $this.prevAll() 
 var after = $this.nextAll()
 var which = before.length;
 
 before.each(function(){
  var $this = $(this)
  var which = $this.prevAll().length
  var right = ((slidecount - which - 2) * tabwidth) + slidewidth
  $this.stop(true).animate({'right' : right}, slidetime);  
 });

 var right = ((slidecount - which - 1) * tabwidth);
 $this.stop(true).animate({'right' : right}, slidetime);  
 
 after.each(function(){
  var $this = $(this)
  var which = $this.prevAll().length
  var right = ((slidecount - which -1) * tabwidth)
  $this.stop(true).animate({'right' : right}, slidetime);
 });
 
 var color = $('div.bg.color', $this)
 var text = $('div.text', $this)
 color.stop(true, true).fadeIn(fadetime);
 text.stop(true, true).fadeIn(fadetime);
 $shown = $this
}
