(function($){

$.fn.x_share = function(opts){
   
   var settings = {'btn-print': 'javascript:window.print();'};
   var $base = $(this);
   
   $('#jqModal').jqm({
        ajax: '@href'
    });
    
   return this.each(function(){
      if(opts){
         $.extend(settings, opts);
      }
     
      var $el=$(this);
      $(">a", $el).append(function(){
            return '<span class="icon"></span>'+$(this).attr("title");
         })
         .attr("href", function(i, val){
         if(val) return val;
         cls = $(this).attr("class");
         if(settings[cls]) return settings[cls]; 
         return "javascript:;";
      });
      
      $("a.btn-email").live('click',
         function(){
            $('#jqModal').jqmShow(this);
            return false;
            //$('#jqModal').jqmShow();
            // return false;
      });
     $("a.btn-share").live('click', function(){
        $(".share-form", $base).toggle();
        $("#share-copy-help").val(window.location.href).focus().select();
        return false;
     })
   });
};

})(jQuery);

jQuery.log=function(msg){
  if(window.console) {
     window.console.log(msg);
  } else {
//     alert(msg);
    ;
  }
};

$('document').ready(function() {
  jQuery(".story-service").x_share({
     'btn-email': '/app/share/friend'
  });
});

/*
// initialize modal,
// load the container with a remote return based on the 'href'
//    attribute of triggering element(s)
 $('#jqModal').jqm({
     ajax: '@href'
 });
*/
