$(document).ready(function(){
    $('div.fancy-bibs').each(function(){
        var thisFancyBibs = this;
        // handle tab click
        $(this).find('ul.left a,ul.right a').click(function(){
            var imgBackgroundPosition = $(this).find('img:first').css('backgroundPosition');
            try{
                imgBackgroundPosition = imgBackgroundPosition.split(' ');
            }catch(e){
                // for IE
                imgBackgroundPosition = $(this).find('img:first').css('backgroundPositionX') + ' ' + $(this).find('img:first').css('backgroundPositionY');
                imgBackgroundPosition = imgBackgroundPosition.split(' ');
            }
            
            
            // remove selected tab styling
            $('div.fancy-bibs ul.left li, div.fancy-bibs ul.right li').removeClass('cur');
            $('div.fancy-bibs ul.left li img, div.fancy-bibs ul.right li img').each(function(){
                var imgBackgroundPosition = $(this).css('backgroundPosition');
                try{
                    imgBackgroundPosition = imgBackgroundPosition.split(' ');
                }catch(e){
                    // for IE
                    imgBackgroundPosition = $(this).css('backgroundPositionX') + ' ' + $(this).css('backgroundPositionY');
                    imgBackgroundPosition = imgBackgroundPosition.split(' ');
                }
                $(this).css({backgroundPosition: '-48px ' + imgBackgroundPosition[1]}); 
            });
            
            // add slected tab styling to clicked tab
            $(this).closest('li').addClass('cur');
            $(this).find('img:first').css({backgroundPosition: '0px ' + imgBackgroundPosition[1]});
            
            // scroll content
            var hash = $(this).attr('href').split('#');
            try{
                hash = hash[1];
            }catch(e){
                hash = '';
            }
            $(thisFancyBibs).find('ul.fancy-bibs-content-list:first').scrollTo('li.fancy-bibs-bibs-content-' + hash, 500);
        });
        
        $('div.fancy-bibs ul.left li.cur, div.fancy-bibs ul.right li.cur').eq(0).find('a').click();
        
        // remove links
        //$(this).find('ul.left a,ul.right a').attr({href:'javascript:void(0);'});
    });
});
