jQuery(document).ready(setupInlineLabel);
jQuery(document).ready(setupLinkBlockHover);
jQuery(document).ready(equalizeFooterBlocks);
jQuery(document).ready(setupStylishSelect);
jQuery(document).ready(setupVisualScroll);

function setupVisualScroll() {
   var $root = jQuery('.visualscroller');

   if ($root.length > 0) {
      var offerScroller = new AutoScroll({
         rootelement: $root,
         animationtime: 1000,
         waittime: 6500,
         direction: 'horizontal',
         onscrollend: function (block, index) {
            $('.vf_link').html(block.attr('title'));
            $('.vf_link').attr('href', block.attr('href'));
         }
      });
   }
}

function setupInlineLabel() {
   var inlineLabels = jQuery('.ff_inlinelabel label');
   var inlineFields = jQuery('.ff_inlinelabel input');

   inlineFields.each(function () {
      if (this.value != '') {
         jQuery(this).prev().hide();
      }
   });
   inlineFields.focus(function () {
      jQuery(this).prev().fadeOut(100);
   });
   inlineFields.blur(function () {
      if (this.value.trim() == '') {
         jQuery(this).prev().fadeIn(700);
      }
   });
    //IE compat, since transparency is click-through
   inlineFields.click(function () {
      jQuery(this).prev().fadeOut(100);
   });

   inlineLabels.click(function () {
      jQuery(this).fadeOut(100);
      jQuery(this).next().focus();
   });
}

function setupLinkBlockHover() {
   var $ = jQuery;

   $('.linkblock').hover(
      function () {
         var $top = $('.lb_top', this);
         var $bottom = $('.lb_bottom', this);

         $(this).addClass('lb_hover');
         $top.attr('src', $top.attr('src').replace('.png', '_hover.png'));
         $bottom.attr('src', $bottom.attr('src').replace('.png', '_hover.png'));
      },
      function () {
         var $top = $('.lb_top', this);
         var $bottom = $('.lb_bottom', this);

         $(this).removeClass('lb_hover');
         $top.attr('src', $top.attr('src').replace('_hover', ''));
         $bottom.attr('src', $bottom.attr('src').replace('_hover', ''));
      }
   );
}

function equalizeFooterBlocks() {
   $('.footerblock').css('min-height', $('.footerblocks').height());
}

function setupStylishSelect() {
   $('select.stylish_select').sSelect({ddMaxHeight: '500px', onTop: false });
}
