jQuery(document).ready(function($) {

  // regex support from http://james.padolsey.com/javascript/regex-selector-for-jquery/
  jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ?
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
  }

  try {
/*    var interval;
    jQuery('ul#myRoundabout').roundabout({
       minOpacity: 0.8,
       minScale: 0.5,
       maxScale: 1,
       btnNext: '#slider_next',
       btnPrev: '#slider_previous',
       easing: 'easeInOutBack',
       reflect: true,
       duration: 1200
    }).hover(
      function() {
        // oh no, it's the cops!
        clearInterval(interval);
      },
      function() {
        // false alarm: PARTY!
        interval = startAutoPlay();
      }
    );

    // let's get this party started
    interval = startAutoPlay();

    // show the slider only after the page has loaded
    $('#slider').css('visibility', 'visible');*/
  } catch(e) { /* silence */ }

  // add a highlight class to compare1 table tds with bold content, retroactively
  jQuery('table.compare1').find("strong").parents("table.compare1 td").addClass("highlight1");

  // add a highlight class to compare1 table tds with italics content, retroactively, and remove italics altogether
  jQuery('table.compare1').find("em,i").parents("table.compare1 td").each(function() {
    var el = jQuery(this);
    var t = el.text();
    el.addClass("highlight2");
    el.html(t);
  });

  // QR cluetip
  jQuery("div.post_content a:not(:has('img[src*=chart.apis.google]'))").not("[href$='jpg']").not("[href$='png']").not("[href$='jpeg']").not("[href$='gif']").cluetip({
    width: '202px',
    attribute: 'href',
    titleAttribute: 'disable',
    cluetipClass: 'ap',
    positionBy: 'mouse',
    showTitle: false,
    local: true,
    hideLocal: false,
    mouseOutClose: true,
    sticky: false,
    cursor: 'pointer',
    tracking: false,
    clickThrough: true,
    hoverIntent: {
      sensitivity: 1,
      interval:    1200,
      timeout:     500
    },
    onShow: function(ct, c){
      var link = jQuery(this).attr('href');
      var size = 200;
      var qr_tag = "<div id='qr_img'><img alt='QR code for " + link + "' title='QR code for " + link + "' width='" + size + "' height='" + size +
        "' src='http://chart.apis.google.com/chart?cht=qr&chs=" + size + "x" + size + "&chl=" + encodeURIComponent(link) + "'></div>" +
        "<div id='qr_code_footer'><img class='qr_code_help_icon' src='/wp-content/themes/ap1/images/icons/help.png'>To improve your mobile experience, AndroidPolice provides QR codes that appear after a few seconds of hovering on most in-post links.<p><img class='qr_code_help_icon' src='/wp-content/themes/ap1/images/icons/mobile_phone.png'>Scan the QR code above using Barcode Scanner from the Android Market, and the link will be instantly accessible on your phone.</p></div>";
      c.html(qr_tag);
    }
  });
});

/*function startAutoPlay() {
  return setInterval(function() {
    jQuery('ul#myRoundabout').roundabout_animateToNextChild();
  }, 7000);
}*/