(function($) {
	GS.extend('homepage', function() {
		
		// Slide down project text
		$('.shotview').mouseenter(function() {
			$(this).find('.feature-drop').fadeIn('fast');
		});
		$('.shotview').mouseleave(function() {
			$(this).find('.feature-drop').fadeOut('fast');
		});
		$('.feature-drop').mouseenter(function () {
			$(this).show();
		});

		new GS.carousel(GS.CAROUSEL);

		new GS.MemberCounter($('#memberCounter'));
	});

	GS.extend('MemberCounter', function($tie, $speed) {
		var tie = $tie,
			count = tie.html(),
			speed = $speed || 10000,
			nums = [],
			height = 0;

		function Init() {
			$('.gsStatus').addClass('counting');
			// ok make the count a number
			count = parseInt(count.replace(/,/g, ''));
			// construct the crazy html
			BuildHTML();
			HandleRender();
			// now fire the tick
			setTimeout(HandleTick, Math.random()*speed);
		}

		function BuildHTML() {
			tie.empty();
			var commas = count.toString().length;
			for (var i = 0, length = commas; i < length; i++) {
				var html = '<span class="number">';
				for (var u = 0; u < 10; u++) {
					html += '<span class="item">'+u+'</span>';
				}
				html += '<span class="item">0</span>';
				var num = $(html+'</span>').appendTo(tie).css('top', 0);
				nums.push(num);
				if (commas % 3 == 1 && i+1 < length) {
					$('<span class="number comma">,</span>').appendTo(tie);
				}
				commas--;
				if (height == 0) {
					height = $('span:first-child', num).outerHeight();
				}
			}
		}

		function HandleRender() {
			var bits = count.toString().split('');
			for (var i = 0, length = bits.length; i < length; i++) {
				var position = 0-parseInt(bits[i])*height,
					end = false,
					top = parseInt(nums[i].css('top'));
				if (position == 0 && top != 0) {
					position = 0-(10*height);
					end = true;
				}
				if (position != top) {
					nums[i].data('end', end).animate({
						'top' : position
					}, {
						queue : false,
						duration : 200,
						easing : 'swing',
						complete : function() {
							var item = $(this);
							if (item.data('end')) {
								item.css('top', 0);
							}
						}
					});
				}
			}
		}

		function HandleTick() {
			// increment the count
			count++;
			// render
			HandleRender();
			// now fire the tick
			setTimeout(HandleTick, Math.random()*speed);
		}

		Init();
	});

})(jQuery);

