(function($){$.fn.tabbedbox=function(){var $contents=$(this).find('.tabbedbox_content'),$tabs=$(this).find('.navigation li a');function show_tab($tab){$contents.hide();$tabs.removeClass('active');$tab.addClass('active');$contents.filter('.'+$tab.attr('href').replace(/^#/,'')).show();}
return this.each(function(){show_tab($tabs.filter(':eq(1)'));$tabs.click(function(){show_tab($(this));return false;});$(this).find('.tabbedbox_content').tabbedbox_carousel();});};$.fn.tabbedbox_carousel=function(){return this.each(function(){var $self=$(this),$wrapper=$self.find('> .wrapper').css('overflow','hidden'),$slider=$wrapper.find('> ul'),currentPage=0,json_url="/ajax/tabbedbox/",oid=$self.attr('id').split("_")[3],tid=$self.attr('id').split("_")[2];if($slider.find('> li:first').length==0)
return;function gotoPage(page){var dir=page<currentPage?1:-1,singleWidth=$slider.find('> li:first').outerWidth(),visible=Math.floor($wrapper.innerWidth()/singleWidth);$.getJSON(json_url+'page/'+oid+'/'+tid+'/'+page,function(data){var $last_append,inserted=0,left;jQuery.each(data.pids,function(){var pid=this;var $element=$('<li/>').each(function(){$(this).addClass('tabbedbox_loader');var $helper=$(this);$.getJSON(json_url+'product/'+pid,function(product){$helper.removeClass('tabbedbox_loader');$helper.html(product);});});if(dir==-1)
$slider.append($element);else{if($last_append)
$last_append.after($element);else
$slider.find('> li:first').before($element);$last_append=$element;inserted++;$slider.css('left',(inserted*singleWidth*-1)+'px');}});if(dir==-1)
left=singleWidth*visible*dir;else
left=0;add_draggable();$slider.filter(':not(:animated)').animate({left:left+'px'},1500,function(){if(dir==-1)
$slider.find('> li:lt('+visible+')').remove();else
$slider.find('> li:gt('+(visible-1)+')').remove();$slider.css('left',0);currentPage=page;});});return false;}
$.getJSON(json_url+'hasmore/'+oid+'/'+tid,function(data){if(data==1){$('<a/>').addClass('arrow back').insertAfter($wrapper).click(function(){return gotoPage(currentPage-1);});$('<a/>').addClass('arrow forward').insertAfter($wrapper).click(function(){return gotoPage(currentPage+1);});}});});};})(jQuery);