(function ($) {
    jQuery.fn.buyit = function (options) {
        var opts = $.extend({},
        $.fn.buyit.defaults, options); 
		
        var $this = $(this);
        $this.data('opts', opts);
        return this.each(function (i, e) {
            var $t = jQuery(this);
            //IMPORTANT !!!
            //Prevent MULTIPLE Binding !!
            //IN case when they was already Binded!
            jQuery(e).unbind('click.buyit'); 
			//Bind Click 
            jQuery(e).bind('click.buyit', function (event) {
                event.preventDefault();                
                var this_cart = $("#cart_" + $t.parent().attr('m_id'));
				var this_form = $("#sendForm_" + $t.parent().attr('m_id'));
                
                this_cart.show();
                var master_id = $t.parent().attr('m_id');
                
                var sentence_id = $t.parent().attr('id');
                var sentence_number = $t.parent().attr('num_id');
                var sentence_price = $t.parent().attr('pr_id');
                
                $t.hide();
                $("#" + sentence_id).addClass("sel");
                
                this_cart.append('<div class="list-div"><div class="list-item">Sentence ' + sentence_number + '&nbsp;</div><div class="list-price msg_price_' + master_id + '">; Price :' + sentence_price + '&nbsp;</div><div sentence_id="' + sentence_id + '" class="borrar" id="b_' + sentence_id + '" cart_id="' + master_id + '"></div></div>');
                this_form.append('<input type="hidden" name="sid_'+sentence_id+'" id="sid_'+sentence_id+'" value="'+$t.parent().attr('p_id')+'">');
				var $message_price_class = 'msg_price_' + master_id;
                var totalPrice = $("." + $message_price_class).sum().toFixed(3);
                var message_cartTotal_id = '#cartTotal_' + master_id;
				var form_price='#ptprice_'+master_id;
                $(message_cartTotal_id).text(totalPrice);
				$(form_price).val(totalPrice);
                
                $(".borrar").mremove();
            });
        })
    } //defaults
    jQuery.fn.buyit.defaults = {
        def1: "value1"
    }; //private part


    function _load_missing_js($file_name) {
        $.getScript($file_name, function () {
            alert('Loaded');
        });
    }
})(jQuery);
