
$(document).ready(function(){


////////////////////////////////////////////////fade btns
	$('.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 () {
		  if ($(this).hasClass('.active')){
		  } else{
			$span.stop().fadeTo(500, 0); 
		  }
	  }); 
	});

	
 ////////////////////////////////////////////////////////menu//////////////////////////
	function megaHoverOver(){
		//var ah = $(this).css('left'); //grab left of current LI hoverd
		var ah2 = $(this).find(".sub2").height(); //grab height of submenu
		
		//$(this).find(".sub2").css('top', 41);
		$(this).find("#mDivider").css('height', ah2); //adjust main divider to submenu's height
		//$(this).find(".sub2").css('left', ah); //adjust submenu's left position to current LI
		$(this).find(".sub2").stop().fadeTo('fast', 1).show()
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub2").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });

	}
 
 
	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);
 
	
	
});

 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) 
			});

} 

