/**
 * FIX IE6 IMAGE FLICKER PROBLEM
 *
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}



JCDA = {

	init: function() {
		
		Cufon.replace('#header ul.toolbar a', { fontFamily: 'Helvetica Neue', hover: true });
		Cufon.replace('#header ul.primary > li > a', { fontFamily: 'Helvetica Neue', hover: true });
		Cufon.replace('#header ul.secondary a', { fontFamily: 'HelveticaNeue Light', hover: true });

		Cufon.replace('#header ul.tools li.print, #header ul.tools li.share, #header ul.tools li.textsize span', { fontFamily: 'Helvetica Neue' });
		Cufon.replace('div.widget h3, #body div.authors h3, #body div.references h3', { fontFamily: 'Helvetica Neue' });
		Cufon.replace('div.widget.rss a', { fontFamily: 'Helvetica Neue' });
		Cufon.replace('div.widget.qanda big.q', { fontFamily: 'Helvetica Neue' });

		// Render primary navigation.
		this.primaryNavigation();

		// Check for presence of secondary navigation.
		if($('#header ul.secondary').children().size() == 0) {
			$('div.breadcrumb').addClass('solo');
		}

		this.photoCaptions();
		this.dataTables();
		
		var textSizeStatus = (title) ? title : 'small';
		$('div.breadcrumb .textsize a').removeClass('lit');
		$('div.breadcrumb .textsize a[rel="' + textSizeStatus  + '"]').addClass('lit');
		
		$('div.breadcrumb .textsize a').click(function() {
			setActiveStyleSheet($(this).attr('rel'));
			
			$('div.breadcrumb .textsize a').removeClass('lit');
			$(this).addClass('lit');
			
			JCDA.primaryNavigation();
			return false;
		});

	},

	primaryNavigation: function() {
		$('#header ul.primary ul').each(function() {
			$('li:last', this).addClass('last');
		});

		var priElemWidth = maxHeight = 0;
		var maxWidth = 156;

		$('#header ul.primary li a.top').each(function(){
			// Reset old values (if applicable).
			$(this).width('auto');
			$('span', this).height('auto');

			priElemWidth += $(this).width();
		});

		if(priElemWidth > 954) { 


			$('#header ul.primary li a.top').each(function() {
				if($(this).width() > 156) {
					$(this).width('156px');
				}
				maxHeight = ($(this).height() > maxHeight) ? $(this).height() : maxHeight;
			});
			$('#header ul.primary li a.top span').each(function() {
				$(this).height(maxHeight - 20 + 'px');
			});
		}
	},

	photoCaptions: function() {
		$('#body div.photo-and-caption').each(function() {
			var imgSize = $('img', this).width() - 30;
			$(this).width(imgSize + 'px');
		});
	},

	dataTables: function() {
		$('#body table').each(function() {
			// 'Zebra' strips on every odd row.
			$('tbody tr:odd').addClass('shade');

			// First and last columns require left/right border.
			$('tr', this).each(function() {
				$('th:first, td:first', this).addClass('first');
				$('th:last, td:last', this).addClass('last');
			});

			// First and last rows require top/bottom border.
			$('tr:first', this).addClass('first');
			$('tbody tr:last', this).addClass('last');
		});
	}

}
