/// <reference path="C:\References\jquery-1.4.1-vsdoc.js" />

// ********************************************************************
// 
// Manheim Retail Marketing
// ********************************************************************
// Copyright © 2010 Manheim Retail Marketing.
//
//  Summary
// ******************************
// $Workfile: BaseClass.js $
// Notes:
//
// File History Information
// ************************
// Created on:					    
// Last Modified:					$Modtime: 23/09/10 11:56 $
// Original Author:					Liam Prescott
// Last Modified by:				$Author: Prescottl $
// Last JS Lint:					
//
// Source Control Information
// **************************
// File Version:					$ $
// VSS Location:					$Archive: /Manheim.Portfolio/Manheim.Portfolio.Web.UI.Client.Assets/assets/js/mrm/lib/core/1.0/BaseClass.js $
//
// ********************************************************************


// Check / create namespace
if (!mrm.global.isNamespaceDefined("mrm.lib.core"))
{
	mrm.global.createNamespace("mrm.lib.core", "1.0");
}


// Class definition
mrm.lib.core.BaseClass = Object.subClass
({
	
	/*
	=============================
	CONSTANTS
	=============================
	*/



	/*
	=============================
	CONSTRUCTOR
	=============================
	*/
	"init" : function () {},

	
	
	/*
	=============================
	PUBLIC PROPERTIES
	=============================
	*/
	
	

	/*
	=============================
	PUBLIC methods
	=============================
	*/
	
	/* Setup methods */
		
		// Root 'setup' method called to configure associated html control
		//
		// @param [strTarget] : jqTargetString used to find html elements
		// @param [objSettings]
		"setup" : function (strTarget, objClassSettings, objInstanceSettings)
		{
			var __this = this;
			
			// Override any 'class' constants/settings as required (these WILL NOT be reset)
			// Override any 'instance' constants/settings as required (these WILL be reset)
			var sC = objClassSettings;
			var sI = objInstanceSettings;
			// Default 'class' settings storage
			var d;
			if (sC) { this._setProperties(sC); }
			if (sI) { d = this._setProperties(sI); }
			
			// If a valid targeting string has been supplied 
			if(strTarget && strTarget.length > 0)
			{
				// Resolve targets
				var items = $(strTarget);
				// Run setup for each item
				items.each(function (){ __this._setup(strTarget, $(this)); });
			}
			
			// Restore default settings
			if (sI) { this._setProperties(d); }
		},

	
	
	/*
	=============================
	PRIVATE PROPERTIES
	=============================
	*/
		
		
		
	/*
	=============================
	PRIVATE METHODS
	=============================
	*/
			
	/* Setup methods */
	
		// [Abstract method]
		// This method should be override in all subClasses as a start point in the setup process
		//
		// @param [strTarget]	: jqTargetString used to find/return 'jqTarget'
		// @param [jqTarget]	: Target jQuery Element
		"_setup" : function (strTarget, jqTarget) { },

		
	/* Event handlers */
	
	/* Display manipulation */
	
	/* Utility methods */
		
		// Sets internal properties and returns an object containing any properties updated and their original values
		//
		// @param [objSettings] : Object containing properties to override and associated values e.g. { "PROP_1" : true, "PROP_2" : "string", "PROP_3" : [], "PROP_4" : {},  }
		// @param [objCurrent]	: Object in which to store 'current' settings (if not supplied then an empty object is auto created)
		//
		// @return [Object]	: Current settings
		"_setProperties" : function (objSettings, objCurrent)
		{
			var s = objSettings;
			var c = (objCurrent) ? objCurrent : {};
			
			// Override class settings (if they exist) with those supplied and store current settings
			for (prop in s)
			{
				if (prop in this)
				{
					// Store current property setting
					c[prop] = this[prop];
					
					// Change our instance property value to the property value on provided settings
					this[prop] = s[prop];
				}
			}
			// Return object containing current properties
			return c;
		}
		
		
});

