/*---------------------------------------------------------------------------
	Common
---------------------------------------------------------------------------*/

$(document).ready(function(){
	if (jQuery.browser.msie) {
		$('#header').corner("round bl br 10px");
		$('.block, .fill, #cta-bookmarkwith').corner("round 10px");
		$('#cta-community, .fill:has(#cta-readingguide), .book-club-item, .fill:has(#cta-viewreadingguide)').uncorner();
		$('.book-club-item').corner("round tl tr 10px");
	}
	
	/* Reading Guides */
	// Adds Question/Answer OL to reading guides.
	$('div.interview ol').each(function(i) {
		var qIndex = i + 1;
		$(this).after("<strong>" + qIndex + ". " + $(this).find("li").html() + "</strong>").remove();		
	});
	
	$('.interview.collapsable strong').css("display","none");
	
		
	$('.block.collapsable').each(function() {
		var self = $(this);
		
		self.find('h2')
			.addClass('open')
			.css('cursor', 'pointer')
			.append('<span>open</span>')			
			.siblings().hide();
		
		self.find('h2').toggle(function() {
			$(this).siblings().show();
			$(this).find("span").remove();
			$(this).removeClass('open')
			.addClass('close')			
			.append('<span>close</span>');
						
		}, function() {
			$(this).siblings().hide();
			$(this).find("span").remove();
			$(this).removeClass('close')
			.addClass('open')			
			.append('<span>open</span>');
		});
		
		if(self.hasClass('first')) {
			self.find('h2').trigger("click");
		}		
	});
	
	$('ul.subsection-links li a').click(function() {
		var anchor = $(this).attr('href').split('#')[1];
	
		//$('.block.collapsable').find('h2.close').trigger('click');
		$('.block.collapsable[name=' + anchor + ']').find('h2').trigger('click');	
	});

	
	// Hijack Anchor Clicks
	$('a[href~="#"]').each(function() {
		var anchor_id = $(this).attr('href');
		if ($(anchor_id).length == 1) {
			$(this).click(function() {
				$.scrollTo(anchor_id,1000);
				return false;
			});
		}
	});
	
	// Open external links in a new window:
	$('a.external, div.additional-resources a:not([href~="#"])').click(function() {
		window.open($(this).attr('href'));
		
		return false;
	});	
		
	// Newsletter Fix 
	$('input[type=checkbox]').css("border","none");
});