/**
 *	[x+1] JavaScript Utilities
 * 
 * 	(c) 2009 x+1 Inc. - all rights reserved
 * 	http://www.xplusone.com
 * 
 *  $Id: xplusone.utils.js 21 2009-09-29 18:31:45Z hieronymus $
 */
 
/**
 * Create Namespace
 */
var XPLUSONE = {};

/**
 * Navigation
 * 
 * @author shinjuku
 * @version $Rev$
 */
XPLUSONE.navigation = function () 
{

	var container 	= '';
	var children	= [];
	
/**
 * Swaps image name in SRC attr
 * @private
 */	
	toggle_image = function(element, state)
	{
		if ($(element).find('img').attr('class') !== 'nav_select')
		{
			imgsrc = $(element).find('img').attr('src').split('_');
			imgsrc[imgsrc.length - 1] = state + ".png";
			imgsrc = imgsrc.join('_');			
			$(element).find('img').attr('src', imgsrc);
		}

	};
	
/**
 * Derives rollover image id from calling id and toggles display
 * @private
 */	
	toggle_product_rollover = function(parent, state)
	{
		var parent_id = parent.id.split('_');
		var root_id = parent_id.slice(1,parent_id.length);
		var target_name = ['#rollover'];
		var target_id = target_name.concat(root_id).join('_');
		
		if (state == 1)
		{
			$(target_id).show();
		}
		else
		{
			$(target_id).hide();
		}
	};
	

/**
 * PUBLIC METHODS
 */
	return  {
	
	/**
	 * Instantiates rollover state for top nav
	 */	
		init_nav_rollovers : function (c)
		{
			children = $(c + ' li a');

			children.each(function(i)
			{			
				$(this).hover(			
					// Over
					function()
					{
						toggle_image(this, 'on');
					},

					// Out
					function()
					{
						toggle_image(this, 'off');
					}			
				)
			});
		},
		
	/**
	 * Instantiates hover state for product images
	 */
		init_product_rollovers : function(classname)
		{
			$(classname).each(function(i){

				$(this).hover(

					function()
					{
						toggle_product_rollover(this, 1);
					},

					function()
					{
						toggle_product_rollover(this, 0);
					}

				);

			});
		}
		
	};

}(); 