$(function()
{
	// Main Banner.
	$('#homePageBannerContainer ul').cycle(
	{
		fx:      'fade',
		easing:  'easeinout', 
		speed:   500, 
		timeout: 5200,
		pager:   '#homePageBannerContainer .pagination', 
		pagerAnchorBuilder: function(idx, slide)
		{ 
			return '<a href="#" class="page"><img class="ie6png" src="images/hover/mainBannerPage.png" alt="*" /><!--[if lte IE 6]><img src="/images/blank.gif" alt="" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/hover/mainBannerPage.png\', sizingMethod=\'crop\'); width: 12px; height: 24px;" /><![endif]--></a>';
		}, 
		sync: true
	});
	
	// Start cycle plugin for find your rover machine.
	$('.findYourRover .filterGroups').cycle(
	{
		fx:      'scrollHorz',
		easing:  'easeinout', 
		speed:   ($.browser.msie && $.browser.version == '6.0') ? 500 : 500, 
		timeout: 0,
		pager:   $('.findYourRover .pagination'), 
		pagerAnchorBuilder: function(idx, slide)
		{ 
			return '<a href="#" class="page">*</a>';
		}, 
		sync: true, 
		after: function()
		{
			$(this).parents('.filterGroups').removeClass('cycling');
		}, 
		before: function()
		{
			$(this).parents('.filterGroups').addClass('cycling');
		}
	});
	
	// Go to second slide if option on slide 1 is elected.
	$('.findYourRover .formSection:first .radioItem input').click(function(e)
	{
		$('.findYourRover .pagination a:nth-child(2)').trigger('click');
	});
	
	// Fix to make hovers always on top.
	$('.formArea .popdown, .findYourRover .fieldLabel a').mouseenter(function()
	{
		$(this).parents('.formArea').addClass('hover hoverShow');
	});
	$('.formArea .popdown, .findYourRover .fieldLabel a').mouseleave(function()
	{
		var $affectedElements = $(this).parents('.formArea');
		$affectedElements.removeClass('hover');
		
		var t = setTimeout(function()
		{
			if(!$affectedElements.hasClass('hover')) {
				$affectedElements.removeClass('hoverShow');
			}
		}, 300);
	});
	
	// What's this tooltips.
	$('.findYourRover').addClass('cycling');
	$('.findYourRover .formSection').css(
	{
		visibility: 'hidden', 
		display: 'block'
	});
	$('.whatsThis.tooltipTrigger').each(function()
	{
		var position = $(this).position();
		var left = position.left + 55;
		
		var $target = $($(this).attr('href'));
		
		$target.css('left', left);
	});
	$('.findYourRover').removeClass('cycling');
	$('.findYourRover .formSection').css(
	{
		visibility: 'visible', 
		display: ''
	});
});
