// Stb
Stb = function () {};
Stb.$ = jQuery.noConflict();
Stb.init = function() {
	jQuery("a.mail").LM_JQ_MailAddress();
	jQuery("a[rel='external']").LM_JQ_ExtLink();
};

// jQuery Plugins ----------------------------------------------

/**
 * LM.JQ.MailAddress
 * Ver. 0.2
 */
(function($) {
$.fn.LM_JQ_MailAddress = function () {
	$(this).each(function () {
		var adr = $(this).text();
		adr = adr.replace(/\s\(\w*\)\s/, "@");
		adr = adr.replace(/\s\[\w*\]\s/g, ".");
		$(this).attr('href', 'mailto:' + adr);
		$(this).html(adr);
	});	
};
})(jQuery);

/**
 * LM.JQ.ExtLink
 * Ver. 0.1
 */
(function($) {
$.fn.LM_JQ_ExtLink = function () {
	$(this).each(function () {
		$(this).attr('target', '_blank');
	});
};
})(jQuery);

/**
 * LM.JQ.Mp3Player
 * Ver. 0.1
 */
(function($) {
$.fn.LM_JQ_Mp3Player = function (playerId) {
	$(this).each(function () {
		var file = $(this).attr('href');
		LM_Player.play(playerId, file);
	});
};
})(jQuery);


function checkEmail(email)
{
  var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var emailVal = $("#" + email).val();
  return pattern.test(emailVal);
}

// init ----------------------------------------------
jQuery(document).ready(function() {
    Stb.init();

  /*
    // Newsletter Subscribe
    $("#newslettersubscribeButton").click(function() {

      // First, disable the form from submitting
      $('form').submit(function() { return false; });

      // Grab form action
      formAction = $("form").attr("action");

      // Hack together id for email field
      emailId = formAction.replace("http://cloudleaves.createsend.com/t/r/s/", "");
      emailId = emailId.replace("/", "");
      emailId = emailId + "-" + emailId;

      // Validate email address with regex
      if (!checkEmail(emailId))
      {
        alert("Please enter a v alid email address");
        return;
      }

      // Serialize form values to be submitted with POST
      var str = $("form").serialize();

      // Add form action to end of serialized data
      final = str + "&action=" + formAction;

      // Submit the form via ajax
      $.ajax({
        url: "newslettersignup/",
        type: "POST",
        data: final,
        success: function(html){
          $("#theForm").hide(); // If successfully submitted hides the form
          $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
        }
      });
    });
  */
});