/*
 * rrTabs 1.0.0 - Tabs by Reading Room
 *
 * Copyright (c) 2009 Reading Room Ltd (readingroom.com)
 * Written by Keng Jin Chew (keng.jin@readingroom.com) 
 */
(function($){ $.fn.rrtabs = function(param){
	
	var param = $.extend({
		ActiveClass: 'on',
		List: '.jsTabsList',
		Content: '.jsTabsContent',
		ScrollClass: '.jsScrollPane'
	}, param);

	// Loop through each in case there are multiple selected
	return $(this).each(function(){
		var that = $(this),
			hasScroll = param.ScrollClass && 0 < $(param.ScrollClass).length;
		
		// Set scroll on content area
		if (hasScroll){
			that.find(param.Content).css({'height':'291px','overflow':'auto'});
			//$(param.ScrollClass).css({'width':'auto', 'height':'auto','padding-right':'20px'}); // style hacks
			$('.jScrollPaneContainer').css({'width':'auto'}); // style hacks
		}
		
		// Show first tab, hide the rest
		that.find(param.Content + " div[id*='tab']").hide();
		that.find(param.List + ' li').removeClass(param.ActiveClass);

		// Bind tab click events
		that.find(param.List + ' a').each(function(i){
			$(this).click(function(){

				// Set tab states				
				that.find(param.List + ' li').removeClass(param.ActiveClass);
				$(this).parent().addClass(param.ActiveClass);
				
				// Show content
				that.find(param.Content + " div[id*='tab']").hide().eq(i).show();
				
				// Activate scroll bar styling
				if (hasScroll && 'function' == typeof $.fn.jScrollPane){
					$(param.ScrollClass).jScrollPane({
						showArrows: true,
						scrollbarWidth: 15,
						scrollbarMargin: 0,
						arrowSize: 15,
						dragMinHeight: 38,
						dragMaxHeight: 38
					});
				}
		
				return false;
			});
		});
		
		that.find(param.List + ' a:eq(0)').click();
	});

}})(jQuery);

$(document).ready(function(){
	$('.jsTabsContainer').rrtabs();
	$('.eStoresListing ul.featureList li div.inner').show();
});