////////////////////////////////////////////////////////////////
// HomeNet JS Core Site Library
// Carvenience Center Module
// (c) 2010, HomeNet Automotive LLC
////////////////////////////////////////////////////////////////

if (typeof HNSITE == 'undefined') HNSITE = {};
if (typeof HNSITE.Modules == 'undefined') HNSITE.Modules = {};

// ***************************************
// Define the modified jQueryUI tabs widget
//  -> widget namespace: ui.carvenience
//  -> source: jquery.ui.carvenience-1.8.5.dev.js
// ***************************************
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(b($,1S){p 2i=0,2j=0;b 2k(){h++2i}b 2l(){h++2j}$.P("4.2p",{D:{Y:t,1t:t,11:J,E:t,U:J,1Y:t,v:[],1X:t,1s:"2w",13:t,2f:"4-6-",H:t,1M:"<2h></2h>",1h:t,1f:t,y:t,1Z:"<2g>3a…</2g>",2C:"<k><a q=\'#{q}\'><1a>#{W}</1a></a></k>"},37:b(){3.1m(1g)},3m:b(1K,1r){c(1K=="d"){c(3.D.U&&1r==3.D.d){h}3.1f(1r)}K{3.D[1K]=1r;3.1m()}},1R:b(a){h a.2e&&a.2e.19(/\\s/g,"3g").19(/[^\\w\\2V-\\2U-]/g,"")||3.D.2f+2k()},1n:b(V){h V.19(/:/g,"\\\\:")},14:b(){p E=3.E||(3.E=3.D.E.2T||"4-6-"+2l());h $.E.2S(t,[E].2c($.2W(2X)))},I:b(1v,z){h{1v:1v,z:z,9:3.f.9(1v)}},1u:b(){3.l.O(".4-j-1q").F("4-j-1q").1W("1a:G(W.6)").1c(b(){p x=$(3);x.1F(x.G("W.6")).1p("W.6")})},1m:b(2m){p 7=3,o=3.D,2o=/^#.+/;3.17=3.A.1W("2R,30").M(0);3.l=$(" > k:2Z(a[q])",3.17);3.f=3.l.1z(b(){h $("a",3)[0]});3.u=$([]);3.f.1c(b(i,a){p q=$(a).1V("q");p 1y=q.2q("#")[0],1H;c(1y&&(1y===1T.2Y().2q("#")[0]||(1H=$("31")[0])&&1y===1H.q)){q=a.V;a.q=q}c(2o.2P(q)){7.u=7.u.Y(7.1n(q))}K c(q&&q!=="#"){$.G(a,"q.6",q);$.G(a,"H.6",q.19(/#.*$/,""));p S=7.1R(a);a.q="#"+S;p $z=$("#"+S);c(!$z.B){$z=$(o.1M).1V("S",S).C("4-6-z 4-P-1d 4-R-1w").2Q(7.u[i-1]||7.17);$z.G("1k.6",1g)}7.u=7.u.Y($z)}K{o.v.2z(i)}});c(2m){3.A.C("4-6 4-P 4-P-1d 4-R-1D");3.17.C("4-6-2y 4-1C-2B 4-1C-2A 4-P-2v 4-R-1D");3.l.C("4-j-1J 4-R-1U");3.u.C("4-6-z 4-P-1d 4-R-1w");c(o.d===1S){c(1T.V){3.f.1c(b(i,a){c(a.V==1T.V){o.d=i;h J}})}c(1L o.d!=="2r"&&o.E){o.d=2N(7.14(),10)}c(1L o.d!=="2r"&&3.l.O(".4-6-d").B){o.d=3.l.9(3.l.O(".4-6-d"))}o.d=o.d||(3.l.B?0:-1)}K c(o.d===t){o.d=-1}o.d=((o.d>=0&&3.f[o.d])||o.d<0)?o.d:0;o.v=$.3d(o.v.2c($.1z(3.l.O(".4-j-v"),b(n,i){h 7.l.9(n)}))).2t();c($.1E(o.d,o.v)!=-1){o.v.22($.1E(o.d,o.v),1)}3.u.C("4-6-m");3.l.F("4-6-d 4-j-Z");c(o.d>=0&&3.f.B){3.u.M(o.d).F("4-6-m");3.l.M(o.d).C("4-6-d 4-j-Z");7.A.N("6",b(){7.L("y",t,7.I(7.f[o.d],7.u[o.d]))});3.H(o.d)}$(3i).X("3h",b(){7.l.Y(7.f).1l(".6");7.l=7.f=7.u=t})}K{o.d=3.l.9(3.l.O(".4-6-d"))}3.A[o.U?"C":"F"]("4-6-U");c(o.E){3.14(o.d,o.E)}32(p i=0,k;(k=3.l[i]);i++){$(k)[$.1E(i,o.v)!=-1&&!$(k).T("4-6-d")?"C":"F"]("4-j-v")}c(o.11===J){3.f.1p("11.6")}3.l.Y(3.f).1l(".6");c(o.1s!=="23"){p 1Q=b(j,x){c(x.3f(":1O(.4-j-v)")){x.C("4-j-"+j)}};p 1P=b(j,x){x.F("4-j-"+j)};3.l.X("23.6",b(){1Q("1I",$(3))});3.l.X("3j.6",b(){1P("1I",$(3))});3.f.X("1B.6",b(){1Q("1B",$(3).1i("k"))});3.f.X("15.6",b(){1P("1B",$(3).1i("k"))})}p 1b,18;c(o.13){c($.3l(o.13)){1b=o.13[0];18=o.13[1]}K{1b=18=o.13}}b 1N($x,13){$x.3n("3e","");c(!$.36.2s&&13.2s){$x[0].35.34("O")}}p 1A=18?b(12,$y){$(12).1i("k").C("4-6-d 4-j-Z");$y.m().F("4-6-m").21(18,18.24||"25",b(){1N($y,18);7.L("y",t,7.I(12,$y[0]))})}:b(12,$y){$(12).1i("k").C("4-6-d 4-j-Z");$y.F("4-6-m");7.L("y",t,7.I(12,$y[0]))};p 1x=1b?b(12,$m){$m.21(1b,1b.24||"25",b(){7.l.F("4-6-d 4-j-Z");$m.C("4-6-m");1N($m,1b);7.A.1o("6")})}:b(12,$m,$y){7.l.F("4-6-d 4-j-Z");$m.C("4-6-m");7.A.1o("6")};3.f.X(o.1s+".6",b(){p x=3,$k=$(x).1i("k"),$m=7.u.O(":1O(.4-6-m)"),$y=$(7.1n(x.V));c(($k.T(\'4-6-d\')&&!o.U)||$k.T("4-j-v")||$k.T("4-j-1q")||7.u.O(":29").B||7.L("1f",t,7.I(3,$y[0]))===J){3.15();h J}o.d=7.f.9(3);7.1j();c(o.U){c($k.T("4-6-d")){o.d=-1;c(o.E){7.14(o.d,o.E)}7.A.N("6",b(){1x(x,$m)}).1o("6");3.15();h J}K c(!$m.B){c(o.E){7.14(o.d,o.E)}7.A.N("6",b(){1A(x,$y)});7.H(7.f.9(3));3.15();h J}}c(o.E){7.14(o.d,o.E)}c($y.B){c($m.B){7.A.N("6",b(){1x(x,$m)})}7.A.N("6",b(){1A(x,$y)});7.H(7.f.9(3))}K{26"1G 27 2n: 2x 2G 2F."}c($.2H.2K){3.15()}});3.f.X("20.6",b(){p x=3,$k=$(x).1i("k"),$m=7.u.O(":1O(.4-6-m)"),$y=$(7.1n(x.V));c(!$k.T(\'4-6-d\')||$k.T(\'4-j-v\')||$k.T(\'4-j-1q\')||7.u.O(":29").B||7.L("1f",t,7.I(3,$y[0]))===J){3.15();h J}o.d=7.f.9(3);7.1j();c($y.B){c($m.B){7.A.N("6",b(){1x(x,$m)})}7.A.N("6",b(){1A(x,$y)});7.H(7.f.9(3))}K{26"1G 27 2n: 2x 2G 2F."}c($.2H.2K){3.15()}});3.f.X("2w.6",b(){h J})},16:b(9){c(1L 9=="38"){9=3.f.9(3.f.O("[q$="+9+"]"))}h 9},1k:b(){p o=3.D;3.1j();3.A.1l(".6").F("4-6 4-P 4-P-1d 4-R-1D 4-6-U").1p("6");3.17.F("4-6-2y 4-1C-2B 4-1C-2A 4-P-2v 4-R-1D");3.f.1c(b(){p q=$.G(3,"q.6");c(q){3.q=q}p $3=$(3).1l(".6");$.1c(["q","H","11"],b(i,2u){$3.1p(2u+".6")})});3.l.1l(".6").Y(3.u).1c(b(){c($.G(3,"1k.6")){$(3).1h()}K{$(3).F(["4-j-1J","4-R-1U","4-6-d","4-j-Z","4-j-1I","4-j-1B","4-j-v","4-6-z","4-P-1d","4-R-1w","4-6-m"].2M(" "))}});c(o.E){3.14(t,o.E)}h 3},Y:b(Q,W,9){c(9===1S){9=3.f.B}p 7=3,o=3.D,$k=$(o.2C.19(/#\\{q\\}/g,Q).19(/#\\{W\\}/g,W)),S=!Q.3c("#")?Q.19("#",""):3.1R($("a",$k)[0]);$k.C("4-j-1J 4-R-1U").G("1k.6",1g);p $z=$("#"+S);c(!$z.B){$z=$(o.1M).1V("S",S).G("1k.6",1g)}$z.C("4-6-z 4-P-1d 4-R-1w 4-6-m");c(9>=3.l.B){$k.2E(3.17);$z.2E(3.17[0].39)}K{$k.2J(3.l[9]);$z.2J(3.u[9])}o.v=$.1z(o.v,b(n,i){h n>=9?++n:n});3.1m();c(3.f.B==1){o.d=0;$k.C("4-6-d 4-j-Z");$z.F("4-6-m");3.A.N("6",b(){7.L("y",t,7.I(7.f[0],7.u[0]))});3.H(0)}3.L("Y",t,3.I(3.f[9],3.u[9]));h 3},1h:b(9){9=3.16(9);p o=3.D,$k=3.l.M(9).1h(),$z=3.u.M(9).1h();c($k.T("4-6-d")&&3.f.B>1){3.1f(9+(9+1<3.f.B?1:-1))}o.v=$.1z($.2D(o.v,b(n,i){h n!=9}),b(n,i){h n>=9?--n:n});3.1m();3.L("1h",t,3.I($k.1W("a")[0],$z[0]));h 3},1X:b(9){9=3.16(9);p o=3.D;c($.1E(9,o.v)==-1){h}3.l.M(9).F("4-j-v");o.v=$.2D(o.v,b(n,i){h n!=9});3.L("1X",t,3.I(3.f[9],3.u[9]));h 3},1Y:b(9){9=3.16(9);p 7=3,o=3.D;c(9!=o.d){3.l.M(9).C("4-j-v");o.v.2z(9);o.v.2t();3.L("1Y",t,3.I(3.f[9],3.u[9]))}h 3},1f:b(9){9=3.16(9);c(9==-1){c(3.D.U&&3.D.d!=-1){9=3.D.d}K{h 3}}3.f.M(9).2I(3.D.1s+".6");h 3},20:b(9){9=3.16(9);c(9==-1||3.D.U)h 3;3.f.M(9).2I("20.6");h 3},H:b(9){9=3.16(9);p 7=3,o=3.D,a=3.f.M(9)[0],Q=$.G(a,"H.6");3.1j();c(!Q||3.A.N("6").B!==0&&$.G(a,"11.6")){3.A.1o("6");h}3.l.M(9).C("4-j-1q");c(o.1Z){p 1a=$("1a",a);1a.G("W.6",1a.1F()).1F(o.1Z)}3.1e=$.3b($.2d({},o.1t,{Q:Q,2L:b(r,s){$(7.1n(a.V)).1F(r);7.1u();c(o.11){$.G(a,"11.6",1g)}7.L("H",t,7.I(7.f[9],7.u[9]));28{o.1t.2L(r,s)}2a(e){}},2b:b(1e,s,e){7.1u();7.L("H",t,7.I(7.f[9],7.u[9]));28{o.1t.2b(1e,s,9,a)}2a(e){}}}));7.A.1o("6");h 3},1j:b(){3.A.N([]);3.u.33(J,1g);3.A.N("6",3.A.N("6").22(-2,2));c(3.1e){3.1e.1j();3k 3.1e}3.1u();h 3},Q:b(9,Q){3.f.M(9).1p("11.6").G("H.6",Q);h 3},B:b(){h 3.f.B}});$.2d($.4.2p,{2O:"1.8.5"})})(1G);',62,210,'|||this|ui||tabs|self||index||function|if|selected||anchors||return||state|li|lis|hide|||var|href|||null|panels|disabled||el|show|panel|element|length|addClass|options|cookie|removeClass|data|load|_ui|false|else|_trigger|eq|queue|filter|widget|url|corner|id|hasClass|collapsible|hash|label|bind|add|active||cache|clicked|fx|_cookie|blur|_getIndex|list|showFx|replace|span|hideFx|each|content|xhr|select|true|remove|closest|abort|destroy|unbind|_tabify|_sanitizeSelector|dequeue|removeData|processing|value|event|ajaxOptions|_cleanup|tab|bottom|hideTab|hrefBase|map|showTab|focus|helper|all|inArray|html|jQuery|baseEl|hover|default|key|typeof|panelTemplate|resetStyle|not|removeState|addState|_tabId|undefined|location|top|attr|find|enable|disable|spinner|reload|animate|splice|mouseover|duration|normal|throw|UI|try|animated|catch|error|concat|extend|title|idPrefix|em|div|tabId|listId|getNextTabId|getNextListId|init|Tabs|fragmentId|carvenience|split|number|opacity|sort|prefix|header|click|Mismatching|nav|push|clearfix|reset|tabTemplate|grep|appendTo|identifier|fragment|browser|trigger|insertBefore|msie|success|join|parseInt|version|test|insertAfter|ol|apply|name|uFFFF|u00c0|makeArray|arguments|toString|has|ul|base|for|stop|removeAttribute|style|support|_create|string|parentNode|Loading|ajax|indexOf|unique|display|is|_|unload|window|mouseout|delete|isArray|_setOption|css'.split('|'),0,{}))

// ***************************************
// Define our Modules.Carvenience namespace
// ***************************************
HNSITE.Modules.Carvenience = {};

// <summary>
// Contains configuration data needed to setup and create the Carvenience Center
// </summary>
HNSITE.Modules.Carvenience.Configuration = {
	IsConfigured: false, 
	IsDraggable: true, 
	TabPrefixID: 'ui-tabs-carvenience-', 
	Tabs: [], 
	Me: false
};

// <summary>
// Manually copy objects configuration data for complete control over setup
// Config Settings: 
//    draggable (boolean): Allow Carvenience to be a draggable panel
//    tabs (array of objects): Define tabs to implement in this format...
// 	                           [{name: 'Search', content: '/search.asp', shorthand: 'search'},...]
// </summary>
HNSITE.Modules.Carvenience.Configure = function(config) {
	if (typeof config.draggable == 'boolean')
		this.Configuration.IsDraggable = config.draggable;
	if (typeof config.tabs != 'undefined' && $j.isArray(config.tabs))
		this.Configuration.Tabs = config.tabs;
	else
		alert("The 'tabs' set in Carvenience.Configure is incorrect. Only developers should be seeing this and fixing immediately.");
};

// <summary>
// Properties available for help that provide information on the currently selected tab instead
// of remembering all the jQuery data variable names where its internally stored somewhere
// </summary>
HNSITE.Modules.Carvenience.CurrentTab = {
	Index: null,
	Referrer: null, 
	IsDirty: false,
	ID: function() { return HNSITE.Modules.Carvenience.Configuration.TabPrefixID + String(this.Index + 1); }, 
	Title: function() { return HNSITE.Modules.Carvenience.Configuration.Tabs[this.Index].name; },
	PostPath: function() { return HNSITE.Modules.Carvenience.Configuration.Tabs[this.Index].content; },
	WrapperClass: function() { return 'tab-content-' + HNSITE.Modules.Carvenience.Configuration.Tabs[this.Index].shorthand; }, 
	CustomBindings: function(thisContext) { 
		if (typeof HNSITE.Modules.Carvenience.Configuration.Tabs[this.Index].bindings == 'function') 
			HNSITE.Modules.Carvenience.Configuration.Tabs[this.Index].bindings.call(thisContext);
	}
};

// <summary>
// Displays the Carvenience Center to the user when being called from an element outside of Carvenience (otherwise use Reload)
// Options (specific to each instance of opening): 
//    openTab (string): Tab name ('shorthand' in config) to default to on opening
//    openParams (object): Simple key/pair object converted to a querystring to pass in data (must also set 'openTab')
//    onClose (function): Callback for when Carvenience is closed
//    showLastState (boolean): Show without specifying a tab but instead of resetting we will show the last tab viewed in its same state
// </summary>
HNSITE.Modules.Carvenience.Show = function(options) {
	if (typeof options == 'undefined') options = {};
	var self = this,
		saveOptions = {},
		carvenience = $j("#carvenience"),
		cover = HNSITE.UI.CreatePageCover({ coverOpacity: 0.3 });
	
	// Validate options and store internally the non-instance options needed beyond this method execution
	saveOptions['coverpage'] = cover;
	options.openParams = (typeof options.openParams == 'undefined') ? {} : $j.extend(options.openParams, {r: HNSITE.Utils.Stamp()});
	options.showLastState = (options.showLastState === true) ? true : false;
	if (options.onClose == 'function') saveOptions['onClose'] = options.onClose;
	carvenience.data("carvenience-options", saveOptions);
	
	// Instance initialization options before we display the Carvenience Center each time
	var isFirstExecution = self.Initialize(carvenience),
		openTabID = 0;
	if (options.showLastState === false && typeof options.openTab == 'string') {
		var requestedTab = HNSITE.Data.FilterByProperty(self.Configuration.Tabs, 'shorthand', options.openTab);
		openTabID = (requestedTab.length == 1) ? requestedTab[0].index : 0;
	}
	
	// Display and stay in center of screen until closed (first execution changes tab early to not show an empty box before it first loads something)
	if (options.showLastState === false)
		self.Loader.Show();
	if (isFirstExecution) 
		self.SelectTab(openTabID, options.openParams);
	HNSITE.Element.CenterInViewport(carvenience[0]).fadeIn("fast", function() {
		if (options.showLastState === false && !isFirstExecution)
			self.SelectTab(openTabID, options.openParams);
	});
	$j(window).bind("resize.carvenience", function() {
		HNSITE.Element.CenterInViewport(carvenience[0]);
	});
};

// <summary>
// Load or reload any tab for use while Carvenience Center is already being displayed so that any tab can pass data to itself
// and to each other for creating very interactive tab components. Also note that calling this with 'tabData' completely undefined 
// will reload the same tab with no data to simply refresh its original, default state for "start over" functionality if ever needed.
// Options (specific to each instance of opening): 
//    openTab (string): Defaults to current tab for reloading if undefined. Tab name (its 'shorthand' again) to load different tab.
//    openParams (object): Same simple key/pair object format of a querystring. Can leave empty if simply needing to link to another tab.
// </summary>
HNSITE.Modules.Carvenience.LoadTab = function(tabData) {
	if (this.Configuration.IsConfigured !== true) return;
	// Find which tab we are trying to load or reload
	tabData = tabData || {};
	var loadTabIndex,
		loadTabData = (typeof tabData.openParams != 'object') ? {} : $j.extend(tabData.openParams, {r: HNSITE.Utils.Stamp()});
	if (typeof tabData.openTab != 'string')
		loadTabIndex = this.CurrentTab.Index;
	else {
		var loadTabName = HNSITE.Data.FilterByProperty(this.Configuration.Tabs, 'shorthand', tabData.openTab);
		if (loadTabName.length != 1) return;
		loadTabIndex = loadTabName[0].index;
	}
	// Load the requested tab with optional data to pass in
	this.SelectTab(loadTabIndex, loadTabData);
};

// <summary>
// Interface to the select and load tab functionality to enforce refreshing the content via ajax. Switch to the requested tab  
// or if the request tab is the same as the current tab then reload it.
// </summary>
HNSITE.Modules.Carvenience.SelectTab = function(requestIndex, params) {
	this.UpdateAjaxData(params);
	if (this.CurrentTab.Index != requestIndex || this.CurrentTab.Index == null)
		this.Configuration.Me.carvenience('select', requestIndex);
	else 
		this.Configuration.Me.carvenience('reload', requestIndex);
};

// <summary>
// Uses the configuration data in the documents executer to create and setup the tabs
// as well as perform any binding for static elements that exist
// </summary>
HNSITE.Modules.Carvenience.Initialize = function(carvenience) {
	var self = this;
	if (self.Configuration.IsConfigured === true) return;
	
	// Create the tabs from our configuration
	var tabsMarkup = '';
	$j.each(self.Configuration.Tabs, function(index, tab) {
		tab['index'] = index; // Save index in each tab object for greping
		tabsMarkup += '<li class="tab"><a href="' + tab.content + '">' + tab.name + '</a></li>';
	});
	carvenience.children("ul.tabs-row").first().html(tabsMarkup);
	
	// Setup the tabs functionality and events
	self.Configuration.Me = carvenience.carvenience({
		idPrefix: self.Configuration.TabPrefixID, 
		panelTemplate: '<div class="carvenience-tab-panel"></div>', 
		selected: -1, 
		cache: false, 
		fx: { opacity: 'toggle', duration: 350 }, 
		ajaxOptions: {
			type: 'GET', 
			global: false, 
			data: {}, 
			error: function(xhr, status, index, anchor) {
				$j(anchor.hash).html("Carvenience Center couldn't load this tab. Please try again and if the problem still occurs please alert us.");
			}
		}, 
		select: function(event, ui) {
			self.CurrentTab.Referrer = self.CurrentTab.Index;
			return true;
		}, 
		load: function(event, ui) {
			// Add our inner tab structure to wrap each content file consistently
			self.CurrentTab.Index = ui.index;
			var tabContext = $j('#' + self.CurrentTab.ID());
			tabContext.wrapInner("<div class='" + self.CurrentTab.WrapperClass() + " container'></div>");
			// Reset the ajax data each time after loaded
			self.UpdateAjaxData({});
			// Bind here after content loads but before we show it to user
			HNSITE.UI.Initializer(tabContext[0]);
			self.CurrentTab.CustomBindings(tabContext[0]);
			if (self.Loader.IsLoading() === true) 
				self.Loader.Hide();
		}, 
		show: function(event, ui) {
			// Empty contents of the referring tab if applicable
			if (self.CurrentTab.Referrer != null && self.CurrentTab.Referrer != self.CurrentTab.Index)
				$j('#' + self.Configuration.TabPrefixID + String(self.CurrentTab.Referrer + 1)).empty();
			// Trigger a global event to allow anything to bind to when the panel is visible
			$j.event.trigger('Carvenience_Show');
		}
	});
	
	// Modify settings based on configuration
	if (self.Configuration.IsDraggable === true)
		carvenience.draggable({ handle: ".tabs-handle" });
	
	// Bind events to static close button
    carvenience.children(".close-button")
		.hover(function() { $j(this).toggleClass("ui-state-hover"); }, function() { $j(this).toggleClass("ui-state-hover"); })
		.click(function() { HNSITE.Modules.Carvenience.Close(); });
	
	// ** Create our live events for detecting special content markup to help create rich, interactive tab content files **
	// Usage: add class 'reload-tab' to an element to let it reload the current tab in its default state
	$j("#carvenience .carvenience-tab-panel").delegate(".reload-tab", "click", function() {
		self.LoadTab();
		return false;
	});
	// Usage: add class 'load-tab' to anchors and set the href to one of three options available shown in the below examples
	//   Ex 1: '<a class="load-tab" href="javascript:void(0);" rel="contact">' loads the contact tab (using shortcode) without any data
	//   Ex 2: '<a class="load-tab" href="javascript:void(0);" rel="search?type=used">' loads the search tab (using shortcode) with querystring as data to pass
	//   Ex 3: '<a class="load-tab" href="javascript:void(0);" rel="?type=used">' reloads the current tab with querystring as data to use
	$j("#carvenience").delegate(".load-tab", "click", function() {
		var tabRequest = $j(this).attr("rel").trim(),
			qsPosition = tabRequest.indexOf('?');
		if (qsPosition >= 0) {
			var tabParams = tabRequest.substring(qsPosition + 1);
			if (qsPosition === 0) 
				self.LoadTab({ openParams: HNSITE.Data.ParseQueryString(tabParams) });
			else {
				var tabShortcode = tabRequest.substring(0, qsPosition);
				if (HNSITE.Data.FilterByProperty(self.Configuration.Tabs, 'shorthand', tabShortcode).length) {
					self.LoadTab({
						openTab: tabShortcode, 
						openParams: HNSITE.Data.ParseQueryString(tabParams)
					});
				}
			}
		}
		else {
			if (HNSITE.UI.Validation.Regex.QuickTests.IsCharacters(tabRequest))
				self.LoadTab({ openTab: tabRequest });
		}
		return false;
	});
	// Usage: add class 'load-within-tab' to anchors in content files to open the link within the tab
	$j("#carvenience").delegate(".load-within-tab", "click", function() {
		$j('#' + self.CurrentTab.ID()).load($j(this).attr("href"));
		return false;
	});
	
	// Flag as having been configured so we dont reinitialize
	self.Configuration.IsConfigured = true;
	return true;
};

// <summary>
// Update the tabs ajax options with a new data object in key/pair values
// </summary>
HNSITE.Modules.Carvenience.UpdateAjaxData = function(newData) {
	if (typeof newData != 'object') newData = {};
	newData = $j.extend(newData, { r: HNSITE.Utils.Stamp() });
	var updatedAjax = $j.extend(this.Configuration.Me.carvenience('option', 'ajaxOptions'), { data: newData });
	this.Configuration.Me.carvenience('option', 'ajaxOptions', updatedAjax);
};

// <summary>
// Close the Carvenience Center and execute optional callback
// </summary>
HNSITE.Modules.Carvenience.Close = function() {
	if (!this.IsShown()) return;
	
	var carvenience = $j("#carvenience"),
		options = this.GetOptions();
	
	// Execute optional onClose callback
	if (options && typeof options.onClose == 'function')
		options.onClose.call(carvenience[0]);
	
	// Hide form again and remove cover
	carvenience.fadeOut("fast", function() {
		options.coverpage.hide().remove();
		$j(window).unbind("resize.cover").unbind("resize.carvenience");
	});
};

// <summary>
// Controls the loading screen between tab transitions on first opening the Carvenience Center panel. Helps to cover the
// transitioning effect due to the event ordering of displays that we need and also helps hide initialization visual oddities from
// some components like accordians while they transform.
// </summary>
HNSITE.Modules.Carvenience.Loader = (function() {
	var _loader;
	var GetLoader = function() { 
		if (typeof(_loader) == 'undefined')
			_loader = $j("#carvenience > .tab-loading-screen").first();
	};
	var _isLoading = false;
	var IsLoading = function() { return _isLoading; };
	var Show = function() {
		GetLoader();
		if (_loader.css("display") == 'none') {
			_isLoading = true;
			_loader.css("opacity", "0.90").show();
		}
	};
	var Hide = function() {
		GetLoader();
		if (_loader.css("display") == 'block') {
			_isLoading = false;
			_loader.hide().css("opacity", "1.00");
		}
	};
	return {
		Show: Show, 
		Hide: Hide, 
		IsLoading: IsLoading
	};
})();

HNSITE.Modules.Carvenience.IsShown = function() {
	return ($j("#carvenience").css("display") == 'block');
};

HNSITE.Modules.Carvenience.GetOptions = function() {
	return $j("#carvenience").data("carvenience-options");
};

