var c30site = {
	absUri : ''
};

if(Drupal.jsEnabled) {
  var fadeSpeed = 3000;
  var load = true;
  var rotateState = {
      current    : null,
      index      : 1,
      totalItems : 0,
      list       : null,
      interval   : 5,
      isPaused   : false
  };
	
$(document).ready(function() {
	  rotateState.totalItems = ($('#helpDetail .section').size()); 
	  rotateState.current    = $('#helpDetail .section:last-child');
	  rotateState.list       = $('#helpDetail .section');
	  setInterval(rotateImages, (rotateState.interval * 1200));
	  	
	  	//flash embed
		$('#flash_holder').flash({ 
			src: c30site.absUri + '/sites/all/themes/CarouselTHIRTY/flash/hbc-homepage-demo.swf',
			width: 951,
			height: 252,
			wmode: 'transparent',
			flashvars: {'pathToXML': c30site.absUri + '/sites/all/themes/CarouselTHIRTY/flash/HBCHomepageBanner.xml'}
		},
		{
			version: 8
		});
		
		
		/*
		 * Links Open In New Window
		*/
		$("a._blank[href^=]").click(
			function() {
				window.open(this.href);
				return false;
			}
		);

		
		$('.featureBlock').each(function(i){
			$(this).unbind('mouseenter mouseleave');
			$(this).hover(
					  function () {
					    $(this).children("p").addClass("hover");
					  },
					  function () {
					    $(this).children("p").removeClass("hover");
					  }
					);
		});
		
		//Drop-Down Script
		$("#nav > ul > li#about, #nav > ul > li#capabilities , #case_filter > ul > li").bind("mouseenter mouseleave", function(e) {
			// Stop event propagation so events don't stack.
			e.stopPropagation();
			$(this).toggleClass("menu-open");
			$(this).children("ul").toggle();
		});
		
		//gets the value of any input and removes it on focus and replaces it on blur if nothing is entered
		$('#search-text').focus(function(){
			var defaultText = $(this).val();
			$(this).val('');
			
			$("input").blur( function () {
			var userInput = $(this).val();
			
				if (userInput == ''){
					$(this).val(defaultText);
				}
			});
		
		});
		
		$(".case:first").css("background", "none");

// Frontpage Switching
		
		$("#helpDetail .section:first").addClass("active");
		
		$("#helpMenu ul:first li:first a").addClass("menu_first_link");

		$("#helpMenu ul li a").bind("mouseover", function(event) {
			
			
			rotateState.isPaused = true;
			
			var index = $("#helpMenu > ul > li a").index(this);
			
			rotateState.index = index+1;
			
			var time = event.timeStamp;
				
			// Remove sibling classes
			$("#helpDetail .section").siblings().fadeOut("fast").removeClass("active");
			// Set active class on link and associated div
			
			rotateState.current = $("#helpDetail .section").eq(index).fadeIn("fast").addClass("active");			
		});
		
		$("#helpMenu ul li a").bind("mouseout", function(event) {
			rotateState.isPaused = false;
		});
});


function rotateImages() {
	
	if (rotateState.isPaused) {
		return;
	}
	
	if (rotateState.index > rotateState.totalItems) {
		
		rotateState.index = 0;
		
	}else{
		
		rotateState.current.fadeOut(fadeSpeed).removeClass('active');

	}
	
	if(load){
		
	var temp = rotateState.current;
		
	rotateState.current = $(rotateState.list[0]);
	
	rotateState.current.fadeOut(fadeSpeed).removeClass('active');
	
	load = false;
	
	rotateState.current = temp;
	
	}
	
	var target = null;
	
		if(rotateState.index < 4){

			
				target = $(rotateState.list[rotateState.index]);
				
				rotateState.current.fadeOut(fadeSpeed).removeClass('active');
				
				target.fadeIn(fadeSpeed).addClass('active');
				
				rotateState.current=target;
				
		}else{
			
			target = $(rotateState.list[0]);
			
			target.fadeIn(fadeSpeed).addClass('active');
			
			rotateState.current=target;
			
			rotateState.index = 0;
			
		}
		
	rotateState.index++;
	
	}
}