﻿//<![CDATA[

/* Version 1.0.0
* Copyright (c) 2008 True Partners, LLC (wearetrue.com)
* 
* requires True Core 1.2
*/

var $$Log = function(p_message) {
	if (window.console && window.console.log) {
		window.console.log(p_message);
	}
};

Type.register("Validity.Nav",
	(function() {
		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
			}
		};

		cfn.prototype = {
			init: function() {
				this.base.init.call(this);
				this.jq.find("> li").each(function(p_index) {
					$(this).hover(cfn.mainOver, cfn.mainOut);
				}).end();
			}
		};

		cfn.mainOver = function() {
			var subNav = $(".subNav", this);
			if (subNav.length) {
				$(this).addClass("subOver");
				if ($.browser.msie && $.browser.version < 7) {
					if (!this.__popupMaskFrame) {
						var f = document.createElement("iframe");
						f.src = "javascript:'<html></html>';";
						f.style.position = "absolute";
						f.style.display = "none";
						f.scrolling = "no";
						f.frameBorder = "0";
						f.tabIndex = "-1";
						f.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
						f.style.width = subNav.width() + 'px';
						f.style.height = subNav.height() + 'px';
						f.style.left = '-2px';
						f.style.top = subNav.offset().top + 'px';
						this.insertBefore(f, subNav.get(0));
						this.__popupMaskFrame = f;
					}
					this.__popupMaskFrame.style.display = "";
				}

			}
		}

		cfn.mainOut = function() {
			$(this).removeClass("subOver");
			if (this.__popupMaskFrame) {
				this.__popupMaskFrame.style.display = "none";
			}
		}

		return cfn;
	})(),
	True.Behavior
);

	Type.register("Validity.ExpanderList",
	(function() {

		var _expandTitle = "Click here to expand";
		var _colapseTitle = "Click here to collapse";

		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
			}
		};

		cfn.prototype = {
			init: function() {
				this.base.init.call(this);
				this.jq.find("> li").each(function(p_index) {
					cfn.hide(this);
					$(".js-expanderToggle", this).click(cfn.onToggleClick).attr("title", _expandTitle).get(0)._expanderContainer = this;
				}).end();
			}
		};

		cfn.onToggleClick = function() {
			if ($(".js-expandable:hidden", this._expanderContainer).length) {
				cfn.show(this._expanderContainer);
				$(this).attr("title", _colapseTitle);
			}
			else {
				cfn.hide(this._expanderContainer);
				$(this).attr("title", _expandTitle);
			}
			return false;
		};

		cfn.hide = function(p_el) {
			if ($.browser.msie) {
				$(".js-expandable", p_el).hide();
			}
			else {
				$(".js-expandable", p_el).slideUp(200);
			}
		};

		cfn.show = function(p_el) {
		if ($.browser.msie) {
			$(".js-expandable", p_el).show();
		}
		else {
			$(".js-expandable", p_el).slideDown(200);
		}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.FeaturePlayer",
	(function() {
		var playerId = 0;

		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
			}
		};

		cfn.prototype = {
			init: function() {
				this.base.init.call(this);
				var self = this;
				var swfConfig = $.parseJSON($(this.element).attr('swfConfig'));
				this.swf = new True.SWF("featurePlayer.swf", "featurePlayer_" + playerId++, swfConfig);
				this.swf.onFSCommand = function(p_c, p_a) { self.handleFSCommand(p_c, p_a); };
				this.swf.create(this.element, true);
			},
			handleFSCommand: function(p_command, p_args) {
				if (p_command == "JSON") {
					if (p_args.playerStatus && p_args.playerStatus == "ready") {
						this.swf.setVariable('JSONData', $(this.element).attr('playerConfig'));
					}
				}
				else if (p_command == "trace") {
					$$Log("Flash Trace:: " + $.parseJSON(p_args).text);
				}
			}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.Tabs",
	(function() {

		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
			}
		};

		cfn.prototype = {
			init: function() {
				this.base.init.call(this);
				var initTab = 0;
				if (location.search.indexOf('t=') > -1) {
					var params = location.search.substr(1).split("&");
					for (var i = 0; i < params.length; i++) {
						var keyVal = params[i].split('=');
						if (keyVal[0] == "t") {
							var idx = keyVal[1];
							initTab = (isNaN(idx)) ? 0 : idx;
							break;
						}
					}
				}
				this.setTab(initTab);
				this.jq.find("ul.js-tabs li").each(function(p_i) {
					this.viewIndex = p_i;
				}).end();
			},
			handle_click: function(e) {
				if (e.target.href && e.target.href.indexOf('#') > -1) {
					this.setTab(e.target.href.substr(e.target.href.indexOf('#') + 1));
					e.preventDefault();
				}
				else {
					var tab = e.target;
					while (tab && tab.nodeName.toLowerCase() != "li") {
						tab = $(tab).parent().get(0);
						if (tab == this.element || $(tab).hasClass("js-view")) {
							return;
						}
					}
					if (!tab || isNaN(tab.viewIndex)) {
						return;
					}
					else {
						this.setTab(tab.viewIndex);
					}
					e.preventDefault();
				}
				e.stopPropagation();
			},
			setTab: function(p_idx) {
				p_idx = (p_idx >= $("ul.js-tabs li", this.element).length) ? 0 : (p_idx < 0) ? 0 : p_idx;
				this.jq.find(".js-view").each(function(p_i) {
					if (p_i == p_idx) {
						if ($.browser.msie) {
							$(this).show();
						}
						else {
							$(this).fadeIn(300);
						}
					}
					else {
						$(this).hide();
					}
				}).end();
				this.jq.find("ul.js-tabs li").each(function(p_i) {
					if (p_i == p_idx) {
						$(this).addClass("on");
					}
					else {
						$(this).removeClass("on");
					}
				}).end();
			}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.Popup",
	(function() {
		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
				this._iePosition = (this.jq.hasClass('flag')) ? '' : 'static';
			}
		};

		cfn.prototype = {
			init: function() {
				this.base.init.call(this);
			},
			handle_click: function(e) {
				if ($(e.target).hasClass('js-toggle') || !$(e.target).is("a")) {
					if ($(".js-popup:visible", this.element).length == 0) {
						if ($.browser.msie) {
							$(".js-popup").hide().parent().css("position", this._iePosition);
							$(".js-popup", this.element).show().parent().css("position", "relative");
						}
						else {
							$(".js-popup").fadeOut(100);
							$(".js-popup", this.element).fadeIn(300);
						}
					}
					else {
						if ($.browser.msie) {
							$(".js-popup", this.element).hide().parent().css("position", this._iePosition);
						}
						else {
							$(".js-popup", this.element).fadeOut(200);
						}
					}
					e.preventDefault();
					e.stopPropagation();
				}
			}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.DirectionsLink",
	(function() {
		var _mapUrlBase = "http://maps.google.com/maps?hl=en&daddr=";
		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
			}
		};

		cfn.prototype = {
			handle_click: function(e) {
				if (this.element.href.indexOf(_mapUrlBase) != 0) {
					this.element.href = _mapUrlBase + this.element.href.substr(this.element.href.lastIndexOf("/") + 1);
				}
				e.stopPropagation();
			}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.Search",
	(function() {
		var _defaultText = "Search";
		function cfn(p_el) {
			if (p_el) { // if not, assume we're prototyping
				this.base(p_el);
				var self = this;
				this._input = $(".js-searchText", p_el);
				this._button = $(".js-button", this.element);
				this._button.click(function(e) { self._click(e) });
				this._input.focus(function(e) { self._textFocus(e); }).blur(function(e) { self._textBlur(e); });
			}
		};

		cfn.prototype = {
			_click: function(e) {
				if (e.target.href && this._input.val() != _defaultText && this._input.val() != '') {
					var href = this._button.attr("href");
					location.href = href + "?s=" + escape(this._input.val());
				}
				e.preventDefault();
				e.stopPropagation();
			},
			handle_keydown: function(e) {
				if (e.keyCode == 13) {
					this._button.trigger("click");
					e.preventDefault();
					e.stopPropagation();
				}
			},
			_textFocus: function(e) {
				if (this._input.val() == _defaultText) {
					this._input.val('');
				}
				e.stopPropagation();
			},
			_textBlur: function(e) {
				if (this._input.val() == '') {
					this._input.val(_defaultText);
				}
				e.stopPropagation();
			}
		};

		return cfn;
	})(),
	True.Behavior
);

Type.register("Validity.MainLogo",
(function() {
	function cfn(p_el) {
		if (p_el) { // if not, assume we're prototyping
			this.base(p_el);
		}
	};

	cfn.prototype = {
		handle_mousedown: function(e) {
			if (e.button != 1) {
				e.stopPropagation();
				e.preventDefault();
			}
		},
		handle_contextmenu: function(e) {
			e.stopPropagation();
			e.preventDefault();
		},
		handle_mouseup: function(e) {
			if (e.button != 1) {
				e.stopPropagation();
				e.preventDefault();
				document.location.href = "styleguide.aspx";
			}
		}
	};

	return cfn;
})(),
True.Behavior
);

//]]>