/*
	2011-Aug-09  dwl  tried to retrofit this furball to expect a class of indexTabMenu
						instead of an id (of which there can be only one!)
*/

$().ready(function() {

	/*
		homeContentLeftTabs furball
	*/

	$('#homeContentLeftTabs .tabBoxNav').find('a').removeAttr('href');

	/* tabBoxArea */
	$('#homeContentLeftTabs .tabBoxNav li:first a').addClass('on');
	$('#homeContentLeftTabs .tabBox').hide();
	$('#homeContentLeftTabs .tabBox01').show();

	$('#homeContentLeftTabs .tabBoxArea').each(function() {

		var thisArea = $(this);

//!		if($(thisArea).attr('id') == 'indexTabMenu'){
		if ($(thisArea).hasClass('indexTabMenu')) {
			true;
		} else {
			// tab max width
			var liMaxWidth = $(this).find('#homeContentLeftTabs .tabBoxNav').width() / 3 -32;
			$(this).find('#homeContentLeftTabs .tabBoxNav').find('li').find('a').each(function(){
				var liThisWidth = $(this).width();
				if(liThisWidth >= liMaxWidth){
					$(this).width(liMaxWidth);
				} else {
					$(this).width('auto');
				}
			});
			// tab max height
			$('#homeContentLeftTabs .tabBoxNav li a').height($('#homeContentLeftTabs .tabBoxNav li a').maxHeight());
		}

		// tab click [the hard way]
		$(this).find('.tabBoxNav').find('a').each(function(){

			var thisRel = $(this).attr('rel');
			var showBlock = '.tabBox' + thisRel;
			$(this).hover(
				function(){
					$(this).addClass('hover');
				},
				function(){
					$(this).removeClass('hover');
				}
			);

			$(this).one('click',function(){
				$(this).addClass('visited');
			});

			$(this).click(function(){
				$(thisArea)
					.find('.tabBoxNav')
						.find('a')
							.removeClass('on')
						.end()
					.end()
				.end();
				$(this).addClass('on');
				$('#homeContentLeftTabs .tabBox').hide();
				$(showBlock).show();

//!				if ($(thisArea).attr('id') == 'indexTabMenu'){
				if ($(thisArea).hasClass('indexTabMenu')) {
					$('#homeContentLeftTabs .tabBoxNav li a').removeClass('else');
					if(thisRel == 1) {
						$('li#tabPress').find('a').removeClass('else');
					}
					if(thisRel == 2) {
						$('li#tabLatest').find('a').addClass('else');
					}
					if(thisRel == 3) {
						$('li#tabPress').find('a').addClass('else');
					}
				}
			});
		});
	});		// each #homeContentLeftTabs .tabBoxArea



	/*
		homeContentRightTabs furball
	*/

	$('#homeContentRightTabs .tabBoxNav').find('a').removeAttr('href');

	/* tabBoxArea */
	$('#homeContentRightTabs .tabBoxNav li:first a').addClass('on');
	$('#homeContentRightTabs .tabBox').hide();
	$('#homeContentRightTabs .tabBox04').show();
	$('#homeContentRightTabs .tabBoxArea').each(function() {
		var thisArea = $(this);
//!		if($(thisArea).attr('id') == 'indexTabMenu'){
		if ($(thisArea).hasClass('indexTabMenu')) {
			true;
		} else {
			// tab max width
			var liMaxWidth = $(this).find('#homeContentRightTabs .tabBoxNav').width() / 3 -32;
			$(this).find('#homeContentRightTabs .tabBoxNav').find('li').find('a').each(function(){
				var liThisWidth = $(this).width();
				if(liThisWidth >= liMaxWidth){
					$(this).width(liMaxWidth);
				} else {
					$(this).width('auto');
				}
			});
			// tab max height
			$('#homeContentRightTabs .tabBoxNav li a').height($('#homeContentRightTabs .tabBoxNav li a').maxHeight());
		}

		// tab click
		$(this).find('.tabBoxNav').find('a').each(function(){
			var thisRel = $(this).attr('rel');
			var showBlock = '#homeContentRightTabs .tabBox' + thisRel;
			$(this).hover(
				function(){
					$(this).addClass('hover');
				},
				function(){
					$(this).removeClass('hover');
				}
			);
			$(this).one('click',function(){
				$(this).addClass('visited');
			});
			$(this).click(function(){
				$(thisArea)
					.find('.tabBoxNav')
						.find('a')
							.removeClass('on')
						.end()
					.end()
				.end();
				$(this).addClass('on');
				$('#homeContentRightTabs .tabBox').hide();
				$(showBlock).show();

//!				if($(thisArea).attr('id') == 'indexTabMenu'){
				if ($(thisArea).hasClass('indexTabMenu')) {
					$('#homeContentRightTabs .tabBoxNav li a').removeClass('else');
					if(thisRel == 1) {
						$('li#tabPress').find('a').removeClass('else');
					}
					if(thisRel == 2) {
						$('li#tabLatest').find('a').addClass('else');
					}
					if(thisRel == 3) {
						$('li#tabPress').find('a').addClass('else');
					}
				}
			});
		});
	});	// each #homeContentRightTabs .tabBoxArea
});
