﻿var url = window.location.href.replace(/#.*/,"");
Cufon.replace(".box .hd h2", { fontFamily: "Franklin Gothic Medium Condensed" });

$(function() {
	// PDC membership box
	var pdc_hd_img_height = $(".pdc-membership .bd img:first").outerHeight(true);
	$(".pdc-membership ul li strong").click(function() {
		$(this).closest("ul").find("div").not($(this).next()).each(function() {
			if ($(this).is(":visible")) {
				$(this).slideUp();
				$(this).prev("strong").find(".icon-arrow").toggleClass("icon-arrow-down");
			}
		});
		$(this).siblings("div").slideToggle();
		$(this).find(".icon-arrow").toggleClass("icon-arrow-down");
	});
	
	// Training & events box
 	// First, hide the ones in the community events category
 	$(".box.events li.community_event").hide();
 	$(".box.events .bd div").show();
 	$(".box.events .bd div a.pdc").addClass("selected");
 	$(".box.events .bd div a").live("click", function(e) {
		$container = $(this).closest("div.box");
		if ($(this).hasClass("selected") !== true) {
			$(this).add($(this).siblings()).toggleClass("selected");
			$container.find("li").toggle();
		}
		e.preventDefault();
	});
	
	// Accordions
	$("div.accordion-default").length == 0 ? null : $("div.accordion-default").accordion({ header: "h3.header", autoHeight: false });

	if ($("div.accordion-alt").length > 0) {
		$("div.accordion-alt").find("h3 + div").hide();
		$("div.accordion-alt").find("h3").append('<span class="icon-arrow"></span>');
		$("div.accordion-alt h3").click(function() {
			$(this).find("span").toggleClass("icon-arrow-down");
			$(this).next().slideToggle();
		});
	}
	
	// Tabset
	$("div.tabset").length == 0 ? null : $("div.tabset").tabs();
	
	// Carousel
	var $pager = $('<p class="pager">').appendTo($(".carousel"));
	$(".carousel-items").each(function() {
		$(this).cycle({
			fx:			'scrollHorz',
			pager:		$pager,
			timeout:	0,
			speed:		500,
			nowrap:		true
		});
	});
	
	// Results table (articles, events)
	url.indexOf("Print=1") == -1 ? $("table.results:not(.members) tr.details").hide() : null;
	$("table.results:not(.members) tr:not(.details)").click(function() {
		$(this).next().toggle();
		$(this).find("span.icon-arrow").toggleClass("down");
	});
	
	// Results table (members)	
	url.indexOf("Print=1") == -1 ? $("table.results.members span:not(.icon-arrow)").hide() : null;
	$("table.results.members tr").click(function() {
		$(this).find("span:not(.icon-arrow)").toggle();
		$(this).find("span.icon-arrow").toggleClass("down");
	});
	
	// Print page funciton
	if (url.indexOf("Print=1") != -1) {
		$(window).load(function() {
			$("table.results.members span:not(.icon-arrow)").show();
			window.print();
		});
	};
	
	// Print links
	$("a.print").click(function(e) {
		e.preventDefault();
		if (url.indexOf("Print=1") != -1) return;
		window.open($(this).attr("href"), "PrintPreviewWindow", "menubar=0,resizable=0,scrollbars=1,width=750,height=500");
	});
});




