$(function() {
	var fade_time = 600;
	var slideshow_block = $('#slideshow_rotation');
	
	slideshow_block.find('img:not(:first)').removeClass('hide').hide();
	
	window.setInterval(function(){
		current_img = slideshow_block.find('img:visible');
		next_img =  (current_img.is(':last-child')) ? slideshow_block.find('img:first') : current_img.next();
		current_img.fadeOut(fade_time);
		window.setTimeout(function(){next_img.fadeIn(fade_time);}, (fade_time+10));
	}, 7000);

	/* homepage brand bar hovers */

	$("#home_brands").children("li").each(function() {
		var current = "active";
		var parentClass = $(this).attr('class');
		var thisClass = $(this).attr('id');
		$(this).children("a").css({backgroundImage:"none"});
		
		if (parentClass == current) {
			$(this).before('<div class="' + thisClass + '_active"></div>');
		}
		
	});
				
	$.each(['hb-aloft', 'hb-element', 'hb-four_points', 'hb-le_meridien', 'hb-luxury', 'hb-sheraton', 'hb-st_regis', 'hb-w_hotels', 'hb-westin'], function (i, val) {
		attachNavEvents("#home_brands", val);	
	});
	
	function hoverOver() {
		myClass = $(this).attr('id');
		$(this).before('<div class="' + myClass + '"></div>');
		$("div." + myClass).css({display:"none"}).fadeIn(500);
	}
	
	function hoverOut() {
		myClass = $(this).attr('id');
		
		$("div." + myClass).fadeOut(500, function() {
			$(this).remove();
		});
		
	}
			
	function attachNavEvents(parent, myID) {
	
		var config = {    
			 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 20, // number = milliseconds for onMouseOver polling interval    
			 over: hoverOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 0, // number = milliseconds delay before onMouseOut    
			 out: hoverOut // function = onMouseOut callback (REQUIRED)    
		};
		
		$(parent + " #" + myID).hoverIntent(config); 
		
	}
});