/*---- Print function ----*/
function ngsprint() {
	window.print();
}

$(document).ready(function() {	
	/*---- Apply Styles for users with JS enabled ----*/
	// $("<link>") .attr({type: "text/css",href: "styles/projects/news/c/js_enabled.css",rel:"stylesheet"}) .appendTo("head"); 
	/*---- DL Code ----*/
	$('div.dl h3').addClass('hidden');
	$('div.dl .credit').removeClass('hidden');
	$('div.dl ul').slideshow();
	
	/*---- Put label text inside input for Newsletters ----*/
	$("#newsletter input").labelify({ text: "label" });
	
	/*---- Initialize Carousels ----*/
	$('div.carousel ul.three').jcarousel({
		scroll: 3,
		visible: 3
	});
	
	$('div.carousel ul.seven').jcarousel({
		scroll: 7,
		visible: 7
	});
	
	$('div.carousel ul.four').jcarousel({
		scroll: 4,
		visible: 4
	});
	
	$('div.carousel ul.five').jcarousel({
		scroll: 5,
		visible: 5
	});
	
	/*---- Share Button Home Code ----*/
	$('body.home #share, body.level_2 #share').addClass('collapsed');
	$('#nav_share li a').addClass('hiddenText');
	$('#nav_share li').slice(4).addClass('hidden');
	$('#nav_share').append('<li class="more_link"><a href="">More</a></li>');
	var moreLink = $('#nav_share .more_link');
	moreLink.click(function () { 
		$('#share').toggleClass('collapsed');
		$('#nav_share li').slice(4, -1).toggleClass('hidden');
		if (moreLink.text() =='More'){
			moreLink.html('<a href="">Collapse</a>');				
		} else {
			moreLink.html('<a href="">More</a>');
		}
			return false;
	});
	
	/*---- Hide Share Email Form ----*/
	$('#share_email').addClass('hidden');
	
	/*---- Prepend Print Link to Article Rating div ----*/
	// Causing some error, possibly related to Share Links scripts; user not affected - LB 061009
	$('#article_rating').before('<div id="print_link"><a href="#" onclick="ngsprint();return false;">Printer Friendly</a></div>');
	
	/*---- Most Popular Tabs Code ----*/
	$('div.tabbed_box').each(function() {
		// Show just the first tab
		var sections = $('.popularity_type', this);
		sections.hide();
		$(sections[0]).show();
	
		// Build the tab-links
		var ul = $('<ul class="nav nav_tabbed">');
		sections.each(function(index) {
			var section_obj = $(this);
			var heading = $('h4', this).html();
			var li = $('<li class="nav_0'+(index+1)+'">');
			$('h4', this).remove();
			li.append(
				$('<h4><a href="#">'+heading+'</a></h4>').click(function() {
					// Show just this section.
					sections.hide();
					section_obj.show();
				
					// And mark just this tab
					tabs.removeClass('selected');
					li.addClass('selected');
					return false;					
			}));
			ul.append(li);
		})
		
		$('div.wrap', this).before(ul);
	
		// Compile the list of new tabs we just made, and select the first one.
		var tabs = $('li', ul);
		$(tabs[0]).addClass('selected');
	});
	
	$('table.striped tr:odd').css('background-color','#f4f4f4');
	
	/*---- Article Rating functionality ----*/
	$('#article_rating input.star').rating();

	// $('div.fancybox').hide();
	// $('a').fancybox({
	// 	'padding': 30,
	// 	'imageScale': true,
	// 	'hideOnContentClick': false,
	// 	'frameWidth': 610,
	// 	'imageScale': true,
	// 	'centerOnScroll': false,
	// 	'overlayShow': true,
	// 	'overlayOpacity': 0.5
	// });
	// $('#fancy_close').append("CLOSE");
	// $('a.fancybox_close').click(function(){
	// 	$.fn.fancybox.close;
	// });
	// 	
	
	/*---- Set Equal Heights on Columns ----*/
	$('.homepage .subsection, .homepage #content_page_specific, .article .subsection, .small_article .subsection, .home .subsection, .article #content_page_specific, .small_article #content_page_specific, .home #content_page_specific, .a_z #content_page_specific').equalHeights(true);	
});	
