CGBABY = {};

$(function() {
	
	CGSITE.updateCopyright(2009);
	
	var pageId = $(document.body).attr('id');
	
	// get all h2 tags and convert to Flash + add printable HTML headline after
	$('h2, span.h2').each(function(index){
		if (!$(this).hasClass('noConvert')) {
			$(this).attr('id', 'headline' + index);
			var headlineText = $(this).html();
			var flashText = CGSITE.textToFlash(headlineText);
			// if it's not inside a .featurePods li, it's an overall page headline:
			if (!$(this).parent().hasClass('featurePods')) {
				var swfUrl = "headline_page.swf?hlText=" + flashText;
				var so = new SWFObject(swfUrl, flashText, 580, 28, 9, "#FFFFFF");
			// else, if it's a headline inside a .featurePods li:
			} else {
				var isWide = $(this).hasClass('wide') ? true : false;
				var flashWidth = isWide ? 570 : 265;
				var swfUrlFilename = isWide ? "headline_featurepod_wide" : "headline_featurepod";
				var swfUrl = swfUrlFilename + ".swf?hlText=" + flashText;
				var so = new SWFObject(swfUrl, flashText, flashWidth, 24, 9, "#FFFFFF");
			}
			so.addParam("wmode", "transparent");
			so.write($(this).attr('id'));
			/* did the Flash get added? if so, add a printing version of the headline
			 * since objects and embeds won't print, per style sheet
			 */
			var comparisonString = $(this).html();
			if (comparisonString.match(/<embed/gi) || comparisonString.match(/<object/gi) || comparisonString.match(/\.swf/gi)) {
				var printOnlyTagName = this.tagName == "SPAN" ? "span" : "h2";
				var printOnlyHead = $('<' + printOnlyTagName + ' class="printOnly">' + headlineText + '<\/' + printOnlyTagName + '>');
				$(this).after(printOnlyHead);
			} // end if
		} // end if
	});
	
	// get all featurePods divs and reformat to 2-column layout
	if (pageId == 'home') {
		var featurePods = $('ul.featurePods li');
		var clearingEl = "<li class=\"clear\"><\/li>";
		var floatValue = "right";
		featurePods.each(function(index){
			floatValue = (floatValue == "right" ? "left" : "right");
			$(this).css( { 'width' : '48%', 'float' : floatValue } );
			if (floatValue == "right" || index == featurePods.length - 1) {
				$(this).after(clearingEl);
			} // end inner if
		});
		$('li a span.h2 embed', 'li a span.h2 object').each(function(){
			$(this).css('cursor', 'pointer');
		});
	} // end if
	
	if (pageId == 'activities') {
		$('a.song').each(function(index){
			var audioId = "audio_key" + index;
			var listItem = $(this).parent();
			var audioFile = $(this).attr('href');
			var linkContent = $(this).html();
			$(this).remove();
			var remainingContent = listItem.html();
			listItem.html(linkContent + " " + remainingContent);
			listItem.append("<div id=\"" + audioId + "\"></div>");
			var qt = new QTObject(audioFile, "Audio_" + index, "250", "16");
			qt.addParam("autostart", "false");
			qt.write(audioId);
			listItem.css('fontWeight', 'bold');
			listItem.parent().removeClass('list');
			listItem.css('textAlign', 'center');
			listItem.css('padding', '15px 0');
		});	
	}
	
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20880597-2']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
