(function () {
	"use strict";
	
	/*
	*	Stretch center div to fill window height.
	*	CSS currently has no means to take 100% height including padding/margins.
	*	box-sizing: border-box exists, but is not reliable at time of writing.
	*/
	function StretchLayout() {
		var originalHeight = $("#center").height();
		var offsetHeight = ($("#inner").outerHeight(true) - $("#inner").height()) + ($("#center").outerHeight(true) - $("#center").height());

		var resizeContent = function () {
			// set the center height back to default, otherwise #outer height calculation will be incorrect
			$("#center").height("auto");

			// calculate the new height of the content
			var newHeight = $("#outer").height() - offsetHeight;

			// if the new height is greater than the height the document began with, apply new height
			if (newHeight > originalHeight) {
				$("#center").height(newHeight);
			}
		};

		resizeContent();
		$(window).resize(function () {
			resizeContent();
		});
	}
	new StretchLayout();

	/*
	*	Tie a default, persistent value to a text input to use in place of a traditional label
	*/
	function CRB_InputValueAsLabel(el) {
		this.text = $(el).val();
		this.changed = false;
		var self = this;
		$(el).focus(function () {
			$(this).addClass("active");
			if (!self.changed) {
				$(this).val("");
			}
		}).blur(function () {
			$(this).removeClass("active");
			if ((self.changed && !$.trim($(this).val())) || !self.changed) {
				self.changed = false;
				$(this).val(self.text);
			}
		}).keypress(function () {
			self.changed = true;
		});
	}

	function CRB_TabbedDialog() {

		this.init = function () {
			var self = this;

			// hide all content areas but the first
			$(".tabbed-dialog > li:not(:first-child)").hide();
			// set the first tab as the active tab
			$(".tabbed-dialog > li:first-child .tab").addClass("active");

			// put the pointer/hand cursor on tabs
			$(".tabbed-dialog > li .tab").css({
				cursor : "pointer"
			});

			// bind events to tabs
			$(".tabbed-dialog > li .tab").each(function (id) {
				$(this).click(function () {
					self.goToTab(id);
				});
			});

			// move and aggregate tabs to a new location
			$(".tabbed-dialog").before(
				"<ul class=\"tabbed-dialog-tabs-list\">" +
				"</ul>"
			);
			$(".tabbed-dialog > li .tab").each(function () {
				$(this).appendTo(".tabbed-dialog-tabs-list").wrap("<li></li>");
			});
		};

		this.goToTab = function (id) {
			// hide content area of all tabs
			$(".tabbed-dialog > li").hide();
			// show content area for selected tab
			$(".tabbed-dialog > li").eq(id).show();
			// remove active class from all tabs
			$(".tabbed-dialog-tabs-list > li .tab").removeClass("active");
			// add active class to selected tab
			$(".tabbed-dialog-tabs-list > li .tab").eq(id).addClass("active");
		};
	}

	new CRB_TabbedDialog().init();

	/*
	*	SLIDER FUNCTIONALITY OVERVIEW:
	*	set width of slider to double width of view (current slide + transition slide)
	*	add left margin to emulate third pane on left side, allowing current slide to be in the center of the three
	*	    1         2         3
	*	[********][OOOOOOOO][        ]
	*	* - margin
	*	O - slides
	*	1) Left pseudo slide created by left margin for retreating transition
	*	2) Center/current/at rest slide
	*	3) Right slide for advancing transition
	*
	*	Advancing would happen like this:
	*	1. [********][OOOOOOOO][        ]
	*	2. [********][OOOOOOOO][OOOOOOOO]
	*	3. [********][OOOOOOOO][        ]
	*
	*	1) Starting state
	*	2) Add new slides in third section
	*	3) Remove slides in second section, and third section will automatically move to second section
	*
	*	Retreating would happen something like this:
	*	1. [********][OOOOOOOO][        ]
	*	2. [OOOOOOOO][OOOOOOOO][        ]
	*	3. [OOOOOOOO][        ][        ]
	*	4. [********][OOOOOOOO][        ]
	*
	*	1) Starting state
	*	2) Remove left margin and add new slides in first section
	*	3) Remove slides from second section
	*	4) Add margin back, automatically making first section become second section by pushing panes to the right
	*/
	function CRB_Slider(parms) {
		parms.elements = parms.elements || {};
		parms.animation = parms.animation || {};

		// identify the elements that will be used
		this.els = {};
		this.els.slider = parms.elements.slider || "#slider";
		this.els.viewbox = parms.elements.viewbox || this.els.slider + " .viewbox";
		this.els.slides = parms.elements.slides || this.els.viewbox + " .slides";
		this.els.slide = parms.elements.slide || this.els.slides + " li";
		this.els.retreatButtons = parms.elements.retreatButtons || false;
		this.els.advanceButtons = parms.elements.advanceButtons || false;
		this.els.goToButtons = parms.elements.goToButtons || false;
		this.els.pauseButtons = parms.elements.pauseButtons || false;
		
		if (!$(this.els.slide)[0]) {
			return false;
		}

		// identify attributes of the animation
		this.animation = {};
		this.animation.direction = parms.animation.direction && parms.animation.direction == "vertical" ? "vertical" : "horizontal";
		this.animation.interval = parms.animation.interval || 10000;
		this.animation.duration = parms.animation.duration || 1000;
		this.animation.offset = 0;
		if (this.animation.direction == "vertical") {
			this.animation.offset = parms.animation.offset || -($(this.els.slide).eq(0).outerHeight(true));
		} else {
			this.animation.offset = parms.animation.offset || -($(this.els.slide).eq(0).outerWidth(true));
		}

		this.animation.continuousLoop = parms.animation.continuousLoop && parms.animation.continuousLoop === false ? false : true;
		this.animation.autoAdvance = parms.animation.autoAdvance && parms.animation.autoAdvance === true ? true : false;

		this.options = {};
		this.options.createPagingButtons = parms.options.createPagingButtons || false;

		// identify attributes about the slider
		this.slides = [];
		this.delta = parms.delta || 1;					// the number of slides in a group
		this.current = 0;								// track the id of the current slide being viewed (or the first in the group/range/delta)
		this.next = 0;									// the id of the next slide to transition to (initilize to first slide)
		this.numSlides = $(this.els.slide).length;		// the number of slides available
		this.slideBuffer = false;
		this.sliderOrigin = false;
		this.autoAdvancePaused = true;					// the state of the pause of the auto-advancement

		this.init = function (parms) {
			var i,
				self = this,
				size = Math.abs(this.animation.offset * this.delta),
				css = {position : "relative"};

			// create array of slides
			$(this.els.slide).each(function () {
				self.slides.push($(this));
			});

			// move all slides into hidden div
			// This removes them from the slider, but keeps the references in the this.slides array valid so they can be accessed later
			$(this.els.slider).append("<div id=\"slider_slideOverflow\" style=\"display: none;\"></div>");
			this.slideBuffer = $("#slider_slideOverflow");
			for (i in this.slides) {
				if (!this.slides.hasOwnProperty(i)) {
					continue;
				}
				this.slideBuffer.append(this.slides[i]);
			}

			// set width/height (size) of slider to double width of view (current slide + transition slide)
			// add left margin to emulate third pane on left side, allowing current slide to be in the center of the three
			if (this.animation.direction == "vertical") {
				css.top = size * -1;
				css.height = size * 2;
//				css.{"margin-top"} = size;
				css["margin-top"] = size;
			} else {
				css.left = size * -1;
				css.width = size * 2;
//				css.{"margin-left"} = size;
				css["margin-left"] = size;
			}
			$(this.els.slides).css(css);

			// define the origin for the slider (co-ordinates for current pane space)
			this.sliderOrigin = size * -1;
//			this.sliderOrigin.left = size * -1;
//			this.sliderOrigin.top = 0;

			// show/copy initial slides (0 through delta - 1)
			for (i = 0; i < this.delta; i++) {
				this.slides[i].clone().appendTo(this.els.slides);
			}

			// create buttons for paging
			if (this.options.createPagingButtons) {
				this.createPagingButtons();
			}

			// bind button events
			this.assignRetreatButtons();
			this.assignAdvanceButtons();
			this.assignGoToButtons();
			this.assignPauseButtons();

			// show buttons
			$(this.els.retreatButtons).show().css({visibility : "visible"});
			$(this.els.advanceButtons).show().css({visibility : "visible"});
			$(this.els.goToButtons).show().css({visibility : "visible"});
			$(this.els.pauseButtons).show().css({visibility : "visible"});

			// instantiate the auto-advance/timer controlled sliding
			if (this.animation.autoAdvance) {
				this.autoAdvancePlay();
			}
		};

		this.createPagingButtons = function () {
			var i,
//				numSlides = $(this.els.slides).length,
				numSlides = this.numSlides,
				pagingLinks = [];

			for (i = 1; i <= numSlides; i ++) {
				pagingLinks.push("<li><a href=\"#\" title=\"" + i + "\">" + i + "</a></li>");
			}
			pagingLinks = (
				"<ol class=\"paging\">" +
				pagingLinks.join("") +
				"</ol>"
			);

			$(this.els.slider).append(pagingLinks);

			// give first paging button active status
			$(this.els.goToButtons).eq(0).addClass("active");
		};

		// bind events to retreat buttons
		this.assignRetreatButtons = function () {
			var i,
				self = this,
				btns;

			if (!$(this.els.retreatButtons).length) {
				return false;
			}

			// if multiple selectors, split them up
			btns = this.els.retreatButtons.split(",");

			for (i in btns) {
				if (!btns.hasOwnProperty(i)) {
					continue;
				}
				$(btns[i]).each(function () {
					$(this).click(function () {
						self.goTo("prev");
						return false;
					});
				});
			}
		};

		// bind events to advance buttons
		this.assignAdvanceButtons = function () {
			var i,
				self = this,
				btns;

			if (!$(this.els.advanceButtons).length) {
				return false;
			}

			// if multiple selectors, split them up
			btns = this.els.advanceButtons.split(",");

			for (i in btns) {
				if (!btns.hasOwnProperty(i)) {
					continue;
				}
				$(btns[i]).each(function () {
					$(this).click(function () {
						self.goTo("next");
						return false;
					});
				});
			}
		};

		// bind events to goTo buttons
		this.assignGoToButtons = function () {
			var i,
				self = this,
				btns;

			if (!$(this.els.goToButtons).length) {
				return false;
			}

			// if multiple selectors specified, split them up
			btns = this.els.goToButtons.split(",");

			for (i in btns) {
				if (!btns.hasOwnProperty(i)) {
					continue;
				}
				$(btns[i]).each(function (id) {
					$(this).click(function () {
						self.goTo(id);
						return false;
					});
				});
			}
		};
		
		// bind events to pause buttons
		this.assignPauseButtons = function () {
			var i,
				self = this,
				btns;

			if (!$(this.els.pauseButtons).length) {
				return false;
			}
			
			// if multiple selectors specified, split them up
			btns = this.els.pauseButtons.split(",");
			
			for (i in btns) {
				if (!btns.hasOwnProperty(i)) {
					continue;
				}
				$(btns[i]).each(function (id) {
					$(this).click(function () {
						if (self.autoAdvancePaused) {
							self.autoAdvancePlay();
						} else {
							self.autoAdvancePause();
						}

						return false;
					});
				});
			}
		};

		// add an 'active' class to goTo buttons that correspond to the current slide
		this.updateButtons = function () {
			var i,
				btns;

			// if multiple selectors specified, split them up
			if (!this.els.goToButtons) {
				return;
			}
			btns = this.els.goToButtons.split(",");
			for (i in btns) {
				if (!btns.hasOwnProperty(i)) {
					continue;
				}
				// clear 'active' status from all buttons
				$(btns[i]).removeClass("active");
				// assign 'active' status to buttons that correspond to the current slide
				$(btns[i]).eq(this.current).addClass("active");
			}
		};

		// set a timer to automatically advance the current slide
		this.autoAdvancePlay = function () {
			var self = this;

			// Not using window.setInterval - every callback would need to reset the timer anyway to handle manual invocation
			// of the goTo() method (If user clicked a button to choose a slide)
			this.autoAdvancePaused = false;

			this.timer = window.setTimeout(function () {
				self.goTo("next");
			}, this.animation.interval);

			$(this.els.pauseButtons).removeClass("active");
		};

		// pause playback/automatic advancing
		this.autoAdvancePause = function () {
			this.autoAdvancePaused = true;
			window.clearTimeout(this.timer);
			$(this.els.pauseButtons).addClass("active");
		};

		// position the slider back in its starting position
		this.returnToOrigin = function () {
			var css = {};
			if (this.animation.direction == "vertical") {
				css.top = this.sliderOrigin;
//				css.{"margin-top"} = Math.abs(this.sliderOrigin);
				css["margin-top"] = Math.abs(this.sliderOrigin);
			} else {
				css.left = this.sliderOrigin;
//				css.{"margin-left"} = Math.abs(this.sliderOrigin);
				css["margin-left"] = Math.abs(this.sliderOrigin);
			}
			$(this.els.slides).css(css);
		};

		// go to a specified slide
		this.goTo = function (slideId) {
			var i,
				self = this,
				direction = "advance",
				group = [],
				key = false,
				destination = false,
				parms = {};

			// calculate which slide to go to and what direction to animate to get there
			if (slideId === "next") {
				slideId = this.current + this.delta;
				if (slideId > this.numSlides - 1) {
					slideId = slideId - this.numSlides;
				}
				direction = "advance";
			} else if (slideId === "prev") {
				slideId = this.current - this.delta;
				if (slideId < 0) {
					slideId = this.numSlides + slideId;
				}
				direction = "retreat";
			} else {
				if (slideId > this.current) {
					direction = "advance";
				} else {
					direction = "retreat";
				}
			}

			// Ensure desired slide exists
			if (!this.slides[slideId]) {
				return false;
			}

			// identify the slide we're transitioning to (next slide). If the next slide is requested while it is
			// currently being transitioned to, the request will be ignored
			if (slideId === this.next) {
				return false;
			}
			this.next = slideId;

			// stop any animation that may currently be taking place
			$(this.els.slides).stop(true, true);

			// clear the autoAdvance timeout in case this was a manual goTo
			if (this.animation.autoAdvance) {
				window.clearTimeout(this.timer);
			}

			// copy next range of elements into destination
			// get range of elements
			if (direction == "advance") {
				// get #[delta] elements after current element
				for (i = 0; i < this.delta; i++) {
					key = slideId + i;

					if (key >= this.numSlides) {
						key = key - this.numSlides;
					}
					group.push(this.slides[key]);
				}
			} else {
				// get #[delta] elements before current element
				for (i = 0; i < this.delta; i++) {
					key = slideId + i;

					if (key >= this.numSlides) {
						key = key - this.numSlides;
					}
					group.push(this.slides[key]);
				}
				group.reverse();
			}

			if (direction == "advance") {
				// add new elements to the end of the slider
				for (i in group) {
					if (group.hasOwnProperty(i)) {
						group[i].clone().appendTo(this.els.slides);
					}
				}
			} else {
				// remove the margin from the left of the slider, and reset the offset because of the missing margin
				var css = {};
				if (this.animation.direction == "vertical") {
//					css.{"margin-top"} = 0;
					css["margin-top"] = 0;
					css.top = this.sliderOrigin;
				} else {
//					css.{"margin-left"} = 0;

					css["margin-left"] = 0;
					css.left = this.sliderOrigin;
				}
				$(this.els.slides).css(css);

				// add new elements to the beginning of the slider
				for (i in group) {
					if (group.hasOwnProperty(i)) {
						group[i].clone().prependTo(this.els.slides);
					}
				}
			}

			// identify destination offset
			if (direction == "advance") {
				destination = this.sliderOrigin + this.delta * this.animation.offset;
			} else {
				destination = 0;
			}

			// move to destination offset
			if (this.animation.direction == "vertical") {
				parms.top = destination;
			} else {
				parms.left = destination;
			}
			$(this.els.slides).animate(parms, this.animation.duration, function () {
				var i = 0;

				// remove old slide elements
				if (direction == "advance") {
					// remove the first #[delta] elements
					$(self.els.slide).each(function () {
						i++;
						if (i > self.delta) {
							return;
						}

						$(this).remove();
					});
				} else {
					// remove the last #[delta] elements
					$(self.els.slide).each(function () {
						i++;
						if (i <= self.delta) {
							return;
						}

						$(this).remove();
					});
				}

				// shift slider back to origin position
				self.returnToOrigin();

				// update the current slide
				self.current = slideId;
				// clear the next slide
				this.next = false;

				// update any goTo buttons
				self.updateButtons();

				// reapply the autoAdvance timer
				if (self.animation.autoAdvance && !self.autoAdvancePaused) {
					self.autoAdvancePlay();
				}
			});
		};

		this.init();
	}

	/********************************************************************************/

	function HeaderSearchForm() {
		var el = "#search input[type=\"text\"]";
		if ($(el).length) {
			new CRB_InputValueAsLabel(el);
		}
	}
	new HeaderSearchForm();

	function PromoPlayer() {
		this.slider = false;
		this.init = function () {
			this.slider = new CRB_Slider({
				elements : {
					slider : "#promo",
					slides : "#promo .slides",
					slide : "#promo .slides > li",
					goToButtons : "#promo .paging > li a"
				},
				animation : {
					autoAdvance : true,
					interval : 10000,
					duration : 400
				},
				options : {
					createPagingButtons : true
				}
			});
		}

		this.init();
	}
	new PromoPlayer();

	function ModalDialog(parms) {
		parms = parms || {};

		this.init = function () {
			var self = this;

			// only proceed if the provided required element(s) exist
			if (!$(parms.requiredElement).length) {
				return;
			}

			// append popup window/overlay to end of body - IE7 can't handle z-index properly if added elsewhere
			if (!$("#modal-dialog").length) {
				$("body").append(
					"<div id=\"modal-dialog\">" +
					"<div class=\"controls\">" +
					"<a class=\"btn-close\" href=\"#\" title=\"Close\">Close X</a>" +
					"</div>" +
					"<div class=\"content\">" +
					"</div>" +
					"</div>" +
					"<div id=\"modal-dialog-overlay\"></div>"
				);
			}

			// click on dialog 'close' button
			$("#modal-dialog .btn-close, #modal-dialog-overlay").click(function () {
				self.hideDialog();
				return false;
			});

			// bind any application specific events
			this.bindControls();
		};

		/*
		*	overwrite this function, binding the desired events (typically the events that will show the dialog)
		*/
		this.bindControls = function () {
			return;
		};

		/*
		*	overwrite this function, generating the desired dialog content
		*/
		this.getDialogContent = function () {
			return "";
		};

		/*
		*	Show the dialog - identify/generate/insert dialog content
		*/
		this.showDialog = function () {
			var content = this.getDialogContent();
			this.populateDialog(content);
			$("#modal-dialog").fadeIn("fast");
			$("#modal-dialog-overlay").fadeIn("fast");
		};

		/*
		*	Hide the dialog
		*/
		this.hideDialog = function () {
			var self = this;
			$("#modal-dialog").fadeOut("fast", function () {
				$("#modal-dialog-overlay").fadeOut("fast");
				// clear contents of dialog
				self.clearDialog();
			});
		};

		/*
		*	Clear the contents of the dialog
		*/
		this.clearDialog = function () {
			$("#modal-dialog > .content").empty();
		}

		/*
		*	Insert the provided HTML into the dialog
		*/
		this.populateDialog = function (html) {
			$("#modal-dialog > .content").html(html);
		}
	}
	
	var HomePageVideoDialog = new ModalDialog({
		requiredElement : '.homepage-video-dialog'
	});
	HomePageVideoDialog.video = {};
	HomePageVideoDialog.video.webm;
	HomePageVideoDialog.video.mp4;
	HomePageVideoDialog.bindControls = function() {
		var self = this;
		$(".homepage-video-dialog").click(function() {
			var data = $.parseJSON($(this).parents("li").find("[name=\"video-data\"]").val());
			self.video.webm = data.webm || "";
			self.video.mp4 = data.mp4 || "";
			self.video.poster = data.poster || "";
			self.title = data.title || "";
			self.postID = data.postID || "";
			self.showDialog();
			return false;
		});
		$(".homepage-video-link").click(function() {
			var data = $.parseJSON($(this).parents("li").find("[name=\"video-data\"]").val());
			self.video.webm = data.webm || "";
			self.video.mp4 = data.mp4 || "";
			self.video.poster = data.poster || "";
			self.title = data.title || "";
			self.postID = data.postID || "";
			self.showDialog();
			return false;
		});
	}
	HomePageVideoDialog.getDialogContent = function() {
		/*
		var html = (
			"<video width=\"640\" height=\"360\" controls=\"controls\" autoplay=\"autoplay\">\n" +
			"\t<source src=\"" + this.video.mp4 + "\" type=\"video/mp4\"></source>\n" +
			"\t<source src=\"" + this.video.webm + "\" type=\"video/webm\"></source>\n" +
			"\t<object width=\"640\" height=\"360\" type=\"application/x-shockwave-flash\" data=\"" + this.video.mp4 + "\">\n" +
			"\t\t<param name=\"movie\" value=\"/wp-content/themes/carlton/_common/videos/flowplayer-3.2.7.swf\"/>\n" +
			"\t\t<param name=\"allowfullscreen\" value=\"true\"/>\n" +
			"\t\t<param name=\"flashvars\" value=\"config={'playlist':['" + this.video.poster + "',{'url':'" + this.video.mp4 + "','autoPlay':true,'autoBuffering':true}]}\"/>\n" +
			"\t\t<img src='"+ this.video.poster + "' alt='"+ this.title + "' width='640' height='360' />\n" +
			"\t</object>\n" +
			"</video>\n"
		);
		*/
		var html = (
			"<video width=\"720\" height=\"405\" controls=\"controls\" poster=\""+this.video.poster+"\" autoplay=\"autoplay\">\n" +
			"\t<source src=\"" + this.video.mp4 + "\" type=\"video/mp4\"></source>\n" +
			"\t<source src=\"" + this.video.webm + "\" type=\"video/webm\"></source>\n" +
			"\t<object width=\"720\" height=\"405\" type=\"application/x-shockwave-flash\" data=\"" + this.video.mp4 + "\">\n" +
			"\t\t<param name=\"movie\" value=\"/wp-content/themes/carlton/_common/videos/flowplayer-3.2.7.swf\"/>\n" +
			"\t\t<param name=\"allowfullscreen\" value=\"true\"/>\n" +
			"\t\t<param name=\"flashvars\" value=\"config={'playlist':['" + this.video.poster + "',{'url':'" + this.video.mp4 + "','autoPlay':true,'autoBuffering':true}]}\"/>\n" +
			"\t\t<img src=\""+ this.video.poster + "\" alt=\""+ this.title + "\" width=\"720\" height=\"405\" />\n" +
			"\t</object>\n" +
			"</video>\n"
		);

		return html;
	};
	HomePageVideoDialog.init();
	
	var VideoPageDialog = new ModalDialog({
		requiredElement : '.video-page-dialog'
	});
	VideoPageDialog.video = {}
	VideoPageDialog.video.webm;
	VideoPageDialog.video.mp4;
	VideoPageDialog.bindControls = function() {
		var self = this;
		$(".video-page-dialog").click(function() {
			var data = $.parseJSON($(this).parents("li").find("[name=\"video-data\"]").val());
			self.video.webm = data.webm || "";
			self.video.mp4 = data.mp4 || "";
			self.video.poster = data.poster || "";
			self.title = data.title || "";
			self.postID = data.postID || "";
			self.showDialog();
			return false;
		});	
	}
	VideoPageDialog.getDialogContent = function() {
		var html = (
			"<video width=\"720\" height=\"405\" controls=\"controls\" poster=\""+this.video.poster+"\" autoplay=\"autoplay\">\n" +
			"\t<source src=\"" + this.video.mp4 + "\" type=\"video/mp4\"></source>\n" +
			"\t<source src=\"" + this.video.webm + "\" type=\"video/webm\"></source>\n" +
			"\t<object width=\"720\" height=\"405\" type=\"application/x-shockwave-flash\" data=\"" + this.video.mp4 + "\">\n" +
			"\t\t<param name=\"movie\" value=\"/wp-content/themes/carlton/_common/videos/flowplayer-3.2.7.swf\"/>\n" +
			"\t\t<param name=\"allowfullscreen\" value=\"true\"/>\n" +
			"\t\t<param name=\"flashvars\" value=\"config={'playlist':['" + this.video.poster + "',{'url':'" + this.video.mp4 + "','autoPlay':true,'autoBuffering':true}]}\"/>\n" +
			"\t\t<img src=\""+ this.video.poster + "\" alt=\""+ this.title + "\" width=\"720\" height=\"405\" />\n" +
			"\t</object>\n" +
			"</video>\n"
		);
		return html;
	};
	VideoPageDialog.init();
	
	var ManagementVideoDialog = new ModalDialog({
		requiredElement : '.management_video'
	});
	ManagementVideoDialog.video = {}
	ManagementVideoDialog.video.webm;
	ManagementVideoDialog.video.mp4;
	ManagementVideoDialog.bindControls = function() {
		var self = this;
		$(".management_video").click(function() {
			var data = $.parseJSON($(this).find("[name=\"video-data\"]").val());
			self.video.webm = data.webm || "";
			self.video.mp4 = data.mp4 || "";
			self.video.poster = data.poster || "";
			self.title = data.title || "";
			self.postID = data.postID || "";
			self.showDialog();
			return false;
		});	
	}
	ManagementVideoDialog.getDialogContent = function() {
		var html = (
			"<video width=\"720\" height=\"405\" controls=\"controls\" autoplay=\"autoplay\" poster=\""+this.video.poster+"\">\n" +
			"\t<source src=\"" + this.video.mp4 + "\" type=\"video/mp4\"></source>\n" +
			"\t<source src=\"" + this.video.webm + "\" type=\"video/webm\"></source>\n" +
			"\t<object width=\"720\" height=\"405\" type=\"application/x-shockwave-flash\" data=\"" + this.video.mp4 + "\">\n" +
			"\t\t<param name=\"movie\" value=\"/wp-content/themes/carlton/_common/videos/flowplayer-3.2.7.swf\"/>\n" +
			"\t\t<param name=\"allowfullscreen\" value=\"true\"/>\n" +
			"\t\t<param name=\"flashvars\" value=\"config={'playlist':['" + this.video.poster + "',{'url':'" + this.video.mp4 + "','autoPlay':true,'autoBuffering':true}]}\"/>\n" +
			"\t\t<img src=\""+ this.video.poster + "\" alt=\""+ this.title + "\" width=\"720\" height=\"405\" />\n" +
			"\t</object>\n" +
			"</video>\n"
		);
		return html;
	};
	ManagementVideoDialog.init();


	var CareerDialog = new ModalDialog({
		requiredElement : '#career'
	});
	CareerDialog.bindControls = function() {
		var self = this;
		$("#modal-dialog").addClass('career-form');
		var completed = $("#gforms_confirmation_message");
		if(completed.html() == "Thanks for contacting us! We will get in touch with you shortly."){
			$("#modal-dialog").addClass("completed");
		}
		$("#career .apply-btn").click(function() {
			self.showDialog();
			return false;
		});
		var posted = $("#career .application-form input.post_status").val();
		if(posted == "true"){
			self.showDialog();
		}

	}
	CareerDialog.getDialogContent = function() {
		var html = $("#career .application-form").html();
		return html;	
	};
	CareerDialog.init();


	
}());
