(function($){
	EYE.farmers = function () {
		var click = function (ev) {
			var targetEl = $(ev.target).closest('tr.farmerSummary').find('a');
			if (targetEl.is('a')) {
				var state = targetEl.closest('tr').toggleClass('active').next().toggleClass('hiddenElement').is('.hiddenElement');
				targetEl.blur()
					.find('img')
						.attr('src', state ? '/images/icon_expand.gif' : '/images/icon_collapse.gif');
				return false;
			}
		};
		return {
			init: function() {
				$('#farmersList').bind('click', click);
			}
		};
	}();
	EYE.register(EYE.farmers.init);

	EYE.suppliersCarousel = function()
	{
		var current = -1, total;
		var switchLogo = function() {
			var nextCurrent = current + 1;
			if (nextCurrent >= total) {
				nextCurrent = 0;
			}
			$('#suppliersCarousel img')
				.eq(current).stop().animate({opacity: 0}, 500).end()
				.eq(nextCurrent).stop().animate({opacity: 1}, 500);
			current = nextCurrent;
			setTimeout(switchLogo, 3000);
		};
		return {
			init: function() {
				if (document.getElementById('suppliersCarousel')) {
					total = $('#suppliersCarousel')
								.prepend('<p id="suppliersCarouselContnet" />')
								.find('img').appendTo('#suppliersCarouselContnet')
									.css('opacity', 0).size();
					switchLogo();
				}
			}
		};
	}();
	EYE.register(EYE.suppliersCarousel.init);
	EYE.register(function(){
		$('#calculator').calculator();
	});

	EYE.registration = function() {
		var changeEv = function() {
			$('#accountcompany_kind_other')
				.css(
					'display',
					this.value == 'anders' ? 'inline' : 'none'
				);
		};
		return {
			init: function() {
				if (document.getElementById('registrationForm')) {
					$('#accountcompany_kind').bind('change', changeEv).trigger('change');
				}
			}
		};
	}();
	EYE.register(EYE.registration.init);
})(jQuery);
