$(document).ready(function(){

	/* **************************************************** *
	* IE 6 CSS BACKGROUND FLICKER FIX
	* ***************************************************** */

	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {};

	/* **************************************************** *
	* SEARCH FIELD VALUE SET AND REMOVAL
	* ***************************************************** */

	$(".search-field").val("Search").click(function(){
		$(this).val("");
	});

	/* **************************************************** *
	* HORIZONTAL NAVIGATION DROPDOWN MENU FEATURE
	* ***************************************************** */

	$("#primary-navigation li").hover(
		function(){$(this).addClass("ssfdd");},
		function(){$(this).removeClass("ssfdd");}
	);

	/* **************************************************** *
	* PRODUCTS A-Z FEATURE
	* ***************************************************** */

	$("#all-products").change(function(){
		window.location.href = $(this).find("option:selected").val();
	});

	/* **************************************************** *
	* ZEBRA STRIPING FEATURE
	* ***************************************************** */

	$(".zebra-striped tbody tr:odd td").addClass('zebra');

	/* **************************************************** *
	* ROUNDED CORNER FEATURE
	* ***************************************************** */

	$(".rounded-corners")
	.find(".content").css({padding: "0 10px", borderWidth: "0 1px"}).end()
	.find(".content :first-child").css({marginTop: "0", paddingTop: "0"}).end()
	.find(".content :last-child").css({marginBottom: "0", paddingBottom: "0"}).end()
	.prepend("<div class='top-corners'><span>&nbsp;</span></div>")
	.append("<div class='bottom-corners'><span>&nbsp;</span></div>");

	/* **************************************************** *
	 * TAB FEATURE
	 * **************************************************** */

	if($(".tabs").size() >= 1){
		var uri = window.location.href;
		uri = escape(uri);
		uri = uri.split('%23');
		var initParam = "#" + uri[1];
		initParam = initParam.replace("%7E", "");
		$(".tabs").each(function(){
			if($(this).children("div.tab-content").size() >= 1){
				$(this)
				.children("div.tab-content").addClass("flip").end()
				.children("div.tab-content:first").addClass("flop").end()
				.find("ul.tab-buttons li:first").addClass("current").end()
				.find("ul.tab-buttons li a").click(function(){
					var tgt = $(this).attr("href");
					$(this).parent().siblings().parent().siblings("div.tab-content.flop").removeClass("flop");
					$(this).parent().siblings(".current").removeClass("current");
					$(tgt).addClass("flop");
					$(this).parent().addClass("current");
					$(this).blur();
					return false;
				});
				if(initParam != "#undefined"){
					$(this).find("ul.tab-buttons li a[href=" + initParam + "]").parent().siblings().parent().siblings("div.tab-content.flop").removeClass("flop");
					$(this).find("ul.tab-buttons li a[href=" + initParam + "]").parent().siblings(".current").removeClass("current");
					$(initParam).addClass("flop");
					$(this).find("ul.tab-buttons li a[href=" + initParam + "]").parent().addClass("current");
					$(this).find("ul.tab-buttons li a[href=" + initParam + "]").blur();
				};
			};
		});
	};

	/* **************************************************** *
	 * EXPAND & COLLAPSE FEATURE
	 * **************************************************** */

	if ($(".expandCollapse").size() >= 1) {
		var $ecContent = $(".expandCollapse div.ec-content").length;
		$(".expandCollapse")
		.eq(0).prepend("<div id='ecAll'><a id='expandAll' href='#expandAll'>Expand All</a> <a id='collapseAll' href='#collapseAll'>Collapse All</a></div>").end()
		.children("div.ec-content").addClass("flip").end()
		.children("p.ec-handle").hover(
			function(){$(this).css({cursor: "pointer"});},
			function(){$(this).css({cursor: "auto"})}).end()
			.find("#collapseAll").hide();
			$(".expandCollapse a[href='#expandAll']").click(function(){
				$(".expandCollapse")
				.children("div.ec-content").removeClass("flip").end()
				.children("p.ec-handle").addClass("collapse").end()
				.find("#collapseAll").show().end()
				.find("#expandAll").hide();
				$(this).blur;
				return false;
			});
			$(".expandCollapse a[href='#collapseAll']").click(function(){
				$(".expandCollapse")
				.children("div.ec-content").addClass("flip").end()
				.children("p.ec-handle").removeClass("collapse").end()
				.find("#collapseAll").hide().end()
				.find("#expandAll").show();
				$(this).blur;
				return false;
			});
			$(".expandCollapse").each(function(){
				$(this).children("p.ec-handle").click(function(){
					$(this).toggleClass("collapse");
					$(this).next("div.ec-content").toggleClass("flip");
					var $wFlip = $(".expandCollapse div.ec-content.flip").length;
					if($ecContent == $wFlip) {
						$(".expandCollapse ")
						.find("#collapseAll").hide().end()
						.find("#expandAll").show();
					} else if($wFlip == 0) {
						$(".expandCollapse ")
						.find("#collapseAll").show().end()
						.find("#expandAll").hide();
					} else {
						$(".expandCollapse ")
						.find("#collapseAll").show().end()
						.find("#expandAll").show();
					};
				});
			});
		};

	/* **************************************************** *
	 * COLLAPSED FAQS FEATURE
	 * **************************************************** */

	if ($(".collapsed-faqs").size() >= 1) {
		$("#page-body").prepend("<div id='faqAnswers'><a id='showHideAnswers' href='#showHideAnswers'>Show All Answers</a></div>").end()
		$(".collapsed-faqs")
		.find("dd").addClass("flip").end()
		.find("dt").addClass("anchor")
		.click(function(){
			if($(this).next("dd").is(".flip")){
				$(this).next("dd").removeClass("flip");
			} else {
				$(this).next("dd").addClass("flip");
			}
		});
		$("#faqAnswers > #showHideAnswers").toggle(
			function(){
				$(this).text("Hide All Answers").blur();
				$(".collapsed-faqs").children("dd").removeClass("flip");
			},
			function(){
				$(this).text("Show All Answers").blur();
				$(".collapsed-faqs").children("dd").not(".flip").addClass("flip");
			});
		};

	/* **************************************************** *
	 * EXTERNAL LINKS FEATURE
	 * **************************************************** */

	$("a[rel='external']").addClass("external").click(function(){
		$(this).attr({target: "_blank"});
	});

	/* **************************************************** *
	 * PRINT THIS PAGE FEATURE
	 * **************************************************** */

	$("a[rel='print']").attr({
		href: "javascript:window.print()",
		title: "Print this page",
		alt: "Print this page"
	}).css({display: "inline"}).empty().text("Print");
	
	/* **************************************************** *
	* DOCUMENT TYPE "SPRITE" FEATURE
	* ***************************************************** */

	$("a[rel=document]").each(function() {

		var largeIcon = $(this).parents("ul").hasClass(".doc-types-lg");

		if(largeIcon) {
			$(this)
			.css({display: "inline-block", background: "#E7EAEC", marginLeft: "58px", padding: "10px", width: "250px", border: "1px solid #C7C7C7", color: "#737373"})
			.hover(function() {
				$(this).css({background: "#D2E284"});
			}, function() {
				$(this).css({background: "#E7EAEC"});
			})
			.wrap("<span></span>")
			.find("strong").css({display: "block"});
		} else {
			$(this)
			.css({display: "inline-block", background: "#fff", marginLeft: "18px"})
			.wrap("<span></span>");
		};

		var dLink =  $(this).attr("href").split(".");
		var dCount = dLink.length;
		var dType = dLink[dCount-1];
		var dIcon = $(this).parent("span");

		if(largeIcon) {
			dIcon.css({display: "inline-block", background: "url(https://sc1.checkpoint.com/www/images/layout/duke/sprite-doc-types-lg.gif) 0 0 no-repeat"});
		} else {
			dIcon.css({display: "inline-block", background: "url(https://sc1.checkpoint.com/www/images/layout/duke/sprite-doc-types.gif) 0 0 no-repeat"});
		};

		if(dType == "doc" || dType == "dot") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "0 50%"});
			} else {
				dIcon.css({backgroundPosition: "1px 0"});
			};
		} else if(dType == "pdf") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-69px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-17px 0"});
			};
		} else if(dType == "ppt" || dType == "pps" || dType == "pot") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-137px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-36px 0"});
			};
		} else if(dType == "xls") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-206px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-55px 0"});
			};
		} else if(dType == "zip" || dType == "tar" || dType == "tgz") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-275px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-73px 0"});
			};
		} else if(dType == "fla" || dType == "flv" || dType == "swf" ) {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-343px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-92px 0"});
			};
		} else if(dType == "rss" || dType == "atom") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-409px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-112px 0"});
			};
		} else if(dType == "iso") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-477px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-132px 0"});
			};
		} else if(dType == "mov" || dType == "wmv" || dType == "avi") {
			if(largeIcon) {
				dIcon.css({backgroundPosition: "-541px 50%"});
			} else {
				dIcon.css({backgroundPosition: "-152px 0"});
			};
		} else {
			$(this).css({marginLeft: "0"}).parent("span").css({background: "none"});
		};

	});

});
