$.extend({
  // Flesh out the remaining HTTP verbs
	put: function( url, data, callback, type ) {
		if ( jQuery.isFunction( data ) ) {
			callback = data;
			data = {};
		}

		return jQuery.ajax({
			type: "POST",
			url: url,
			data: $.extend(data, {_method: "put"}),
			success: callback,
			dataType: type
		});
	},

	del: function( url, data, callback, type ) {
		if ( jQuery.isFunction( data ) ) {
			callback = data;
			data = {};
		}

		return jQuery.ajax({
			type: "POST",
			url: url,
			data: $.extend(data, {_method: "delete"}),
			success: callback,
			dataType: type
		});
	}
});

// $.ajaxSettings.accepts.html = $.ajaxSettings.accepts.script;
$.ajaxSetup({
  'beforeSend': function(xhr) { xhr.setRequestHeader("Accept", "text/javascript"); }
});

/*
$(document).ajaxError(function(event, xhr, options, error) {
  alert("error: " + xhr.status + "\n" + xhr.responseText);
});
*/

function embeddedData(key) {
  return $("#data-" + key).text();
}

$(document).ready(function() {
  var setup_poll_form = function() {
    $("#poll form").ajaxForm(function(result) {
      console.log(result);
      $("#poll div.widget-content").html(result);
    });
  };

  $("a.content-placeholder").each(function() {
    var self = this;
    $.get($(this).attr("href"), function(result) {
      $(self).parent().html(result);
      //setup_poll_form();
    });
  });

  $("#navigation li").hover(
    function() { $(this).find("ul:first").stop().css({display: "none", opacity: 0.0, height: null}).animate({height: "show", opacity: 1}, 400); },
    function() { $(this).find("ul:first").stop().slideUp(); }
  );
  $("#blogroll .widget-content").hide();
  $(".widget-accordian .widget-header").click(function() {
    $(this).next().toggle(400);
  });

  //setup_poll_form();

  // Repeat ads to match height of long content pages
  var contentHeight = $("#content").height();
  var sidebarHeight = $("#sidebar").height();

  if (contentHeight > sidebarHeight) {
    var cur_ads = $(".side-ad");
    while (contentHeight > sidebarHeight) {
      cur_ads.each(function() {
        sidebarHeight += $(this).outerHeight(true);
        if (contentHeight > sidebarHeight) {
          $("<div></div>").attr("class", $(this).attr("class"))
                          .append($(this).children("img, a, div:visible").clone())
                          .appendTo($("#sidebar"));
          return true;
        }
        return false;
      });
    }
  }

  // Setup background ad links
  function update_background_links() {
    var content = $("#content");
    $("#background-link-left").css("left", "0").css("width", content.offset().left + "px");
    $("#background-link-right").css("right", "0").css("width", content.offset().left + "px");
  }
  update_background_links();
  $(window).resize(update_background_links);
});
