﻿function msa_load() {

	//this.msa_loadLinkStyles();	
	msa_loadMoreLess();

}

function msa_loadLinkStyles() {

	//external links - add icon using css to identify outgoing links.
	$.expr[":"].external = function (obj) {
		return !obj.href.match("^mailto\:")
				&& !obj.href.match("^javascript\:")
				&& (obj.hostname != location.hostname);
	};
	$("a:external").addClass("external");

 	//internal links - 
	$("a[href^='.'], a[href^='/'], a[href$='mskills.com.au']").addClass("internal");

	//mail links - add mail icon to using css
	$("a[href^=mailto:]").addClass("email");

}

function msa_loadMoreLess() {

	// The height of the content block when it's not expanded
	var adjustheight = 40;
	// The "more" link text
	var moreText = "+  More";
	// The "less" link text
	var lessText = "- Less";

	// The section added to the bottom of the "showmore" div
	$(".showmore .moreblock").each(function () {
		if ($(this).height() > adjustheight) {

			// Sets the .moreblock div to the specified height and hides any content that overflows
			$(this).css('height', adjustheight).css('overflow', 'hidden');

			$(this).parent(".showmore").append('<a href="#" class="adjust"></a>');

			$(this).parent(".showmore").find("a.adjust").text(moreText);

			$(this).parent(".showmore").find(".adjust").toggle(function() {
				$(this).parents("div:first").find(".moreblock").css('height', 'auto').css('overflow', 'visible');
				$(this).text(lessText);
			}, function () {
				$(this).parents("div:first").find(".moreblock").css('height', adjustheight).css('overflow', 'hidden');
				$(this).text(moreText);
			});

		}
	});
}

// http: //jsfiddle.net/jazaret/TcLqd/

(function ($) {
	$.fn.moreOrLess = function (options) {
		// The height of the content block when it's not expanded
		var defaults = { adjustHeight: 40, moreText: "+ More", lessText: "- Less" };
		options = $.extend({}, defaults, options);

		return this.each(function () {

			var $this, $outerDIV, height;
			$this = $(this);
			height = $this.css('height').replace('px', '');
			if (height > options.adjustHeight) {
				// Sets the .more-block div to the specified height and hides any content that overflows
				$this.css('height', options.adjustHeight).css('overflow', 'hidden').addClass('more-block');

				// The section added to the bottom of the "more-less" div
				$outerDIV = ('<div class="more-less" />');
				$this.wrap($outerDIV);

				//$this.parent().append('<span class="continued">... </span><a href="#" class="adjust">' + options.moreText + '</a>');
				$this.parent().append('<a href="#" class="adjust">' + options.moreText + '</a>');

				//Set click properties
				$(".adjust", $this.parent()).toggle(function () {
					var $this = $(this);
					//More Clicked
					$this.parents("div:first").find(".more-block").animate({ height: height + 'px', overflow: 'visible' }, 500, function () {
						$this.text(options.lessText);//.parents("div:first").find("span.continued").css('display', 'none');
					});
				}, function () {
					//Less Clicked
					var $this = $(this);
					$(this).parents("div:first").find(".more-block").animate({ height: options.adjustHeight, overflow: 'hidden' }, 500, function () {
						$this.text(options.moreText);//.parents("div:first").find("span.continued").css('display', '');
					});
				});
			}
		});
	};
})(jQuery);
