﻿function toggleGroups(container, link) {
	if ($(link).html() == "Hide All") {
		$("." + container + " dd").hide()
		$(link).html("Show All")
		$("." + container + " dt .toggle-button").html("Show Answer")
	}
	else if ($(link).html() == "Show All") {
		$(link).html("Hide All")
		$("." + container + " dt .toggle-button").html("Hide Answer")
		$("." + container + " dd").show()
	}
	else if ($(link).html() == "Hide Answer") {
		$(link).html("Show Answer").parent().next("dd").hide()
		$("#" + container + "-toggle").html("Show All")
	}
	else {
		$(link).html("Hide Answer").parent().next("dd").show()
		if ($("." + container + " dd:not(:visible)").size() == 0) {
			$("#" + container + "-toggle").html("Hide All")
		}
	}
}

function csestyle(o) {
	if ($(o).val()) { $(o).addClass("active") }
	else { $(o).removeClass("active") }
}

$(function() {
	// Default easing
	jQuery.easing.def = "easeInOutCubic"

	/* Fancybox
	-------------------------------------------------- */
	$("a[href]").filter(function() {
		return this.href.match(/\.(?:pdf|doc|xls|ppt|docx|xlsx|pptx)($|\&|\?)/)
	}).each(function() {
		if ($.browser.msie) {
			$(this).click(function() {
			window.open("http://docs.google.com/viewer?url=" + escape(this.href), "docviewer", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1")
				return false
			})
		}
		else {
			$(this).fancybox({ type: "iframe", href: "http://docs.google.com/viewer?url=" + escape(this.href) + "&embedded=true" })
		}
	})

	/* Google Analytics Special Links
	-------------------------------------------------- */
	$("a[href]").filter(function() {
		return (this.href.substring(0, 7) == "mailto:" || this.hostname != location.hostname || this.href.match(/\.(?:pdf|doc|xls|ppt|docx|xlsx|pptx)($|\&|\?)/))
	})
	.each(function() {
		$(this).bind('click', function() {
			var link = this.href
			if (link.substring(0, 7) == "mailto:") { pageTracker._trackPageview("/unisun/mailto?href=" + escape(link.substring(7))) }
			else if (this.hostname != location.hostname) { pageTracker._trackPageview("/unisun/external?href=" + escape(link)) }
			else { pageTracker._trackPageview("/unisun/download?href=" + escape(link)) }
		})
	})
})
