    
(function($) {
  $(document).ready(function() {

   // Add class to body to enchance accessibility
   $('body').addClass("js-enabled");

    // Set the Javascript API key
    setApiKey(3031679862);


   //Sort by drop down list
   if($('#id2787, #id2791, #id17387, #id2795, #id2726, #id15003, #id14294, #id18515, #id19190, #id19217, #id18626, #id19044, #id19163, #id19075, #id23642, #id24295, #id24299, #id24303, #id27647, #id3832 ').length){
   sortByDropDown();
   }

    // Set default value for Keep Informed Form
    if($('#sign-up-right').length) {
       $('#cs-name-right').defaultValue("Name");
       $('#cs-organisation-right').defaultValue("Organisation");
       $('#cs-email-right').defaultValue("Email");
    }

    // Content sharing toolbar
    if($('#content-share').length){
       contentShare();
    }

    // Set default value for Keep Informed Footer
    $('#cs-name-footer').defaultValue("Name");
    $('#cs-email-footer').defaultValue("Email");

    // Adds class to first item in Whats happening main content area as default format uses paint layout
    if($('#hp-eventslisting').length){
       $('.hp-upcomingevents li:first-child').addClass("first");
    }

   // Adds class to last right hand menu list
   if($('#right-sub-menu').length) {
      $('ul.menu-list li:last').addClass('last');
   }

   if($(".lightbox").length){
     // lightbox functionality
     $(".lightbox").lightbox({fitToScreen: true}); 
   }

   if($('#nav-pri-list').length){
     //Remove empty uls from main nav so superfish can show arrows only when needed
     $('#nav-pri-list ul').each(function(){
       if($(this).find('li').length == 0){
         $(this).remove();
       }
     });

     // Adds background image when home div on hover
     $("#nav-pri-list>li:first-child").hover(       
       function () {
        $(this).addClass("home-hover");
            }, 
       function () {
        $(this).removeClass("home-hover");
     });

     // dropdowns wohoooo
     $('#nav-pri-list').superfish({
       autoArrows: true
     });
   }

    // Campaign Suite Submission
	$.each($('.cs-sign-up'), function(i, form) {
		$(form).find("input:submit").click(function() {
			// First, disable the form from submitting
			$(form).submit(function() { return false; });
			
			// Grab form action
			var formAction = $(form).attr("action");
			
			// Hacking together id for email field
			// Replace the xxxxx below:
			var id = "ayutih";
			var emailId = id + "-" + id;
			var email = $(form).find('[name=cm-'+emailId+']');
			
			// Validate email address with regex
			if (!checkEmail(email)) {
				alert("Please enter a valid email address");
				return;
			}
			
			if(!$(form).find('input.cs-policy').attr('checked')) {
				alert("Please accept the Privacy Policy");
				return;
			}
			
			$(form).find('.loading').css('display', 'block');
			$(form).find('input:submit').css('display', 'none');
			
			// Serialize form values to be submitted with POST
			var str = $(form).serialize();
			
			// Add form action to end of serialized data
			// CDATA is used to avoid validation errors
			//<![CDATA[
			var serialized = str + "&action=" + formAction;
			// ]]>
			
			// Submit the form via ajax
			$.ajax({
				url: $(form).find('.cs-proxy').val(),
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) {
						email.poshytip({
							className: 'tip-darkgray',
							showOn: 'none',
							alignTo: 'target',
							alignX: 'left',
							alignY: 'center',
							offsetX: 5,
							content: 'Email address is not valid'
						});
						email.poshytip('show');
					}
					else
					{
						$(form).find('.form').hide(); // If successfully submitted hides the form
						$(form).find(".result").slideDown("slow");  // Shows "Thanks for subscribing" div
						$(form).find(".result").tabIndex = -1;
						$(form).find(".result").focus(); // For screen reader accessibility
					}
				}
			});
		});
	});
  
    $('#hp-feature-slideshow').cycle({
    fx: 'fade',
        prev:   '#prev',      // id of element to use as click trigger for previous slide 
        next:   '#next',      // id of element to use as click trigger for next slide   
  timeout:       11000,  // milliseconds between slide transitions (0 to disable auto advance) 
        speed:         2000,  // speed of the transition (any valid fx speed value)                 
        height:       '219px', // container height 
        sync:          true,     // true if in/out transitions should occur simultaneously 
        fit:           true,     // force slides to fit container 
        pause:         true     // true to enable "pause on hover"       
    });
   

  //Slider select for the form 
    if($("#form-content select.slide").length){     
      $('select.slide').each(function(){
        $(this).selectToUISlider()
      });
    }; 
   /*  if($("#form-content").length){     
      var abc = $('select#q1276_q16').selectToUISlider().next();
      var def = $('select#q1276_q17').selectToUISlider().next();
      var ghi = $('select#q1276_q18').selectToUISlider().next();
      var jkl = $('select#q1276_q19').selectToUISlider().next();
      var mno = $('select#q1276_q20').selectToUISlider().next();
      var pqr = $('select#q1276_q21').selectToUISlider().next(); 
    }; */

//Sorting by ascending or descending on News & Info
   $("#search_page_389_sort_by").click(function(){   
   var sorted =  $("#search_page_389_sort_by option:selected").attr("value");
   if (sorted==1)
      $("#search_page_389_sort_direction option[value='1']").attr("selected","selected");     
   if (sorted==2)
      $("#search_page_389_sort_direction option[value='0']").attr("selected","selected"); 
});  
     

//Sorting by ascending or descending on Site Search Results 
   $("#search_page_547_sort_by").click(function(){   
   var sorted =  $("#search_page_547_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_547_sort_direction option[value='1']").attr("selected","selected");   
   if (sorted==2)
      $("#search_page_547_sort_direction option[value='0']").attr("selected","selected"); 
});  
 

//Sorting by ascending or descending on Resources & Tools all resources
   $("#search_page_709_sort_by").click(function(){   
   var sorted =  $("#search_page_709_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_709_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_709_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_709_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==3)
      $("#search_page_709_sort_direction option[value='1']").attr("selected","selected"); 
});     
//Sorting by ascending or descending on Lean Manufacturing
   $("#search_page_1097_sort_by").click(function(){   
   var sorted =  $("#search_page_1097_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_1097_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_1097_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_1097_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==3)
      $("#search_page_1097_sort_direction option[value='1']").attr("selected","selected");
});
//Sorting by ascending or descending on Staff, Skills & Capability
   $("#search_page_966_sort_by").click(function(){   
   var sorted =  $("#search_page_966_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_966_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_966_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==2)
      $("#search_page_966_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==3)
      $("#search_page_966_sort_direction option[value='1']").attr("selected","selected");
});
//Sorting by ascending or descending on Innovation, R&D and IT
   $("#search_page_1077_sort_by").click(function(){   
   var sorted =  $("#search_page_1077_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_1077_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_1077_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_1077_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==3)
      $("#search_page_1077_sort_direction option[value='1']").attr("selected","selected"); 
});
//Sorting by ascending or descending on Capital & Finance
   $("#search_page_1057_sort_by").click(function(){   
   var sorted =  $("#search_page_1057_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_1057_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_1057_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==2)
      $("#search_page_1057_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==3)
      $("#search_page_1057_sort_direction option[value='1']").attr("selected","selected");
});
//Sorting by ascending or descending on Benchmarking
   $("#search_page_885_sort_by").click(function(){   
   var sorted =  $("#search_page_885_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_885_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_885_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_885_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==3)
      $("#search_page_885_sort_direction option[value='1']").attr("selected","selected");
});
//Sorting by ascending or descending on Market & Technical Insight
   $("#search_page_843_sort_by").click(function(){   
   var sorted =  $("#search_page_843_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_843_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_843_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_843_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==3)
      $("#search_page_843_sort_direction option[value='1']").attr("selected","selected");  
});
//Sorting by ascending or descending on Trade Opportunities & Marketing
   $("#search_page_990_sort_by").click(function(){   
   var sorted =  $("#search_page_990_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_990_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_990_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_990_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==3)
      $("#search_page_990_sort_direction option[value='1']").attr("selected","selected");  
});
//Sorting by ascending or descending on Plant, Production & Logistics
   $("#search_page_1552_sort_by").click(function(){   
   var sorted =  $("#search_page_1552_sort_by option:selected").attr("value");   
   if (sorted==0)
      $("#search_page_1552_sort_direction option[value='1']").attr("selected","selected");           
   if (sorted==1)
      $("#search_page_1552_sort_direction option[value='0']").attr("selected","selected");
   if (sorted==2)
      $("#search_page_1552_sort_direction option[value='0']").attr("selected","selected"); 
   if (sorted==3)
      $("#search_page_1552_sort_direction option[value='1']").attr("selected","selected"); 
});


//Replace 'Leave Empty' text with 'All Sources' in dropdown box - News & Info - Site search Results
 if($("#queries_region_query").length){
  $("#queries_region_query option:first-child").text("All Sources"); 

//Sets the region results to the current option 
  $("select[name='queries_region_query'] option[value=" + querySt('queries_region_query') + "]").attr("selected","selected");
 };

//Replace 'Leave Empty' text with 'All Locations' in dropdown box - Training & Events - Site search Results
 if($("#queries_location_query").length){
  $("#queries_location_query option:first-child").text("All Locations"); 

//Sets the region results to the current option 
  $("select[name='queries_location_query'] option[value=" + querySt('queries_location_query') + "]").attr("selected","selected");
 };

//Replace 'Leave Empty' text with 'All Categories' in dropdown box - Training & Events - Site search Results
 if($("#queries_category_query").length){
  $("#queries_category_query option:first-child").text("All Categories"); 

//Sets the region results to the current option 
  $("select[name='queries_category_query'] option[value=" + querySt('queries_category_query') + "]").attr("selected","selected");
 };

//Replace 'Leave Empty' text with 'All Resources' in dropdown box - Resources & Tools section 
 if($("#queries_resources_query").length){
  $("#queries_resources_query option:first-child").text("All Resources");

  //Sets the resources results to the current option
  $("select[name='queries_resources_query'] option[value=" + querySt('queries_resources_query') + "]").attr("selected","selected");
 };   

//Replace '--Leave Empty--' text with 'Resources' for search reults - Resources & Tools section 
  $("#resource-type:contains('-- Leave Empty --')").text("Resources");

//Replace empty return string with text for search reults - Site search results 
  $("#mkhere-results:empty").text("the MKHere website");

//Adds the a href tag to the tagging key words 
  if($(".tagging").length){
      var searchUrl = $("#tagged-search-url").text();
      $(".tagging").each(function(){
        var keyText = $(this).text();
       // var keyText = keyText.replace(/&/g, "&amp;");
        var newText = keyText.replace(/, /g, "xxx");
        keyArray = newText.split(",");
        var i=0;
        for (i=0;i<=keyArray.length-1;i++){
          keyArray[i] = keyArray[i].replace(/xxx/g, ", ");
        }
        var i=0;
        var newKey = "";
        for (i=0;i<=keyArray.length-1;i++){
          var keyHref = keyArray[i].replace(/&/g, "%26");
          newKey += "<a title='Find other resources related to " + keyArray[i] + "' href='" + searchUrl + "?mode=results&queries_tagging_query=" + keyHref + "'>" + keyArray[i] + "</a>," + "";
        }
        $(this).html(newKey);
          
   });
 }

  //Remove the ',' at the end of the tagging key words 
 // if($(".tagging").length){
  //  $(".tagging").each(function(){
    //  var thisText = $(this).text();
    //  var thisLength = thisText.length;
    //  var lastChar = thisText.charAt(thisLength-1);
    //  if (lastChar == ","){
    //    var newText = thisText.substr(0,thisLength-1);
    //    $(this).text(newText);
   //   }
  //  });
//  };

  var cookieExists = $.cookie('manNZimage');
  if(cookieExists != null){
    // If cookie set display referer's image
    var thisUrl = $.cookie('manNZurl');
    var thisTitle = $.cookie('manNZtitle');
    var thisImage = $.cookie('manNZimage');
    displayRefererImage(thisUrl,thisTitle,thisImage);
  }
  else {
    // If cookie not set set it from referrer field and display referer's image
    if (document.referrer.indexOf('mkhere.org.nz') != -1) {
      var refererUrl = "http://www.mkhere.org.nz";
      var refererTitle = "Go to homepage Manufacturing Knowledge Here";
      var refererImageUrl = "./?a=1253";
    } 
    else {
      var refererUrl = "http://www.nz2011.govt.nz/cms";
      var refererTitle = "Go to homepage - NZ 2011";
      var refererImageUrl = "./?a=1738";
    }
    $.cookie('manNZurl', refererUrl);
    $.cookie('manNZtitle', refererTitle);
    $.cookie('manNZimage', refererImageUrl);
    displayRefererImage(refererUrl,refererTitle,refererImageUrl);
  }

  function displayRefererImage(linkUrl,linkTitle,imageUrl){
    $("#af-logo a").attr({href: linkUrl, title: linkTitle});
    $("#af-logo a img").attr("src",imageUrl);
    $("#af-logo").show();
  }; // end of displayRefererImage 

  });
})(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);
  }

  $(function() {
  $("#CampaignSuite input:submit").click(function(event) {
    // First, disable the form from submitting
   event.preventDefault();
    $('form#CampaignSuite').submit(function(event) { event.preventDefault(); });
    
    // Grab form action
    var formAction = $("form#CampaignSuite").attr("action");
    
    // Hacking together id for email field
    // Replace the xxxxx below:                               
    var id = "ktwtj";
    var emailId = id + "-" + id; 
               
    
    // Validate email address with regex
    if (!checkEmail(emailId)) 
    {
      alert("Please enter a valid email address");
      return;
    }
    
    // Serialize form values to be submitted with POST
    var str = $("form#CampaignSuite").serialize();
    
    // Add form action to end of serialized data
    // CDATA is used to avoid validation errors
    //<![CDATA[
    var serialized = str + "&action=" + formAction;
    // ]]>
    
    // Submit the form via ajax
    $.ajax({
      url: "/__data/assets/file/0005/1976/CampaignSuite.php",
      type: "POST",
      data: serialized,
      success: function(data){
        // Server-side validation
        if (data.search(/invalid/i) != -1) {
          alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
        }
        else
        {
         $("#CampaignSuiteWrapper").hide(); // If successfully submitted hides the form
         $("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
         $("#confirmation").tabIndex = -1;
         $("#confirmation").focus(); // For screen reader accessibility
        }
      }
    });
  });
});  
   


//Inserts results per page select box and removes matrix results per page hidden input
    $("input:hidden[name='results_per_page']").remove();
    $("input[name='results_per_page_text_box']")
        .after('<select class="results-per-page" name="results_per_page" ><option value="5" >5</option><option value="10">10</option><option value="25">25</option></select>')
          .remove();

//Sets the page results to the current option
       $("select[name='results_per_page'] option[value=" + querySt('results_per_page') + "]").attr("selected","selected");


//parameter takes name of query and returns its value
   function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
     for (i=0;i<gy.length;i++) {
      ft = gy[i].split("=");
     if (ft[0] == ji) {
      return ft[1];
      }
     }
    }
 

//Rotating Feature Images
(function(D){
  var A="Lite-1.0";
  
  D.fn.cycle=function(E)
  
   {return this.each(function(){E=E||{};
     if(this.cycleTimeout){clearTimeout(this.cycleTimeout)}this.cycleTimeout=0;this.cyclePause=0;var I=D(this);
     
       var J=E.slideExpr?D(E.slideExpr,this):I.children();
     var G=J.get();if(G.length<2){if(window.console&&window.console.log){window.console.log("terminating; too few slides: "+G.length)}
      return }
    
    var H=D.extend({},D.fn.cycle.defaults,E||{},D.metadata?I.metadata():D.meta?I.data():{});H.before=H.before?[H.before]:[];H.after=H.after?[H.after]:[];H.after.unshift(function(){H.busy=0});
    
    var F=this.className;H.width=parseInt((F.match(/w:(\d+)/)||[])[1])||H.width;H.height=parseInt((F.match(/h:(\d+)/)||[])[1])||H.height;H.timeout=parseInt((F.match(/t:(\d+)/)||[])[1])||H.timeout;
      if(I.css("position")=="static"){I.css("position","absolute")}
      if(H.width){I.width(H.width)}if(H.height&&H.height!="auto"){I.height(H.height)}
      
       var K=0;J.css({position:"absolute",top:0,left:0}).hide().each(function(M){D(this).css("z-index",G.length-M)});D(G[K]).css("opacity",1).show();
         if(D.browser.msie){G[K].style.removeAttribute("filter")}
       if(H.fit&&H.width){J.width(H.width)}if(H.fit&&H.height&&H.height!="auto"){J.height(H.height)}
       if(H.pause){I.hover(function(){this.cyclePause=1},function(){this.cyclePause=0})}D.fn.cycle.transitions.fade(I,J,H);J.each(function(){var M=D(this);
         this.cycleH=(H.fit&&H.height)?H.height:M.height();
         this.cycleW=(H.fit&&H.width)?H.width:M.width()});J.not(":eq("+K+")").css({opacity:0});
           if(H.cssFirst){D(J[K]).css(H.cssFirst)}if(H.timeout){if(H.speed.constructor==String){H.speed={slow:600,fast:200}[H.speed]||400}if(!H.sync){H.speed=H.speed/2}while((H.timeout-H.speed)<250){H.timeout+=H.speed}}H.speedIn=H.speed;H.speedOut=H.speed;H.slideCount=G.length;H.currSlide=K;H.nextSlide=1;
         
         var L=J[K];if(H.before.length){H.before[0].apply(L,[L,L,H,true])}
          if(H.after.length>1){H.after[1].apply(L,[L,L,H,true])}
          if(H.click&&!H.next){H.next=H.click}if(H.next){D(H.next).bind("click",function(){return C(G,H,H.rev?-1:1)})}
          if(H.prev){D(H.prev).bind("click",function(){return C(G,H,H.rev?1:-1)})}
          if(H.timeout){this.cycleTimeout=setTimeout(function(){B(G,H,0,!H.rev)},H.timeout+(H.delay||0))}})};function B(J,E,I,K){if(E.busy){return }
          
          var H=J[0].parentNode,M=J[E.currSlide],L=J[E.nextSlide];
           if(H.cycleTimeout===0&&!I){return }
           if(I||!H.cyclePause){if(E.before.length){D.each(E.before,function(N,O){O.apply(L,[M,L,E,K])})}
           
           var F=function(){if(D.browser.msie){this.style.removeAttribute("filter")}D.each(E.after,function(N,O){O.apply(L,[M,L,E,K])})};
            if(E.nextSlide!=E.currSlide){E.busy=1;D.fn.cycle.custom(M,L,E,F)}
          
          var G=(E.nextSlide+1)==J.length;E.nextSlide=G?0:E.nextSlide+1;E.currSlide=G?J.length-1:E.nextSlide-1}
           if(E.timeout){H.cycleTimeout=setTimeout(function(){B(J,E,0,!E.rev)},E.timeout)}}function C(E,F,I){var H=E[0].parentNode,G=H.cycleTimeout;
           if(G){clearTimeout(G);H.cycleTimeout=0}F.nextSlide=F.currSlide+I;
           if(F.nextSlide<0){F.nextSlide=E.length-1}
           else{if(F.nextSlide>=E.length){F.nextSlide=0}}B(E,F,1,I>=0);return false}D.fn.cycle.custom=function(K,H,I,E){var J=D(K),G=D(H);G.css({opacity:0});
           
           var F=function(){G.animate({opacity:1},I.speedIn,I.easeIn,E)};J.animate({opacity:0},I.speedOut,I.easeOut,function(){J.css({display:"none"});
            if(!I.sync){F()}});if(I.sync){F()}};D.fn.cycle.transitions={fade:function(F,G,E){G.not(":eq(0)").css("opacity",0);E.before.push(function(){D(this).show()})}};D.fn.cycle.ver=function(){return A};D.fn.cycle.defaults={timeout:4000,speed:1000,next:null,prev:null,before:null,after:null,height:"auto",sync:1,fit:0,pause:0,delay:0,slideExpr:null}
            
})(jQuery)

function sortByDropDown()
{
       $('#sortby select option:first-child').text("Newest to Oldest");
       $('#sortby select option:first-child').after('<option value="0">Oldest to Newest</option>');
       $('#sortby select option:last-child').after('<option value="1">Z to A</option>');

       $('#sortby select').click(function() {
        switch ($('#sortby select option:selected').attr("text"))
        {
           case "Newest to Oldest":
           $("#sortorder select option[value='1']").attr("selected","selected");
           break;
  
           case "Z to A":
           $("#sortorder select option[value='1']").attr("selected","selected");
           break;
  
           default:
           $("#sortorder select option[value='0']").attr("selected","selected");
        }
      });
}

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);

} // end checkEmail



function contentShare() {
  if($('#content-share option').length==1)
    {
       $('#content-share').remove();
    }

  $('#content-share select option').each(function() {
    var rootNodes = $(this).attr("value");

          var optionGroupClass = $(this).parent().attr('class');
          $(this).addClass(optionGroupClass);
          var groupClass = $(this).attr('class');

     getChildren(rootNodes, 2, function(data) {
       for (var id in data) {
          var currentAsset = $('body').attr('id').substr(2);

          if (id == currentAsset)
          {
            $('#content-share .'+groupClass).remove();
            if($('#content-share option').length==1)
            {
               $('#content-share').remove();
            }
          }
     
       }
     })
  })

  $('#sharebutton').click(function() {
     var createLinkNode = $('#content-share select option:selected').attr('value');
     var currentAsset = $('body').attr('id').substr(2);
   
     switch($('#sharebutton').attr('value'))
     {
        case "Share":
        createLink(createLinkNode, currentAsset, 1,"", 0, 0, 0, function() {}
        ),
        $('#sharebutton').attr('value','Undo')
        break;
      
        case "Undo":
        removeLink(createLinkNode, currentAsset, function() {}
        ),
        $('#sharebutton').attr('value', 'Share')      
     }
  })
} // end contentShare
