$(function() {
  $('#pcomments div.photos a').fancybox({
    'overlayShow':true,
    'overlayOpacity':0.5
  });

  var terms = document.referrer.match(/q=([^&]+)/);
  if (terms) {
    $('#adtop').prepend('<h4 id="searchterms">You searched for "'+unescape(terms[1]).replace(/\+/g,' ')+'".</h4>');
    $('#searchterms').slideDown(300);
  }

  $('#sharebar li a').each(function() {
    var service = $('strong',this).html();
    $(this).attr('href','/cgi-bin/s2.pl?cpn=Social+Bookmarks&loc=problem+detail&plc='+encodeURIComponent(service)+'&url='+encodeURIComponent(this.href));
  });

  $('#moreshares').bind('click',function() {
    var $hidden = $('#sharebar li.hidden');
    var $shown = $('#sharebar li:not(.hidden)');
    $shown.slideUp(300,function() {
      $(this).addClass('hidden');
      $hidden.hide().removeClass('hidden').slideDown(300);
    });
    return(false);
  });

  $('#helpfulsites').corner();
  $('#warrantymsg,#p0 .descad,#textlinkads').corner('bottom');
  $('#justanswer').corner('bottom');
  $('#justanswer textarea').bind('focus',function() { if (this.value == 'Type your question here.') { this.value = ''; } });
/*  too slow
  $('#solutionsad a.close').click(function() { $('#solutionsad').fadeOut(1400); });
  $('#solutionsad').fadeIn(2300).find('a.close').click(function() { $('#solutionsad').fadeOut(1400) });
*/

  $('#justanswer form').bind('submit',function() {
    var fRef = this;
    $.prompt('<h4>Leaving CarComplaints.com</h4><p>You are leaving CarComplaints.com for a third-party website:<br /> <em>&raquo;</em> <strong>JustAnswer.com</strong></p>',{
      buttons:{ 'Continue':true },
      prefix:'colsJqi',
      opacity: 0.9,
      show:'slideDown',
      submit:function(v,m) { 
        if (v) { fRef.submit(); }
      }
    }).children('div:eq(1)').queue('fx',function() { $(this).corner(); });
    return(false);
  });

});

function sendcomment(dindex) {
  var pdesc = restrictlength($('#probdesc'+dindex).html(),360);
  if ((getCookie('l') != '') && (getCookie('p') != '')) {
    setCookie('a',pmatrix[1]); // make
    setCookie('m',pmatrix[2]); // model
    setCookie('y',pmatrix[0]); // year
    setCookie('k',pmatrix[3]); // category
    setCookie('h',pmatrix[4]); // problem
    setCookie('d',pdesc);
    document.location.href = '/cgi-bin/sendcomment.pl?t='+dmatrix[dindex];
  }
  else {
    with(document.forms['commentForm']) {
      a.value = pmatrix[1];
      m.value = pmatrix[2];
      y.value = pmatrix[0];
      k.value = pmatrix[3];
      h.value = pmatrix[4];
      d.value = pdesc;
      t.value = dmatrix[dindex];
      submit();
    }
  }
  return(false);
}
