﻿


/// <reference path="../../../../../jQuery/1.3.2/jquery-1.3.2-vsdoc.js" />


/**
 *****************************************************************
 * AdvancedSearchPanel
 *****************************************************************
 *
 * Provides custom open/close functionality for the AdvancedSearchPanel
 *
 * Author : Liam Prescott
 */


	//Check that namespace into which the Class definition will be creates has been defined & if not then create
	
	if (!mrm.global.isNamespaceDefined("mrm.lexus.display.controls")) mrm.global.createNamespace("mrm.lexus.display.controls", "1.0");
	
	mrm.lexus.display.controls.AdvancedSearchPanel = Object.subClass(
		{
			/*
			 =============================
			 CONSTANTS
			 =============================
			 */
				"CLASS_PANEL_ADVANCED_SETTINGS"			: "panel-advanced-settings",
				"CLASS_PANEL_ADVANCED_SETTINGS_CLOSED"	: "panel-advanced-settings-closed",
				
				// COLUMNS
				"CLASS_COLUMN_1"						: "column-1",
				"CLASS_COLUMN_2"						: "column-2",
				
				// CONTROL CONTAINER CLASSES
				"CLASS_CONTROL_CONTAINER"				: "control-container",
				
				// CONTROL CONTAINER SECONDARY CLASSES
				"CLASS_SLIDER_CONTAINER"				: "slider-container",
				"CLASS_RADIOBUTTONLIST_CONTAINER"		: "radiobuttonlist-container",
				"CLASS_CHECKBOXLIST_CONTAINER"			: "radiobuttonlist-container",
				"CLASS_IMAGELIST_CONTAINER"				: "imagelist-container",
				
				// CONTROL CONTAINER UNIQUE ID CLASSES
				"CLASS_DATA_DISPLAY_CONTAINERS" : ["priceto", "odometerto", "transmission", "fueltype"],
				
				
				
				// STANDARD DISPLAY CLASSES
				"CLASS_STANDARD_DISPLAY_SLIDER"			: "ui-slider-container",	//div.
				"CLASS_STANDARD_DISPLAY_RADIOBUTTONLIST": "radiobuttonlist",		//div.
				"CLASS_STANDARD_DISPLAY_IMAGELIST"		: "imagegroup",				//fieldset.
				
				"CLASS_STANDARD_DISPLAY_OPEN"			: "standard-display-open",
				"CLASS_STANDARD_DISPLAY_CLOSED"			: "standard-display-closed",
				
				"CLASS_STANDARD_DISPLAY_CONTROL_OPEN"	: "standard-display-open",
				"CLASS_STANDARD_DISPLAY_CONTROL_CLOSE"	: "standard-display-close",
				
				
				// EXTENDED DISPLAY CLASSES
				"CLASS_EXTENDED_DISPLAY"				: "extended-data-display",
				
				"CLASS_EXTENDED_DISPLAY_OPEN"			: "extended-display-open",
				"CLASS_EXTENDED_DISPLAY_CLOSED"			: "extended-display-closed",
				
				"CLASS_EXTENDED_DISPLAY_CONTROL_OPEN"	: "extended-display-open",
				"CLASS_EXTENDED_DISPLAY_CONTROL_CLOSE"	: "extended-display-close",
				
				
				// STD PANEL CONSTRUCT CLASSES
				"CLASS_PANEL_BODY_CONTAINER"			: "panel-body-container",
				"CLASS_PANEL_BODY_CONTAINER_OPEN"		: "panel-body-container-open",
				"CLASS_PANEL_BODY_CONTAINER_CLOSED"		: "panel-body-container-closed",
				
				"CLASS_PANEL_BODY_HEADER"				: "panel-body-header",
				"CLASS_PANEL_BODY_CONTENT"				: "panel-body-content",
				"CLASS_OPEN"							: "open",
				"CLASS_CLOSE"							: "close",
				
				
				// SPECIFIC ITEM JQUERY IDs
				"ID_RESULTS_LIST_MODE" : "div.results-container.list-container",
				"ID_RESULTS_FLOW_MODE" : "div.results-container.photoflow-container",
				"ID_RANGE_DETAILS" : "div.range-container",
				
				"ID_MUST_HAVES_CONTROL_CONTAINER" : "div.control-container.options.checkboxlist-container",
				
				
				// STATE CONSTANTS
				"STATE_OPEN"	: "OPEN",
				"STATE_CLOSE"	: "CLOSE",
				
				
				// SCOPE CONSTANTS
				"SCOPE_STANDARD" : "SCOPE_STANDARD",
				"SCOPE_EXTENDED" : "SCOPE_EXTENDED",
				
				
				// DEFAULT PANEL HEIGHTS
				"DEFAULT_PANEL_HEIGHT_2_COLUMN" : 250, //242
				"DEFAULT_PANEL_HEIGHT_1_COLUMN" : 376,
				"DEFAULT_PANEL_HEIGHT_RANGE_DETAILS" : 465,
				
				"PANEL_HEIGHT_CLOSED" : 30,
				
				// PANEL PERSISTENCE
				"DEFAULT_PANEL_LINK_OPEN"		: "Open",
				"DEFAULT_PANEL_LINK_CLOSE"		: "Close",
				"DEFAULT_PANEL_STATE_COOKIE"	: "EnabledPanels",
				"DEFAULT_PANEL_HEIGHT_COOKIE"	: "Height",		
				"DEFAULT_PANEL_PERSISTENCE"		: true,		
				
			/*
			 =============================
			 CONFIGURATION PROPERTIES (instance configuration)
			 =============================
			 */
			
			
			/*
			 =============================
			 CONSTRUCTOR
			 =============================
			 */
				"init" : function (dataDisplayInstanceDetails)
				{
					// Store local reference to data display instances
					
					this._dataDisplayInstances = new Array();
					
					var a = dataDisplayInstanceDetails;
					for (var i = 0; i < a.length; i++)
					{
						var string = a[i][0];
						this._dataDisplayInstances[string] = a[i][1];
					}
					
					
					// Setup
					this._setup();
					
					// Style panel header
					if (sIFR && sIFR.styleAdvancedSettingsPanel)
						sIFR.styleAdvancedSettingsPanel();
				},
			
			
			
			/*
			 =============================
			 INTERNAL RUN-TIME PROPERTIES
			 =============================
			 */
				"_panel_height_open"	: 0,
				
				"_dataDisplayInstances" : undefined,
				
				// Panel persistance array
				"_enabledPanelsNames" : new Array(""),

			/*
			 =============================
			 PUBLIC METHODS
			 =============================
			 */
				"rebind" : function ()
				{
					// If panel !in 2 column mode (i.e. in right hand column) collapse all basic displays
					if (this._basicDisplayCollapsable()) this._collapseAllBasicDisplays();
					
					// Reconfigure open / close links
					this._setupPanelOpenCloseLinks();
					this._setupDisplayOpenCloseLinks();
					
					// Open panels and set height from cookies
//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
					//this._managePanels();
				},
				
				
			
			/*
			 =============================
			 INTERNAL METHODS
			 =============================
			 */
				/*
				 =============================
				 UTILITIES
				 =============================
				 */
					"_isRangeDetailsDisplay" : function () { return ($(this.ID_RANGE_DETAILS).length > 0) ? true : false; },
					
					"_twoColumnDisplayMode" : function ()
					{
						if ($(this.ID_RESULTS_LIST_MODE).length > 0 || this._isRangeDetailsDisplay()) return false; // TODO :: Also return false if on [Range details page]
						return true;
					},
					
					
					"_basicDisplayCollapsable" : function ()
					{
						return !this._twoColumnDisplayMode();
					},
					
					
					"_panelHeight" : function ()
					{
						return parseInt($("div." + this.CLASS_PANEL_ADVANCED_SETTINGS).css("height"));
					},
					
					
					"_getDefaultPanelHeight" : function ()
					{
						var h;
						if (this._twoColumnDisplayMode()) h = this.DEFAULT_PANEL_HEIGHT_2_COLUMN;
						else
						{
							// If results mode list
							if ($(this.ID_RESULTS_LIST_MODE).length > 0) h = this.DEFAULT_PANEL_HEIGHT_1_COLUMN;
							else if (this._isRangeDetailsDisplay()) h = this.DEFAULT_PANEL_HEIGHT_RANGE_DETAILS;
						}
						return h;				
						
						//return (this._twoColumnDisplayMode)? this.DEFAULT_PANEL_HEIGHT_2_COLUMN : this.DEFAULT_PANEL_HEIGHT_1_COLUMN; // TODO :: Account for height on [RangeDetail page]
					},
					
					
					// @param	:	control [ jQuery object ]	: jQuery object for the control container within which we want to find (& return) the standard display
					//											: This MUST be element with class = this.CLASS_CONTROL_CONTAINER
					// @return	:	[ jQuery object ]			: jQuery object for the standard display
					"_getStandardDisplay" : function (control)
					{
						var targetClass;
						
						if (control.hasClass(this.CLASS_SLIDER_CONTAINER))			targetClass = this.CLASS_STANDARD_DISPLAY_SLIDER;
						if (control.hasClass(this.CLASS_RADIOBUTTONLIST_CONTAINER)) targetClass = this.CLASS_STANDARD_DISPLAY_RADIOBUTTONLIST;
						if (control.hasClass(this.CLASS_IMAGELIST_CONTAINER))		targetClass = this.CLASS_STANDARD_DISPLAY_IMAGELIST;
						
						return control.find("." + targetClass);
					},
					
					
					"_setDisplayState" : function (control, scope, state)
					{
						switch (scope)
						{
							case this.SCOPE_STANDARD :
								switch (state)
								{
									case this.STATE_OPEN :
										if (control.hasClass(this.CLASS_STANDARD_DISPLAY_CLOSED)) control.removeClass(this.CLASS_STANDARD_DISPLAY_CLOSED);
										if (!control.hasClass(this.CLASS_STANDARD_DISPLAY_OPEN)) control.addClass(this.CLASS_STANDARD_DISPLAY_OPEN);
										break;
										
									case this.STATE_CLOSE :
										if (control.hasClass(this.CLASS_STANDARD_DISPLAY_OPEN)) control.removeClass(this.CLASS_STANDARD_DISPLAY_OPEN);
										if (!control.hasClass(this.CLASS_STANDARD_DISPLAY_CLOSED)) control.addClass(this.CLASS_STANDARD_DISPLAY_CLOSED);
										break;
									
									default : break;
								}
								break;
								
							case this.SCOPE_EXTENDED :
								switch (state)
								{
									case this.STATE_OPEN :
										if (control.hasClass(this.CLASS_EXTENDED_DISPLAY_CLOSED)) control.removeClass(this.CLASS_EXTENDED_DISPLAY_CLOSED);
										if (!control.hasClass(this.CLASS_EXTENDED_DISPLAY_OPEN)) control.addClass(this.CLASS_EXTENDED_DISPLAY_OPEN);
										break;
										
									case this.STATE_CLOSE :
										if (control.hasClass(this.CLASS_EXTENDED_DISPLAY_OPEN)) control.removeClass(this.CLASS_EXTENDED_DISPLAY_OPEN);
										if (!control.hasClass(this.CLASS_EXTENDED_DISPLAY_CLOSED)) control.addClass(this.CLASS_EXTENDED_DISPLAY_CLOSED);
										break;
									
									default : break;
								}
								break;
							
							default : break;
						}
					},
					
					
					
					"_getDataDisplayClassInstance" : function (jQueryObjectContainer)
					{
						var container	= jQueryObjectContainer;
						var instances	= this._dataDisplayInstances;
						
						var a = this.CLASS_DATA_DISPLAY_CONTAINERS;
						
						for (var i = 0; i < a.length; i++)
						{
							var id = a[i];
							
							if (container.hasClass(id))
							{
								return instances[id];
							}
						}
						return undefined;
					},
					
					
			
				/*
				 =============================
				 SETUP
				 =============================
				 */
					"_setup" : function ()
					{
						// Save current panel height
						var h = $("div." + this.CLASS_PANEL_ADVANCED_SETTINGS).height();
						
						this._panel_height_open = (h == this.PANEL_HEIGHT_CLOSED) ? this._getDefaultPanelHeight() : h;
						
						// Configure panel open / close links
						this._setupPanelOpenCloseLinks();
						
						// Configure display open / close links
						this._setupDisplayOpenCloseLinks();
						
						// If panel !in 2 column mode (i.e. in right hand column) collapse all basic displays
						if (this._basicDisplayCollapsable()) this._collapseAllBasicDisplays();

						// Open panels and set the height from cookies
//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
						//this._managePanels();
						
						//Set up the manufacturer range drop downs for dealer site
						this._setUpManufacturerRangeDropDown();
					},



					// Open flash graphs from cookie
//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//				
//					"_managePanels" : function ()
//					{
//						// Check if open flash graph persistence is switched on
//						if (this.DEFAULT_PANEL_PERSISTENCE)
//						{
//							// Get panels cookie
//							var enabledPanelsNamesString = $.cookie(this.DEFAULT_PANEL_STATE_COOKIE);
//								
//							// Convert the cookie to an array
//							
//							if (enabledPanelsNamesString != null)
//							{
//								this._enabledPanelsNames = enabledPanelsNamesString.split(",");
//								// Walk panels						
//								for (var _iPanelItem = 0; _iPanelItem < this._enabledPanelsNames.length; _iPanelItem++)
//								{
//									if (this._enabledPanelsNames[_iPanelItem] != "")
//									{
//										// Open the panel 
//										$("#" + this._enabledPanelsNames[_iPanelItem] + "_" + this.DEFAULT_PANEL_LINK_OPEN).click();
//									}
//								}
//							}
//						}
//					},


					
					"_setupPanelOpenCloseLinks" : function ()
					{
						var __this = this;
						$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_PANEL_BODY_HEADER + " a." + this.CLASS_OPEN).click(function (e){ __this._openPanel(); });
						$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_PANEL_BODY_HEADER + " a." + this.CLASS_CLOSE).click(function (e){ __this._closePanel(); });
					},
			
					
					"_setupDisplayOpenCloseLinks" : function ()
					{
						var __this = this;
						
						// If this._twoColumnDisplayMode set up extended display open/close links
						// Else set up standard display links + must haves extended display link
						var isRangeDetails = (this._isRangeDetailsDisplay()) ? true : false;
						
						var extendedDisplay = (this._twoColumnDisplayMode() || isRangeDetails) ? true : false;
						
						switch (extendedDisplay)
						{
							case true :
								// Column 1
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_COLUMN_1 + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_OPEN).click(function (){ __this._openDisplay(this, __this.SCOPE_EXTENDED, ((!isRangeDetails)? 1 : 0)); });
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_COLUMN_1 + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_CLOSE).click(function (){ __this._closeDisplay(this, __this.SCOPE_EXTENDED, ((!isRangeDetails)? 1 : 0)); });
								
								// Column 2
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_COLUMN_2 + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_OPEN).click(function (){ __this._openDisplay(this, __this.SCOPE_EXTENDED, ((!isRangeDetails)? 2 : 0)); });
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_COLUMN_2 + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_CLOSE).click(function (){ __this._closeDisplay(this, __this.SCOPE_EXTENDED, ((!isRangeDetails)? 2 : 0)); });
								break;
								
							case false :
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_STANDARD_DISPLAY_CONTROL_OPEN).click(function (){ __this._openDisplay(this, __this.SCOPE_STANDARD, 0); });
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " " + this.ID_MUST_HAVES_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_OPEN).click(function (){ __this._openDisplay(this, __this.SCOPE_EXTENDED, 0); });
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " div." + this.CLASS_CONTROL_CONTAINER + " a." + this.CLASS_STANDARD_DISPLAY_CONTROL_CLOSE).click(function (){ __this._closeDisplay(this, __this.SCOPE_STANDARD, 0); });
								$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS + " " + this.ID_MUST_HAVES_CONTROL_CONTAINER + " a." + this.CLASS_EXTENDED_DISPLAY_CONTROL_CLOSE).click(function (){ __this._closeDisplay(this, __this.SCOPE_EXTENDED, 0); });
								break;
							
							default : break;
						}						
					},
					
					"_setUpManufacturerRangeDropDown" : function ()
					{
							//get our manufacturer select list
							var jqManufacturerSelect = $("#SearchCriteria select.manufacturer");
							//get our model select list.
							var jqRangeSelect = $("#SearchCriteria select.ranges");
							
							if(jqManufacturerSelect.val() == "null")
							{
								jqRangeSelect.attr("disabled" , "disabled");
							}
							
							
							if(jqManufacturerSelect != null)
							{
								jqManufacturerSelect.bind("change" , function()
									{
										var form = $("#SearchCriteria");
										form.trigger("submit");
									}
								)
							}
					},
			
			
			
				/*
				 =============================
				 DISPLAY CREATION
				 =============================
				 */
			
			
			
				/*
				 =============================
				 DISPLAY CONTROL
				 =============================
				 */
					"_collapseAllBasicDisplays" : function ()
					{
						var __this = this;
						// Get all control containers and add 'basic display closed' class and remove and 'extend display open' class
						$("div." + this.CLASS_CONTROL_CONTAINER).each (function ()
						{
							var _item = $(this);
							if (_item.hasClass(__this.CLASS_STANDARD_DISPLAY_OPEN)) _item.removeClass(__this.CLASS_STANDARD_DISPLAY_OPEN);
							if (!_item.hasClass(__this.CLASS_STANDARD_DISPLAY_CLOSED)) _item.addClass(__this.CLASS_STANDARD_DISPLAY_CLOSED);
							if (_item.hasClass(__this.CLASS_EXTENDED_DISPLAY_OPEN)) _item.removeClass(__this.CLASS_EXTENDED_DISPLAY_OPEN);
							if (!_item.hasClass(__this.CLASS_EXTENDED_DISPLAY_CLOSED)) _item.addClass(__this.CLASS_EXTENDED_DISPLAY_CLOSED);
						});
					},
			
					
					"_openPanel" : function ()
					{
						var p = $("div." + this.CLASS_PANEL_ADVANCED_SETTINGS);
						if (p.hasClass(this.CLASS_PANEL_ADVANCED_SETTINGS_CLOSED)) p.removeClass(this.CLASS_PANEL_ADVANCED_SETTINGS_CLOSED);
						
						var body = p.find("div." + this.CLASS_PANEL_BODY_CONTAINER);
						if(body.hasClass(this.CLASS_PANEL_BODY_CONTAINER_CLOSED)) body.removeClass(this.CLASS_PANEL_BODY_CONTAINER_CLOSED);
						if(!body.hasClass(this.CLASS_PANEL_BODY_CONTAINER_OPEN)) body.addClass(this.CLASS_PANEL_BODY_CONTAINER_OPEN);
						
						$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS).height(this._panel_height_open);
					},
					
					
					"_closePanel" : function ()
					{
						var p = $("div." + this.CLASS_PANEL_ADVANCED_SETTINGS);
						p.addClass(this.CLASS_PANEL_ADVANCED_SETTINGS_CLOSED);
						
						var body = p.find("div." + this.CLASS_PANEL_BODY_CONTAINER);
						if(body.hasClass(this.CLASS_PANEL_BODY_CONTAINER_OPEN)) body.removeClass(this.CLASS_PANEL_BODY_CONTAINER_OPEN);
						if(!body.hasClass(this.CLASS_PANEL_BODY_CONTAINER_CLOSED)) body.addClass(this.CLASS_PANEL_BODY_CONTAINER_CLOSED);
						
						$("div." + this.CLASS_PANEL_ADVANCED_SETTINGS).height(this.PANEL_HEIGHT_CLOSED);
					},
					
					
					"_openDisplay" : function (link, scope, columnId)
					{
						//alert("_openDisplay : " + scope + " / col = " + columnId);

						var panel		= $("div." + this.CLASS_PANEL_ADVANCED_SETTINGS);
						var control		= $(link).parent("div." + this.CLASS_CONTROL_CONTAINER);
						var display;
						
						var panelDataDisplayClass = this._getDataDisplayClassInstance(control);
						
						// Current panel height
						var p_h		= panel.height();
						
						// New panel height
						var new_h;
						
						switch (scope)
						{
							case this.SCOPE_STANDARD :
								display		= this._getStandardDisplay(control);
								var d_h		= display.height() + parseInt(display.css("paddingTop")) + parseInt(display.css("paddingBottom")) + parseInt(display.css("borderTopWidth"));
								var c_h		= control.height();
								new_h		= p_h + d_h - c_h; //alert("p_h = " + p_h + "\nd_h = " + d_h + "\nc_h = " + c_h + "\nnew_h = " + new_h);
								this._setDisplayState(control, scope, this.STATE_OPEN);
								break;
							
							case this.SCOPE_EXTENDED :
								var panel_body	= panel.find("div." + this.CLASS_PANEL_BODY_CONTENT);
								var column_1	= panel.find("div." + this.CLASS_COLUMN_1);
								var column_2	= panel.find("div." + this.CLASS_COLUMN_2);
								
								display			= control.find("div." + this.CLASS_EXTENDED_DISPLAY);
								
								if (columnId == 0)
								{
									// Set display state class - occurs mid-calculation so 'open' styles (padding) can be used in next stage of calculation
									this._setDisplayState(control, scope, this.STATE_OPEN);
									
									// Continue with calculation
									var d_h		= display.height() + parseInt(display.css("paddingTop")) + parseInt(display.css("paddingBottom")) + parseInt(display.css("borderTopWidth"));
									new_h		= p_h + d_h;
								}
								else 
								{
									var c_h		= (columnId == 1) ? column_1.height() : column_2.height();
									c_h			+= (parseInt(panel_body.css("paddingTop")) + parseInt(panel_body.css("marginBottom"))); // Add column y position and any container padding to height
									
									// Set display state class - occurs mid-calculation so 'open' styles (padding) can be used in next stage of calculation
									this._setDisplayState(control, scope, this.STATE_OPEN);
									
									// Continue with calculation
									var d_h		= display.height() + parseInt(display.css("paddingTop")) + parseInt(display.css("paddingBottom")) + parseInt(display.css("borderTopWidth"));
									var xs_h	= p_h - c_h;
									var add_h	= Math.max(d_h - xs_h, 0);
									new_h		= p_h + add_h; //alert("p_h = " + p_h + "\nc_h = " + c_h + "\nd_h = " + d_h + "\nxs_h = " + xs_h + "\nadd_h = " + add_h + "\nnew_h = " + new_h);
								}
								
								//
								//
								// CREATE DATA DISPLAY [If range details or 2 column mode]
								//
								//
								if (this._isRangeDetailsDisplay() || columnId != 0)
								{
									if (panelDataDisplayClass)
									{
										try { panelDataDisplayClass.createDisplay(); }
										catch (e){}
									}
								}
								
								
								break;
							
							default : 
								new_h = p_h;
								break;
						}
						
						// Save new overal panel height
						this._panel_height_open = new_h;
						
						// Set new overall panel height
						panel.height(new_h);

//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
//						var aName = $(link).attr("id");
//						var exists = false;
//						// Find panel
//												
//						for (var _openPanelIndex = 0; _openPanelIndex < this._enabledPanelsNames.length; _openPanelIndex++)
//						{
//							if (this._enabledPanelsNames[_openPanelIndex] != "")
//							{
//								if (aName == this._enabledPanelsNames[_openPanelIndex] + "_" + this.DEFAULT_PANEL_LINK_OPEN)
//								{
//									// already included
//									exists = true;
//									break;
//								}
//							}
//						}
//						if (!exists)
//						{
//							// Get in-memory name
//							var name = this._extract(aName)
//							// Push enabled panel into enabled panels array
//							this._enabledPanelsNames.push(name);
//						}
//						// Save cookies
//						this._saveCookies(new_h)
						
					},
					
					// extract value
