jQuery(function(){
    
    Cufon.replace('.replace-obl', {fontFamily: 'WorstveldSlingExtraOblique', hover: true});
    Cufon.replace('.replace-bobl', {fontFamily: 'WorstveldSlingBoldOblique', hover: true});
    
    $('UL', 'UL#main-nav').each(function(){//sub menu alignment
        $(this).css({left: '+=' + (20 + $(this).parent('LI').width() / 2)});
    });

    $('.tab-box').each(function(){
        var $content = $('.tab-content', this),
            $tabs = $('UL.tabs', this);
        
        $('A', $tabs).click(function(){
            $content.load($(this).prop('href'));
            $('.current', $tabs).removeClass('current');
            $(this).parent('li').addClass('current');
            return false;
        }).eq(0).click();
    });
    
    //Image rotator
   $('.slider-box').each(function(){
       var $slider = $(this),
           $slides = $('UL LI', $slider).css({opacity: 0}),
           s_num = $slides.length,
           $nav = $('<ul/>').addClass('nav'),
           $caption = $('H3', this),
           $active = $();
           
       
       $slides.each(function(i){
           var $slide = $(this);
           
           $('img', this).width($slider.width());
           $nav.append('<li/>');
           
           if (i == s_num - 1) {
               $('li', $nav).click(function(){
                   if ( ! $(this).hasClass('active')) {
                       $('LI.active', $nav).removeClass('active');
                       $(this).addClass('active');
                       if ($active.length) {
                           $active.stop(true, false).fadeTo(500, 0, function(){
                               $(this).css({zIndex: 0});
                           });                           
                       }
                       $active = $slides.eq($(this).index()).css({zIndex: 1}).stop(true, false).fadeTo(500, 1); 
                       var capt_html = $('.caption', $active).html();
                       
                       if (capt_html) {
                           $caption.show().prop('class', $active.prop('class')).html(capt_html);
                       } else {
                           $caption.hide();
                       }
                       
                   }
               }).eq(0).click();
               $slider.append($nav);
           }
       });
    });
    
    if ($.browser.opera) {//Opera fix
        $('.replace-obl, .replace-bobl').css('padding-top', '+=4px');
        $('UL.tabs LI SPAN').css('top', '-=4px');
    }
  
      if ($.browser.safari) {//Safari fix
        $('.replace-obl, .replace-bobl').css('padding-top', '+=4px');
        $('UL.tabs LI SPAN').css('top', '-=4px');
    }
    
    $('UL').each(function(){//ie fix
        $('LI', this).filter(':last').addClass('last-child');
    });
}); 
  

