//-------------------------------
// Makes Div equal the same height
//-------------------------------
$.fn.equalCols = function() {
	// Array Sorter
	var sortNumber = function(a,b) {return b - a;},
		heights = [];
	// Push each height into an array
	$(this).each(function() {
		heights.push( $(this).height() );
	});
	heights.sort(sortNumber);
	var maxHeight = heights[0];
	return this.each(function() {
		// Set each column to the max height
		$(this).css({'height': maxHeight + 10});
	});
};

//-------------------------------
// Moves form label to the input
//-------------------------------
$.fn.labelHolder = function() {
	return this.each(function() {
		var holder = $(this).find('label').hide().text(),
			field = $(this).find('input');
		field.blur(function() {
			if ( $(this).val() == '' || $(this).val() == holder ) {
				$(this).val(holder).addClass('holder');
			}
		}).blur();
		field.focus(function() {
			if ( $(this).val() == holder ) {
				$(this).val('').removeClass('holder');
			}
		});
	});
};

//-------------------------------
// Marks the correct cat nav when viewing product
//-------------------------------
function checkProductSubnav() {
	var path = location.pathname;
	if (path.match(/_product_/)) {
		$('#navsub_509510_254083').show();
		var cat = path.split('/')[1].split('_')[2];
		$('#nav_509510 a').each(function() {
			if (this.href.match(cat) || this.href.match(/\/products\//)) {
				$(this).parent().addClass('selected');
			}
		});
	}
}

$(function() {
	$('.validate').validate();
	$('#extra').find('form fieldset div').labelHolder();
	$('#latestnews li:even').addClass('alt');
	$('.email').defuscate();
	checkProductSubnav();
});

$(window).load(function() { // needs to wait for images to load
	$('.products .item').equalCols();	
});
