/**
 * Small Search Form Javascript
 */

var originalSmallSearchFormAction = '';



/**
 * Gives menu items which represent a link to the current page a class of
 * "currentItem".
 */
jQuery(function($) {
	
	var url = document.location.href;

	if (url.substr(-1, 1) == '/'){
		url = url.substr(0, (url.length - 1));
	}

	// @TODO: Add in a fix for finding the current URL for links that are using /site/path instead of http://www.example.com/site/path
	url = url.replace(iwp_global_siteurl, '');

	if (url == '') {
		url = iwp_global_siteurl + '/';
	}

	// jcw - add ability to keep main nav SECTION highlighted
	var siteSection = url.split("/");
	var siteUrl = '/' + siteSection[1];
	
	if (siteUrl != '/') {
		$('.tplIsCurrentItem:has(>a[href^='+siteUrl+'])').addClass('maincurrentItem');
	}
	// jcw - end
	
	$('.tplIsCurrentItem:has( > a[href$=' + url + '])').addClass('currentItem');
	$('.tplIsCurrentItem:has( > a[href$=' + url + '/])').addClass('currentItem');
	
});



/**
 * Variable handlers.
 */

var iwp = {};

iwp.Vars = function () {
	var self = this;

	self.vars = {};

	/**
	 * Retrieves a given variable.
	 * 
	 * @param string name The name of the variable to get.
	 * 
	 * @return mixed
	 */
	self.get = function (name) {
		if (typeof self.vars[name] == 'undefined') {
			return '[Undefined JS Variable: ' + name + ']';
		}

		return self.vars[name];
	};

	/**
	 * Sets a given variable.
	 * 
	 * @param string name The name of the variable to set.
	 * @param mixed  val  The value to give the variable.
	 * 
	 * @return iwp.Vars
	 */
	self.set = function (name, val) {
		if (typeof(name) == 'object') {
			for (i in name) {
				self.vars[i] = name[i];
			}

		} else {
			self.vars[name] = val;
		}
		
		return self;
	};
};

iwp.lang   = new iwp.Vars();
iwp.config = new iwp.Vars();
