jQuery(function ($) {

	var $hero = $('div.hero');
	if($hero.length) {
		var $rw = $hero.find('.heronav_rew'),
			$ff = $hero.find('.heronav_ff'),
			//$cap = $hero.next('.hero_text'),
			$slides = $hero.find('.slide-image'),
			$last,

			timer,
			intrans = false,
			speed = 500,
			timeout = parseInt($hero.attr('data-timeout')) || 10000,
			hide = {opacity: 0},
			show = {opacity: 1};

		var swap = (function(inc) {
			return (function () {
				if(intrans) return;
				intrans = true;
				
				$slides = $hero.find('.slide-image');
				var index = $slides.index($last);
				index += $slides.length - inc;
				index %= $slides.length;
				var $curr = $slides.eq(index);

				/*
				$cap.children().fadeOut(speed/2, function () {
					$cap.html('<div>'+unescape($curr.attr('data-caption'))+'</div>');
					$cap.children().hide().fadeIn(speed/2);
				});
				*/
				$last.css(show).animate(hide, speed);
				$curr.css(hide).animate(show, speed, function () {
					$last.css(hide);
					$curr.css(show);
					intrans = false;
					$last = $curr;
				});
			});
		});

		var start = (function () {
			stop();
			timer = setInterval(swap(+1), timeout);
		});
		
		var stop = (function () {
			clearInterval(timer);
		});

		$rw.bind('click', swap(-1));
		$ff.bind('click', swap(+1));
		$rw.bind('click', stop);
		$ff.bind('click', stop);
		$hero.hover(stop, start);

		$slides.not(':last').css(hide)
		$last = $slides.filter(':last');

		$(start);
	}

	var $nl_box = $('input.newsl_box');
	if($nl_box.length) {
		$nl_box.focus(function(){
			if($nl_box.val()=='your email address') {
				$nl_box.val('').css('color','#222222');
			}
		}).blur(function(){
			if($nl_box.val()=='') {
				$nl_box.val('your email address').css('color','#999999');
			}
		});
	}

});
