function init() {
	if($("#contactForm").length > 0) {
		//Set-up hidden field controls on the contact form.
		$("#districtFields").hide();
		$("#schoolFields").hide();	
		$(".checkShow > input:checkbox:checked")
		$(".checkShow > input:checkbox").click(function() {
			if ($(this).is(":checked")) {
                $(this).siblings("div.subset").fadeIn();
            } else {
                $(this).siblings("div.subset").fadeOut(function() {
					$(this).find("input:checkbox").removeAttr("checked");
            		$(this).find("input, select").val("");
				});
            }												
		});
		
		//Set-up Validation
		$("#contactForm").submit(function() {return fValidate(this)});
	}

	$(".player").each(function (i) {
		var ap = $(this).find("img").length > 0 ? true : ($(this).parent(".overlay").length > 0) || ($(".channels a.selected").length > 0) ? true : false;
		loadFlow($(this).attr("id"),ap);					
	});
	
	if($(".playerLaunch").length > 0) {  
		$("a.playerLaunch[rel]").overlay({
        	effect: 'apple',  
			onLoad: function() {
				// does nothing, will play on its own.
			}, 			 
			// use stop instead of unload to play nicely with IE, but $f() causes error in Firefox
			onClose: function() { 
				if(navigator.appName == "Microsoft Internet Explorer") {
					$f().stop();  
				}
			} 
		});   
	}
}

$(document).ready(function() {
	init();
});

function fValidate(f) {
	var msg = "";
	$(f).find(".missing").removeClass("missing");
	$(f).find("label.req:not(:hidden)").each(function (i) {
		var classname = "#" + $(this).attr("for");
		if (classname != "#") {
			if ($(classname + ":text").length > 0 || $(classname).is("select") || $(classname).is("textarea")) {
				if($(classname).val() == "") {
					$(classname).addClass("missing");
					if (msg == "") {$(classname).focus()}
					msg = msg + "  - " + $(classname).attr("name") + "\n";
				}
			} else if ($(classname + ":checkbox").length > 0 || $(classname + ":radio").length > 0) {
				if ($(this).parents("form").find("input[name='" + $(classname).attr("name") + "']:checked").length == 0) {
					$(classname).addClass("missing");
					if (msg.indexOf("  - " + $(classname).attr("name") + "\n") == -1) {
						if (msg == "") {$(classname).focus()}
						msg = msg + "  - " + $(classname).attr("name") + "\n";
					}
				}
			}
		}
	});
	if (msg != "") {
		msg = msg.replace(/_/g, " ");
		msg = msg.replace(/\[\]/g, "");
		msg = "Please complete the following fields:\n" + msg;
		alert(msg);
		return false
	} else {
		return true;
	}
}

function loadFlow(pid,ap) {
	var auto= ap ? ap : false;
	flowplayer(pid, "http://www.iobservation.com/swf/flowplayer.commercial-3.1.5.swf", {
		key: '#@a0a21bae1b44a52f685',
		clip: {
			autoPlay: ap
		},
		plugins: {
			controls: {
				volumeSliderGradient: 'none',
				progressGradient: 'none',
				sliderColor: '#F1F1F1',
				bufferGradient: 'none',
				buttonColor: '#767676',
				timeBgColor: '#767676',
				backgroundGradient: 'high',
				backgroundColor: '#D6D6D6',
				timeColor: '#FFFFFF',
				tooltipColor: '#5C5C5C',
				volumeSliderColor: '#767676',
				tooltipTextColor: '#FFFFFF',
				progressColor: '#484848',
				bufferColor: '#767676',
				sliderGradient: 'none',
				borderRadius: '0px',
				durationColor: '#D3D3D3',
				buttonOverColor: '#484848',
				height: 20,
				opacity: 1.0
			}
		}
	});
}