$(document).ready(function(){

	
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(500, 1);
	  }, function () {
	    $span.stop().fadeTo(500, 0);
	  });
	});
	
/////////////////////////////////////////////////////////////////////////////	
	startPos = $("#navBtns ul li a.active").position().left + 4;
        $(".grnArrow").stop().animate({
            left: startPos
		});
	///above sets start position when page loads	
		
    function grnOn() { //on hover move slider to hover element's position


        $(".grnArrow").stop().animate({ 
            left: leftPos //animate arrow to the leftPos
		});
	  };
	function grnOff() { //on mouseout, return to start position
        $(".grnArrow").stop().animate({
            left: startPos
		});
   
    };




	
	
	
	
	////////////makes button not interfere with sliding
	$(".grnArrow").hover(function() { //on hover move slider to hover element's position

		leftPos = $(this).position().left + 4;
        $(".grnArrow").stop().animate({
            //left: activePos
		});
	  }, function () {
        $(".grnArrow").stop().animate({
            //left: activePos
		});
   
    });
	//////////////////////////////////////////////////
	
	
		

	
 ////////////////////////////////////////////////////////menu//////////////////////////
	function megaHoverOver(){
		$(this).find(".sub2").stop().fadeTo('fast', 1).show(grnOn);
		leftPos = $(this).position().left + 4; //get position plus 4px
		activePos = $(this).position().left;
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub2").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	  
        $(".grnArrow").stop().animate({
            left: startPos
		});
	}
 
 
	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	$("ul#topNav li .sub2").css({'opacity':'0'});
	$("ul#topNav li .sub2").css({'display':'none'});
	$("ul#topNav li").hoverIntent(config);
 
 
 
  ////////////////////////////////////////////////////////solution menu//////////////////////////

	function megaHoverOverSol(){
		left2 =	$(this).position().left;
		top2 = $(this).position().top;
		
		$(this).find(".solutions").css('left', left2 + 2);
		$(this).find(".solutions").css('top', top2 + 126);
		$(this).find(".solutions").stop().fadeTo('fast', 1).show();
		$(this).find(".btn").addClass("active");
	}
	
	function megaHoverOutSol(){ 
	  $(this).find(".solutions").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	   $(this).find(".solutions").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	  $(this).find(".btn").removeClass("active");
	}
 
 
	var configSol = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 20, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOverSol, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOutSol // function = onMouseOut callback (REQUIRED)    
	};
 
	$(".solutionBox .solutions").css({'opacity':'0'});
	$(".solutionBox .solutions").css({'display':'none'});
	$(".solutionBox").hoverIntent(configSol);
 
 
});
 
 function processSlideshow(elem, imageList, imageDuration, fadeSpeed, current) 
{
	var listSize = imageList.length;
    if (!current || current >= listSize) current = 0;
    if (!imageDuration) imageDuration = 2000;
    if (!fadeSpeed) fadeSpeed = 1000;
    $(elem + " img").attr("src", imageList[current]);
    if (current == (listSize - 1)) { $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
    } else {
        $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
    }
    $(elem + " img").animate({ opacity: "1" }, imageDuration).
	      animate({ opacity: "0.01" }, fadeSpeed, function() 
		   { 
		     $(this).css("opacity", "1"); processSlideshow(elem, imageList, imageDuration, fadeSpeed, current + 1) 
			});

} 





	
	

