(function($) {
	
	$.fn.rollOver = function() {
		$(this).each(function() {
			var self = $(this);
			var src = self.attr('src');
			var body = src.substr(0, src.lastIndexOf('.'));

			if (!body.match(/\_on$/)) {
				// Preload
				var over = src.replace(/(\.gif|\.jpg|\.png)/, '_on$1');
				var img = new Image();
				img.src = over;
				
				img.onload = function() {
					self.hover(function() {
						self.attr('src', over);
					}, function() {
						self.attr('src', src);
					});
				}
			}
		});
	};
	
	$.fn.adjustHeight = function() {
		$(this).each(function() {
			var self = $(this);
			var max = 0;
			
			$(this).children('li').each(function(i, obj) {
				if ($(obj).innerHeight() > max) max = $(obj).innerHeight();
			});
			$(this).children('li').css('height', max);
		});
	};
	
	$.fn.verticalCenter = function() {
		$(this).each(function() {
			$(this).css('margin-top', (($(this).parent().height() / 2) - ($(this).outerHeight() / 2)) + 'px');
		});
	};
	
	$(document).ready(function() {
		$('.rollOver').rollOver();
		$('.adjust').adjustHeight();
		$('.vCenter').verticalCenter();
		
		$('#new_item ul li:nth-child(3n+2)').css('margin', '0 10px 20px');
		$('#ranking ul li:nth-child(3n+2)').css('margin', '0 10px 20px');
		
		if ($.browser.msie && parseInt($.browser.version) == 6) {
			$('.aligncenter').parents('p').css('text-align', 'center');
		}
		
		$('.stripe>p:nth-child(2n)').addClass('even');
	});
})(jQuery);

