CGBABY = {};

CGBABY.loadFunctions = function() {
	
	CGSITE.updateCopyright(2009);
	
	// get all h2 tags and convert to Flash + add printable HTML headline after
	var headlines = $$('h2');
	$$('span.h2').each(function(i){
		headlines.push(i);	
	});
	headlines.each(function(i, index){
		if (i.className != "noConvert") {
			i.id = "headline" + index;
			var headlineText = i.innerHTML;
			var flashText = CGSITE.textToFlash(headlineText);
			var bookPodPattern = new RegExp("^bookPod", "i");
			// if it's an overall page headline:
			if (!bookPodPattern.match(i.up().className)) {
				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 bookPod:
			} else {
				var isWide = i.className == "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(i.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 embedPattern = new RegExp("<embed", "gi");
			var objectPattern = new RegExp("<object", "gi");
			var swfPattern = new RegExp("\.swf", "gi");
			if (embedPattern.match(i.innerHTML) || objectPattern.match(i.innerHTML) || swfPattern.match(i.innerHTML)) {
				var printOnlyHead = i.tagName == "SPAN" ? new Element("span") : new Element("h2");
				printOnlyHead.className = "printOnly";
				printOnlyHead.update(headlineText);
				i.insert({
					after : printOnlyHead
				});
			} // end if
		} // end if
	}.bind(this));
	
	// get all bookPod divs and reformat to 2-column layout
	if ($('home')) {
		var bookPods = $$('.bookPod');
		var clearingDiv = "<div class=\"clear\"><\/div>";
		var floatValue = "right";
		bookPods.each(function(i, index){
			var widePodPattern = new RegExp("openWidth$", "i");
			if (!widePodPattern.match(i.className)) {
				floatValue = (floatValue == "right" ? "left" : "right");
				i.style.width = "48%";
				i.style.cssFloat = floatValue;
				i.style.styleFloat = floatValue;
				if (floatValue == "right" || index == bookPods.length - 1) {
					i.insert({
						after : clearingDiv
					});
				} // end if
			} // end if
		}.bind(this));
		
		var homeBoxFlashEmbeds = $$('li a span.h2 embed');
		var homeBoxFlashObjects = $$('li a span.h2 object');
		var homeBoxHeads = [];
		homeBoxFlashEmbeds.each(function(i){ homeBoxHeads.push(i); });
		homeBoxFlashObjects.each(function(i){ homeBoxHeads.push(i); });
		homeBoxHeads.each(function(i){ i.style.cursor = "pointer"; });
	} // end if
	
	if ($('activities')) {
		$$('a.song').each(function(i, index){
			var audioId = "audio_key" + index;
			var listItem = i.up();
			var audioFile = i.href;
			var linkContent = i.innerHTML;
			i.remove();
			var remainingContent = listItem.innerHTML;
			listItem.update(linkContent + " " + remainingContent);
			listItem.insert("<div id=\"" + audioId + "\"></div>");
			var qt = new QTObject(audioFile, "Audio_" + index, "250", "16");
			qt.addParam("autostart", "false");
			qt.write(audioId);
			listItem.style.fontWeight = "bold";
			listItem.up().removeClassName("list");
			listItem.style.textAlign = "center";
			listItem.style.padding = "15px 0";
		});	
	}
	
} // end loadFunctions

Event.observe(window, "load", CGBABY.loadFunctions);