$(function(){

	// This is how often the featured escorts rotate in seconds.
	var frequency = 3;
	
	
	/*
		
		This is the function that replaces the details of the featured-current div
		
	*/
	
	function select(object){
		
		// Get each bit of information from the featured escorts list li
                var href = object.find('a').attr('href');
		var image = object.find('.homepage-crop-featured').attr('style');
		var name = object.find('.name').text();
		var meta = object.find('.meta').text();
		var description = object.find('.description').text();
		
		// Put them into the featured-current div
                $("#featured-current .profile-link").attr('href', href);
                $("#featured-current #profile").attr('href', href);
		$('#featured-current .homepage-crop-featured').attr('style',image);
		$('#featured-current .name').html('<h3>'+name+'</h3>');
		$('#featured-current .meta').text(meta);
		$('#featured-current .description').text(description);
		$('#featured-current #profile_button').attr('href', href);

		// Redraw cufon font's
		Cufon.replace('h3');
		Cufon.replace('#featured-current .meta');
		
	}
	
	
	/*
		
		This handles the act of hovering over an li in the featured list.
		It handles both the act of hovering, and the act of unhovering.
		
	*/
$('#featured-current').hover(function(){
	clearInterval(rotation_timer);
},function(){
	rotation_timer = setInterval(function(){rotate();},frequency*1000);
});

	$('#featured ul.list li a').hover(function(){
		
		// stop the rotation timer while we are hovered over an item
		clearInterval(rotation_timer);
		
		// take away any artificial hover styling
		$('#featured ul.list li').removeClass('jquery_hovered');
		
		// replace the information to the featured-current div
		select($(this));
		$(this).parent().addClass('jquery_hovered');
		
	},function(){
		
		// restart the rotation timer again after the hover is over
		rotation_timer = setInterval(function(){rotate();},frequency*1000);
		
		// re add artificial hover styling
		//rotation_current.addClass('jquery_hovered');
		
	});
	
	
	/*
		
		This function handles the act of moving from one list item to the next,
		thus creating rotation.
		
	*/
	
	// set the first rotation item (rotation_current) as the first in the list
	var rotation_current = $('#featured ul.list li:first');
	
	// set the artificial hover style on the rotation_current, and select it.
	rotation_current.addClass('jquery_hovered');
	select(rotation_current);
	
	function rotate(){
		
		// this bit of code handles going back to the top of the list once the bottom is hit
		if(rotation_current.find('.name').text() == $('#featured ul.list li:last .name').text()){
			rotation_current = $('#featured ul.list li:first');
		}else{
			rotation_current = rotation_current.next('li');
		}
		
		// clear any existing artificial hover styling
		$('#featured ul.list li').removeClass('jquery_hovered');
		
		// set the current item's styling so it mimicks a mouse hover
		rotation_current.addClass('jquery_hovered');		
		select(rotation_current);
	}
	
	// this is the timer that causes the rotation
	var rotation_timer = setInterval(function(){rotate();},frequency*1000);
	
});

$('.homepage-crop-featured img').each(function(){
		if($(this).height() > 304){
			$(this).css('top','-25%');
		}
	});
