(function(window, document, version, callback) {
    var j, d, head;
    var loaded = false;
    if (!(j = window.jQuery) || version > j.fn.jquery || callback(j, loaded)) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";
        script.onload = script.onreadystatechange = function() {
            if (!loaded && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
                callback((j = window.jQuery).noConflict(1), loaded = true);
                j(script).remove();
            }
        };
		  
		  head = document.documentElement.childNodes[0];
		  
		  while(head && head.tagName != "HEAD") {
			  head = head.nextSibling;
		  }
		  
        head.appendChild(script);
    }
})(window, document, "1.5.2", function($, loaded) {
    // Widget code here
    $(function() {
        if (!window.cp_use_custom_css) {
           if (document.createStyleSheet) {
              document.createStyleSheet("http://calculatorpro.s3.amazonaws.com/cleanslate.css");
              document.createStyleSheet("http://calculatorpro.s3.amazonaws.com/widget.css");
           } else {
              $('<link rel="stylesheet" href="http://calculatorpro.s3.amazonaws.com/cleanslate.css">')
                .appendTo('head');
              $('<link rel="stylesheet" href="http://calculatorpro.s3.amazonaws.com/widget.css">')
                .appendTo('head');
           }

           $('.widgetForm').addClass('cleanslate');

           if($.browser.msie && ($.browser.version <= 7 || !$.support.boxModel)) {
               $('.calcTable').attr("style", "table-layout: fixed !important");
           }
        }

        $('#widgetSubmit, .widgetSubmit').click(function(e) {
           var form = $(this).closest('form');

           e.preventDefault();
           var widget_url = "http://www.calculatorpro.com/wp-content/plugins/calcs/ajax/calc.php?callback=?"
           $.getJSON(widget_url, $(this).closest('form').serialize(), function(data) {
               form.find('.answer').html(data.answer);
               form.find('.answerRow').removeClass('answerRow').addClass('visibleAnswerRow');
           });

           return false;
        });
   });
});