//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
//					"_extract" : function (aName)
//					{
//						// copy to underscore
//						var nameLen = aName.indexOf('_');
//						
//						var trueName = "";
//						
//						if (nameLen > 1)
//						{
//							trueName = aName.substr(0, nameLen);
//						}
//						return trueName;
//					},
					
					"_closeDisplay" : function (link, scope, columnId)
					{
						//alert("_closeDisplay : " + scope + " / col = " + columnId);
						
						var panel		= $("div." + this.CLASS_PANEL_ADVANCED_SETTINGS);
						var control		= $(link).parent("div." + this.CLASS_CONTROL_CONTAINER);
						var display;
						
						// Current panel height
						var p_h	= panel.height();
						
						// New panel height
						var new_h;
						
						switch (scope)
						{
							case this.SCOPE_STANDARD :
								this._setDisplayState(control, scope, this.STATE_CLOSE);
								display		= this._getStandardDisplay(control);
								var d_h		= display.height() + parseInt(display.css("paddingTop")) + parseInt(display.css("paddingBottom")) + parseInt(display.css("borderTopWidth"));
								var c_h		= control.height();
								new_h		= (p_h - d_h) + c_h;
								break;
							
							case this.SCOPE_EXTENDED :
								var panel_body	= panel.find("div." + this.CLASS_PANEL_BODY_CONTENT);
								var column_1	= panel.find("div." + this.CLASS_COLUMN_1);
								var column_2	= panel.find("div." + this.CLASS_COLUMN_2);
								
								var additionalColumn_h	= (parseInt(panel_body.css("paddingTop")) + parseInt(panel_body.css("marginBottom")));
								
								var col1_h	= column_1.height() + additionalColumn_h;
								var col2_h	= column_2.height() + additionalColumn_h;
								
								display		= control.find("div." + this.CLASS_EXTENDED_DISPLAY);
								var d_h		= display.height() + parseInt(display.css("paddingTop")) + parseInt(display.css("paddingBottom")) + parseInt(display.css("borderTopWidth"));
								
								if (columnId == 0)
								{
									// No column checking required so just set remove display height
									new_h = p_h - d_h;
								}
								else 
								{
									// Is current column the column that is controlling overall panel height
									var colControllingHeight = false;
									var column_primary_h;
									var column_secondary_h;
									
									if (columnId == 1)
									{
										colControllingHeight	= (col1_h > col2_h)? true : false;
										column_primary_h		= col1_h;
										column_secondary_h		= col2_h;
									}
									else if (columnId == 2)
									{
										colControllingHeight	= (col2_h > col1_h)? true : false;
										column_primary_h		= col2_h;
										column_secondary_h		= col1_h;
									}
									
									if (!colControllingHeight) new_h = p_h; 
									else
									{
										var calc_new_h = column_primary_h - d_h;
										if (calc_new_h < column_secondary_h)
										{
											var max_reduction_h = column_primary_h - column_secondary_h;
											calc_new_h			= column_primary_h - max_reduction_h;
										}
										new_h = calc_new_h; //alert(" p_h = " + p_h + "\n new_h = " + new_h + "\n d_h = " + d_h + "\n col1_h = " + col1_h + "\n col2_h = " + col2_h + "\t column_primary_h = " + column_primary_h + "\n column_secondary_h = " + column_secondary_h);
									}
								}
								
								this._setDisplayState(control, scope, this.STATE_CLOSE);
								break;
							
							default : 
								new_h = p_h;
								break;
						}
						
						if (new_h != p_h)
						{
							// Save new overal panel height
							this._panel_height_open = new_h;
							
							// Set new overall panel height
							panel.height(new_h);
						}

//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
//						var aName = $(link).attr("id");
//						var exists = -1;
//						
//						// Find panel
//						for (var _closePanelIndex = 0; _closePanelIndex < this._enabledPanelsNames.length; _closePanelIndex++)
//						{
//							if (this._enabledPanelsNames[_closePanelIndex] != "")
//							{
//								if (aName == this._enabledPanelsNames[_closePanelIndex] + "_" + this.DEFAULT_PANEL_LINK_CLOSE)
//								{
//									// already included
//									exists = _closePanelIndex;
//									break;
//								}
//							}
//						}
//						if (exists > -1)
//						{
//							// remove from array list using splice (as pop method does not work)
//							this._enabledPanelsNames.splice(_closePanelIndex, 1);
//						}
//						// Save cookies
//						this._saveCookies(new_h);

					}
			
					// Saves cookies for open states and panel height
//
// DISABLED :: MECHANISM LOGIC FLAWED (Panel state history)
//
//					"_saveCookies" : function (new_h)
//					{
//						// Pack array in string
//						var cookieNames = this._enabledPanelsNames.join();
//						
//						// Save cookie
//						$.cookie(this.DEFAULT_PANEL_STATE_COOKIE, cookieNames, { expires: 7, path: "/" });
//						
//						// Save height for the panel in the cookie 						
//						$.cookie(this.CLASS_PANEL_ADVANCED_SETTINGS + this.DEFAULT_PANEL_HEIGHT_COOKIE, new_h, { expires: 7, path: "/" });												
//					}			
			
				/*
				 =============================
				 INTERNAL EVENT HANDLERS
				 =============================
				 */
				
				
		}
	);
	
	//alert("hellooooooooooooooooooooooooooo");
