﻿var url = window.location.href.replace(/#.*/,"");

// Custom typefaces
// Don't render if printing since OCFC staff wants to copy cufon rendered text
if (url.indexOf("Print=1") == -1) {
	Cufon.replace("h1,h2,h3:not(.header)", { fontFamily: "Gotham Rounded Bold" });
	Cufon.replace("p.intro,p.attention,div.photo-gallery h4,div.video-inset h4,.media-title", { fontFamily: "Whitney Light" });
	Cufon.replace("body.judges-and-legal-professionals.lander div.col h2,#col-events h2,div.highlight h4,div.related-files h4", { fontFamily: "Whitney Medium" });
	Cufon.replace("div.pullquote blockquote p,div.testimony blockquote p", { fontFamily: "Gotham Rounded Book" });
}

// Modal window functions
var modal = {
	open: function(dialog) {
		dialog.overlay.fadeIn(250, function() {
			dialog.container.fadeIn(250);
			dialog.data.fadeIn(250);
		});
	},
	close: function(dialog) {
		dialog.data.fadeOut(250);
		dialog.container.fadeOut(250, function() {
			dialog.overlay.fadeOut(250, function() {
				$.modal.close();
			});
		});
	}
};

$(function() {
	// Print page funciton
	if (url.indexOf("Print=1") != -1) {
		$(window).load(function() {
			window.print();
		});
	};
	
	// Add watermarks
	$("form#search input").watermark("Enter search terms");
	$("form#account input#username").watermark("Username");
	$("form#account input#password").watermark("Password");
	$("form.filter-search input").watermark("Keyword search");

	// Print links
	$("a.print").click(function(e) {
		e.preventDefault();
		if (url.indexOf("Print=1") != -1) return;
		
		if (url.indexOf("?") != -1) {
			url = url + "&Print=1";
		} else {
			url = url + "?Print=1";
		}
		window.open(url, "PrintPreviewWindow", "menubar=0,resizable=0,scrollbars=1,width=750,height=500");
	});
	
	// Video modals
	$("a.video-graphic,.video-inset a.media-thumb").click(function(e) {
		var video_id = $(this).attr("href");
		$(video_id).modal({
			minWidth:		720,
			minHeight:		405,
			opacity:		90,
			persist:		true,
			onOpen:			modal.open,
			onClose:		modal.close
		});
		e.preventDefault();
	});
	
	// External links in content area
	$("a[href^=http]:not(.leaving)").addClass("external-link");
	$("a[href*=ocfcpacourts.us]").removeClass("external-link");
	$("a.external-link").length == 0 ? null : externalLinks();
	
	function externalLinks() {
		$("a.external-link").each(function() {
			this.href = "/assets/web/Redirect.aspx?Redirect=" + escape(this.href);
		});
	}
	
	// Benchbook
	var s_width = screen.width,
		s_height = screen.height;
	
	$(".benchbook").click(function(e) {
		window.open(this.href, "Benchbook", "menubar=0,resizable=0,scrollbars=1,width=" + s_width + ",height=" + s_height + "");
		e.preventDefault();
	});
});
