// JavaScript Document

$(function() {
		
	$('.hero').cycle({fx: 'fade', before: onBeforeSlide, after: onAfterSlide, timeout: 5000,next:'.heroNext',prev:'.heroPrev'});
	
	$('.heroNext').click(function(evt) {
		$('.hero').cycle('pause');
		$('.heroPause').addClass('paused').attr('title','Play');
	});
	
	$('.heroPrev').click(function(evt) {
		$('.hero').cycle('pause');
		$('.heroPause').addClass('paused').attr('title','Play');
	});
	
	
	$('.heroPause').click(function(evt) {
		if($(this).hasClass('paused')) {
			$('.hero').cycle('resume');	
			$(this).removeClass('paused').attr('title','Pause');
		}
		else {
			$('.hero').cycle('pause');	
			$(this).addClass('paused').attr('title','Play');
		}	
	});
	
	function onBeforeSlide(currSlideElement, nextSlideElement, options, forwardFlag) 
	{
		
		/*$('.homeCaption').stop().fadeOut("fast", function() {
			var $alt = $(nextSlideElement).attr('alt');			
			$(this).find('.innerHomeCaption').html($alt);
		});*/
		
		var $alt = $(nextSlideElement).attr('alt');			
		// $('.homeCaption').hide().find('.innerHomeCaption').html($alt);
		$('.homeCaption').find('.innerHomeCaption').html($alt)
		
	}
		
	function onAfterSlide(currSlideElement, nextSlideElement, options, forwardFlag) 
	{
	
		if($('.homeCaption .innerHomeCaption').html() != '') {
			
			$('#heroRef input').each(function(i) { 
				if($(this).attr('class') == $(nextSlideElement).attr('class')) {
					var myHref = '/' + $(this).val();
					$('.homeCaption a').attr('href', myHref);
					$('.hero img').css({'cursor':'pointer'}).click(function() { window.location = myHref; });
					return false;
				}
			});

			/*$('.homeCaption')
			.stop()
			.fadeIn("slow", function() {
				
			});
		*/
		
			// $('.homeCaption').show();
		
		}
	
	}
	
});