$(document).ready(function() {
	// Image captions
	$('span.img').each(function(i,n) {
		var width = $(this).children('img').attr('width');
		$(this).css('width', width);
	});
	
	// Equipment type sidebar navigation
	$('#types a.top').click(function(event) {
		event.preventDefault();
		$(this).siblings('ul').toggle();
	});
	
	// Manufacturer alphabet navigation
	$('#alpha-nav a').click(function(event) {
		if ($(this).attr('class') != 'all') {
			event.preventDefault();
			var letter = $(this).attr('href').match(/\/([a-z])\//)[1];
			$('#manufacturers').load('/index.php/products/ajax/'+letter, function(response, status, request) {
				$('#manufacturers').empty().html(response);
			});
		}
	});
	
	// Handle external links
	$('a').click(function(event) {
		if ( $(this).attr("href") && $(this).attr("href").substr( 0,4 ) == "http" && $(this).attr("href").search("treatmentequipment.com") == -1 ) {
    		window.open(this.href);
			return false;
    	}
	});
	
	// Handle external links 2
	$("a[@rel=external]").click(function(event) {
		window.open(this.href);
		return false;
	});
	
	// Search field
	$('#keywords').focus(function() {
		$(this).val('');
	});
	
	$('#keywords').blur(function() {
		var val = ( $(this).val() != '' ) ? $(this).val() : 'Search';
		$(this).val(val);
	});
});