
(function($){

	$(document).ready(function(){
		if (window.name == 'printWindow')
			return;
		initTab();
	});

	function initTab() {
		$('#tab > ul > li')
			.find('img').each(function(){
				// preload image & store data.
				var img = new Image();
				img.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_on$2');
				$(this).data('image', {
					defaultSrc: this.src,
					activeSrc: img.src
				});
			}).end()
			.click(function(){
				var index = $(this).parents('ul').children('li').index(this);
				switchTabTo(index);
				return false;
			});
		switchTabTo(0);
	}

	function switchTabTo(index) {
		// switch tab items.
		$('#tab > ul > li img').each(function(i){
			if (i == index)
				this.src = $(this).data('image').activeSrc;
			else
				this.src = $(this).data('image').defaultSrc;
		});

		// switch tab contents.
		$('#content01 div.tab-content:visible').hide();
		$('#content01 div.tab-content').eq(index).show();
	}

})(jQuery);

