/********************************************************************

	Sbuk.Accordion Object
		- Sidebar Accordion Menu script for Smartbag UK
		
	LM: 01-13-10
	@author Rafael G.

*********************************************************************/
jQuery(function ($) {
window.Sbuk = window.Sbuk || {};
window.Sbuk.Accordion = (function ($) {
	
	var w = window,
		undef,
		uri = w.location.href,
		$acc = $('#bags-accordion');
		
	var __checkURI = function () {
		var page = Ttow.Util.basename(uri) || '',
			parent = '#-none-';
		if (uri.indexOf('bags/non-woven/') !== -1) {			
			parent = '#acc-non-woven';
		}
		else if (uri.indexOf('bags/non-woven-laminated/') !== -1) {			
			parent = '#acc-non-woven-laminated';
		}
		else if (uri.indexOf('bags/woven/') !== -1) {			
			parent = '#acc-woven';
		}
		else if (uri.indexOf('bags/rpet/') !== -1) {			
			parent = '#acc-rpet';
		}
		else if (uri.indexOf('bags/other/') !== -1) {			
			parent = '#acc-other';
		}
		
		return {
			parent : parent,
			child : page
		}		
	};	
	
	var populateAccr = function () {
		// depends on the navigation menu(p7) for the list of links	//
		$('#navsub_434289_263409').find('li').each(function () {
			var $pLi = $(this),
				cat = $.trim($pLi.find('a').text().toLowerCase()),
				list = '',
				ref = __checkURI(),				
				$ul = $pLi.find('ul');			
			if ($ul.length > 0) { 
				list = '<ul>' + $ul.html() + '</ul>';
			}
			
			if (cat.indexOf('non-woven bags') !== -1) {
				if (ref.parent === '#acc-non-woven') {
					$('#acc-non-woven').find('div.prod_nav_list').hide().html(list).slideDown('fast');
				}							
			}
			else if (cat.indexOf('laminated bags') !== -1) {				
				if (ref.parent === '#acc-non-woven-laminated') {
					$('#acc-non-woven-laminated').find('div.prod_nav_list').hide().html(list).slideDown('fast');
				}	
			}
			else if (cat.indexOf('woven bags') !== -1) {				
				if (ref.parent === '#acc-woven') {
					$('#acc-woven').find('div.prod_nav_list').hide().html(list).slideDown('fast');
				}	
			}
			else if (cat.indexOf('rpet bags') !== -1) {				
				if (ref.parent === '#acc-rpet') {
					$('#acc-rpet').find('div.prod_nav_list').hide().html(list).slideDown('fast');
				}	
			}
			else if (cat.indexOf('other bags') !== -1) {				
				if (ref.parent === '#acc-other') {
					$('#acc-other').find('div.prod_nav_list').hide().html(list).slideDown('fast');
				}	
			}
			else {
				return true;
			} 			
		});		
	};
	
	var __doAccr = function () {
		var ref = __checkURI(),
			$pMenu = $(ref.parent);
		populateAccr();				
		if ($pMenu.length <= 0) { return; }		
		$pMenu.addClass('selected');
	};
	
	return {
	
		init : function () {
			__doAccr();
		}
		
	};
	
})(window.jQuery);

Sbuk.Accordion.init();

});

