/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/
jQuery(function ($) {
  
  var rnd = new Date().getTime();
  $( 'body' ).addClass( 'js-present' );
  $.each( $.browser, function(a,b){ $('body')[(b === true) ? 'addClass' : 'removeClass'](a); });

  // mark first-pulldown
  $('.article .pull:first').addClass('top-pull');


  // front page banner toggler
  if ( $.cookie ) {
    $('a#bannertoggler').bind('click', function () {
      var banner = $('#attract-mode div.body'), btn = $( this );
      if ( banner.is(':visible') ) {
        banner.hide();
        $('body').removeClass('with-banner');
        $( this ).text( btn.attr('data-show-text') ).trigger('blur');
        $.cookie('banner_visible', '0', { expires: 365, path: '/' });
      }
      else {
        banner.show();
        $('body').addClass('with-banner');
        $( this ).text( btn.attr('data-hide-text') ).trigger('blur');
        $.cookie('banner_visible', '1', { expires: 365, path: '/' });
      }
      return false;
    });
  }

  //
  $('.provider-cat').each(function(){
    var elm = $( this ),
        sub = elm.children('ul:first'), 
        lnk = elm.children('h4:first');
    if ( !sub.is(':has(strong)') ) {
      sub.hide();
    }
    lnk.wrapInner('<a href="#"></a>').bind('click', function(){
      sub.slideToggle();
      return false;
    });
  });

  // run autocomplete for search input
  $('#q, #ds-q').each(function () {
    var s = $( this );
    s.autocomplete({
      url: s.attr('data-autocompleteurl')
    });
  });
  
  // backwards compatible autofocus
  var has_autofocus = 'autofocus' in document.createElement('input');
  if ( !has_autofocus ) {
    var af = $(':input').map(function(i,a){
      return (a.autofocus || a.hasAttribute && a.hasAttribute('autofocus')) ? a : null;
    });
    if (af.length) {
      af[0].focus();
    }
  }

});

