

/*------------news.js----------*/

// onDomReady
$(function() {
	// setup year links
	$('a.collapsible').click(function() {
		var cont = $('#content-'+$(this).attr('id').slice(-4));
		$(this).toggleClass('expanded', cont.is(':hidden'));
		cont.slideToggle();
		return false;
	});
	
	// setup expand/collapse all links
	$('.expand-all a').click(function() {
		var expand = ($(this).text() == 'Expand All') ? true : false;
		$('.sub-content').toggle(expand);
		$(this).text((expand) ? 'Collapse All' : 'Expand All');
		return false;
	});
	
	// setup auto anchors
	if ($('#jump-to-link').length) {
		var count = 0;
		$('#article-content a[name][href!], #newsletter-container a[name][href!]').each(function() {
			var txt = $(this).attr('name');
			var lnk = txt.replace(/[^a-z0-9_-]/ig, '').toLowerCase();
			$('#jump-to-link select').append('<option value="' + lnk + '">' + txt + '</option>');
			$(this)
				.attr('id', lnk)
				.attr('name', lnk)
			;
			count++;
		});
		if (count) {
			$('#jump-to-link').show();
		}
	}
});

// collapseElements function
function collapseElements(selector) {
	var elems = {};
	var current;
	
	// get section groups
	$(selector+' > p').each(function() {
		var obj = $(this);
		if (obj.hasClass('wysiwyg-section')) {
			current = 'section-' + String(obj.text()).replace(/[^a-z0-9_-]/ig, '').toLowerCase();
			elems[current] = new Array();
			obj
				.attr('rel', current)
				.addClass('expandable')
			;
		} else {
			if (current != '' && elems[current]) {
				elems[current].push(this);
			}
		}
	});
	
	// wrap p's in div's
	$.each(elems, function(k, v) {
			$(v).wrapAll('<div id="'+k+'" class="expandable-content"></div>');
	});
	
	// setup click event
	$('#newsletter-container p[rel]').click(function() {
		$('#'+$(this).attr('rel')).slideToggle();
	});
}

// jumpTo function
function jumpTo(id) {
	if (id == '') { return; }
	
	$.scrollTo('#'+id, 800, {offset:-20});
	$('#jump-to-link select').val('');
}
