$('HTML').addClass('JS');

$.extend({
	switch_tabs: function(obj){
		$('.tab-content').hide();
		$('.tabs a').removeClass("selected");
		var id = obj.attr("id");
		$('#'+id+'-content').show();
		//$('#'+id+'-content h3').hide();
		obj.addClass("selected");
	}
});

$(document).ready(function() {
	$('.tabs a').click(function(){
		$.switch_tabs($(this));
		return false;
	});
	$.switch_tabs($('.defaulttab'));
	// add currency links
	var topID = '<div id="currencyTop" ';
	var bottomID = '<div id="currencyBottom" ';
	var currencyLinks = 'class="currencyLinks"><h4>Select Currency</h4>' + 
	'<ul><li><a class="nz" href="#">NZ dollars</a></li>' +
	'<li><a class="us" href="#">US dollars</a></li>' +
	'<li><a class="aus" href="#">AUS dollars</a></li></ul>' +
	'</div>';
	var currencyLinksTop = topID + currencyLinks;
	var currencyLinksBottom = bottomID + currencyLinks;
	
	$('div#tab1-content h3').first().before(currencyLinksTop);
	$('div#tab2-content h3').first().before(currencyLinksTop);
	$('div.tab-content').append(currencyLinksBottom);
	
	var nz = $('table.rates td:nth-child(2)')
				.add('table.rates th:nth-child(2)')
				.add('table.rates td:nth-child(5)')
				.add('table.rates th:nth-child(5)')
				.add('table.rates td:nth-child(8)')
				.add('table.rates th:nth-child(8)');
	var us = $('table.rates td:nth-child(3)')
				.add('table.rates th:nth-child(3)')
				.add('table.rates td:nth-child(6)')
				.add('table.rates th:nth-child(6)')
				.add('table.rates td:nth-child(9)')
				.add('table.rates th:nth-child(9)');
	var aus = $('table.rates td:nth-child(4)')
				.add('table.rates th:nth-child(4)')
				.add('table.rates td:nth-child(7)')
				.add('table.rates th:nth-child(7)')
				.add('table.rates td:nth-child(10)')
				.add('table.rates th:nth-child(10)');
	// hide $US and $AUS by default
	us.hide();
	aus.hide();
	$('a.nz').click(function() {
        us.hide();
		aus.hide();
		nz.show();
		return false;
    });
	$('a.us').click(function() {
        us.show();
		nz.hide();
		aus.hide();
		return false;
    });
	$('a.aus').click(function() {
        aus.show();
		nz.hide();
		us.hide();
		return false;
    });

});