$(document).ready(function(){ initTabs (); $('.description-btn a').click(function(e){ $(this).closest('li').addClass('active').siblings().removeClass('active'); e.preventDefault(); }).closest('li').find('.description .close-btn').click(function(e){ $(this).parents('li').removeClass('active'); e.preventDefault(); }); var main=$('#main'), mainBottom=main.offset().top+main.height(); $('.description').each(function(){ $(this).css('visibility','hidden').show(); var bottom=$(this).offset().top+$(this).height(); if(bottom>mainBottom) $(this).addClass('bottom'); $(this).removeAttr('style'); }); $(document).click(function(e){ if(!$(e.target).closest('.description-btn').size() && !$(e.target).closest('.description').size()){ $('.catalog li').removeClass('active'); } }); }); function initTabs () { $('.tabset').makeTabset({ tab : '.tab', control : '.tab-control', parent : '.tabset' }); } (function($) { $.fn.makeTabset = function(o) { o = $.extend( { tab : '.tab', control : '.tabcontrol', parent : '.tabset' }, o || {}); $(this).each( function() { tabset_holder = $(this); tabset_holder.find(o.control + ' li').each(function(){ $(this).find('a').attr('href','tab'+($(this).index()+1)); }); var index = 1; tabset_holder.find(o.tab).each(function(){ $(this).addClass('tab'+index); index += 1; }); tabset_holder.find(o.control + ' li a').bind('click',function(){ if (!$(this).parent().is('.active')) { $(this).parents(o.parent).find(o.control + ' .active').removeClass('active'); $(this).parents(o.parent).find(o.tab).hide(); $(this).parent().addClass('active'); $(this).parents(o.parent).find(o.tab + '.' + $(this).attr('href')).show(); } return false; }); }); }; })(jQuery);