

/// <reference path="../../../../jQuery/1.3.2/jquery-1.3.2-vsdoc.js" />

// ********************************************************************
// 
// Manheim Retail Services Marketing
// ********************************************************************
// Copyright © 2010 Manheim Retail Services Marketing.
//
//  Summary
// ******************************
//
// File History Information
// ************************				
// Original Author:					Liam Prescott
//
// ********************************************************************


	// Check / create namespace
	if (!manheim.global.isNamespaceDefined("manheim.rsm.classLibrary"))
	{
		manheim.global.createNamespace("manheim.rsm.classLibrary", "1.0");
	}


	// Class definition
	manheim.rsm.classLibrary.CoreFunctionality = Object.subClass
	(
		{
		
			/*
			=============================
			CONSTANTS
			=============================
			*/
				"CLASS_" : "",
				
				"CLASS_FRAGMENT_DISPLAY_STATE" : "display-state-",
				
				
				/*
				-----------------------
				CONTACT FORM
				-----------------------
				*/
					"TARGET_CC" 				: "#contact-container",
					"TARGET_C" 					: "#contact",
					"TARGET_CC_CONTROL_LINK" 	: "#open-contact-container",
					
					"CC_HEIGHT_CLOSED" 		: 6,
					"CC_HEIGHT_OPEN" 		: 246,
					"CC_SHOW_ANIM_RATE_PP" 	: 3,
					
					"CLASS_CC_OPEN" 		: "open",
				
				
				/*
				-----------------------
				DEFOCUS OVERLAY
				-----------------------
				*/
					"TARGET_DO" : "#defocus-overlay",
				
				
				/*
				-----------------------
				PRODUCTS MENU
				-----------------------
				*/
					"CLASS_MENU_ROOT_NODE" : "menu-root",
					
					"TARGET_PM" : "#products-menu",
				
					"TARGET_PM_HOVER_TARGET" : "ul > li:not(ul > li li)",
					
					"CLASS_PM_DISPLAY_STATE_ACTIVE" : "pm-display-state-active",
			
			/*
			=============================
			CONSTRUCTOR
			=============================
			*/
				"init" : function ()
				{
					this._setupContactForm();
					this._setupProductsMenu();
					
					//Activate sifr styling
					sIFR.replaceCoreAssets();
				},
			
			/*
			=============================
			PUBLIC MEMBERS
			=============================
			*/
			
			
			/*
			=============================
			PRIVATE MEMBERS
			=============================
			*/
				/*
				=============================
				SETUP METHODS
				=============================
				*/
					"_setupContactForm" : function ()
					{
						var __this = this;
						
						// Get open / close link and add event handler
						var link = $(this.TARGET_CC_CONTROL_LINK);
						link.click(function (e){ __this.handleContactFormShow(); })
					},
					
					
					"_setupProductsMenu" : function ()
					{
						var __this = this;
						
						//Find menu
						var menu = $(this.TARGET_PM);
						
						//Find and add hover to hover targets
						var links		= menu.find(this.TARGET_PM_HOVER_TARGET);
						var totalLinks	= links.length;
						
						
						links.each(
						   function (i)
						   {
								var link = $(this);
								link.hover(
									function (e)
									{
										__this._handleProductMenuItemOver(i, menu, totalLinks);
									},
									function (e)
									{
										__this._handleProductMenuItemOut(i, menu, totalLinks);
									}
								);
						   }
						);
						
						
					},
				
				
				/*
				=============================
				EVENT HANDLERS
				=============================
				*/
					"handleContactFormShow" : function ()
					{
						// Get form container and determine current state to determine whether to open or close
						var container = $(this.TARGET_CC);
						
						var show = (!container.hasClass(this.CLASS_CC_OPEN))? true : false;
						
						this.showContactForm(container, show);
					},
					
					
					"handleShowContactComplete" : function (show, defocusOverlayJQO)
					{
						//alert("complete : -- show = " + show);
						//If hide then remove defocus overlay
						if (show) return;
						
						this._hideDefocusOverlay(defocusOverlayJQO);
					},
					
					
					"_handleProductMenuItemOver" : function (id, menu, totalLinks)
					{
						//Remove all display state classes
						this._clearAllDisplayStates(menu, totalLinks);
						//Create new display state class
						var c = this.CLASS_PM_DISPLAY_STATE_ACTIVE + " " + this.CLASS_FRAGMENT_DISPLAY_STATE + id;
						//Add class
						menu.addClass(c);
					},
					
					
					"_handleProductMenuItemOut" : function (id, menu, totalLinks)
					{
						this._clearAllDisplayStates(menu, totalLinks, this.CLASS_PM_DISPLAY_STATE_ACTIVE);
					},
				
				
				
				/*
				=============================
				DISPLAY MANIPULATION METHODS
				=============================
				*/
					"showContactForm" : function (targetJO, show)
					{
						var __this = this;
						
						var t = targetJO
						
						//Stop any animation currently running
						t.stop();
						
						//Retrive height values
						var h 	= t.height();
						var h2	= (show)? this.CC_HEIGHT_OPEN : this.CC_HEIGHT_CLOSED;
						
						//Calculate calibrated duration
						var duration = this.CC_SHOW_ANIM_RATE_PP * Math.abs(h2 - h);
						
						//Get body height and width
						var b = $("body");
						var d = $(this.TARGET_DO);
						
						
						//Add / remove open class to container
						//If show ensure defocus overlay height and width set
						if (show)
						{
							t.addClass(this.CLASS_CC_OPEN);
							
							var bh = b.height();
							var bw = b.width();
							
							d.height(bh);
							d.width(bw);
						}
						else
							t.removeClass(this.CLASS_CC_OPEN);
						
						// If ie 6 just set heights with no animation
						if ($.browser.msie && $.browser.version < 7 )
						{
							//Get internal contact form and set height
							var c = t.find(this.TARGET_C);
							c.height(h2);
							t.height(h2);
							if (!show) this._hideDefocusOverlay(d);
							}
						else
							//Run animation
							t.animate({"height" : h2}, duration, "easeInOutCubic", function (){ __this.handleShowContactComplete(show, d) });
						
						
					},
					
					
					"_clearAllDisplayStates" : function (target, totalStates, additionalClasses)
					{
						var i;
						var t 	= target;
						var j 	= totalStates;
						var cf 	= ((additionalClasses) ? additionalClasses : "") + " " + this.CLASS_FRAGMENT_DISPLAY_STATE;
						
						for (i = j-1; i >= 0; i--)
						{
							var c = cf + i;
							target.removeClass(c);
						}
					},
					
					
					
					"_hideDefocusOverlay" : function (defocusOverlayJQO)
					{
						defocusOverlayJQO.height(0);
						defocusOverlayJQO.width(0);
					},
				
				
				
				/*
				=============================
				UTILITY METHODS
				=============================
				*/
					
					"pageHeight" : function ()
					{
						
					}
					
					
				
			
		}
	);