(function($){

   $.fn.wrapChildren = function(options) {

    var options = $.extend({
                              childElem : undefined,
                              sets : 1,
                              wrapperClass : 'list'
                            }, options || {});
    if (options.childElem === undefined) return this;

 return this.each(function() {
  var elems = $(this).children(options.childElem);
  var arr = [];

  elems.each(function(i,value) {
    arr.push(value);
    if (((i + 1) % options.sets === 0) || (i === elems.length -1))
   {
     var set = $(arr);
     arr = [];
     set.wrapAll($('<div class="' + options.wrapperClass + '">'));
   }
  });
    });

  }

})(jQuery);

    $(document).ready(function() {
        $('ul.udm').superfish({
            delay:       1000,                            // one second delay on mouseout
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation
            speed:       'normal',                          // faster animation speed
            autoArrows:  true,                           // disable generation of arrow mark-up
            dropShadows: true,                            // disable drop shadows
			disableHI: true
        });




        $('ul.leftudm').superfish({ // Left Menu
            delay:       20000,                           
            animation:   {opacity:'show',height:'show'},  
            speed:       20000,                         
            autoArrows:  true
        });
	
		$('#udm_menu_item_our_services a:first').click(function(e) { e.preventDefault(); });
                          
		$('#articles_share_links').appendTo('#container-centre');  // FORCE SYNC

		$('#container-centre').append('<div class="clear"><!-- clear --></div>');
		
		$('body#home .newsTH .link a.morelink span').html("Employment law news");
		
		
		$('ul#udm_menu_employees li').each(function() {
			$(this).appendTo('#udm_menu_our_services').addClass('mmlist1');
		});
	   
		$('ul#udm_menu_employers li').each(function() {
			$(this).appendTo('#udm_menu_our_services').addClass('mmlist2');
		});
	   
	   
		$('li#udm_menu_item_employees').remove();
		$('li#udm_menu_item_employers').remove();
		$('li#udm_menu_item_services').remove();
	   
		var list1size = $('.mmlist1').length;
		var list2size = $('.mmlist2').length;
	   
		 $('#udm_menu_our_services').wrapChildren({
		 childElem : '.mmlist1',
		 sets : list1size,
		 wrapperClass : 'mmcol mmcol01'
		 });
		 
		  $('#udm_menu_our_services').wrapChildren({
		 childElem : '.mmlist2',
		 sets : list2size,
		 wrapperClass : 'mmcol mmcol02'
		 });
		 
		 $('.mmcol01').prepend('<div class="listTitle">Services for Employees</div>');
		 $('.mmcol02').prepend('<div class="listTitle ltsfb">Services for Employers</div>');	
		$('li#udm_menu_item_megemenu').remove();


		// Bookmark Javascript 

		var wlprot = window.location.protocol;
		var wlhost = window.location.host;
		var wlpath = window.location.pathname;
		var wlpathnew = wlpath.replace( /\//g, "%2F");
		var pt = document.title;
		var pagetitle = pt.replace(/[^a-zA-Z 0-9 -]+/g,'').replace(/  /, ' ');
		var fullURL = wlprot + "//www." +  wlhost + wlpath;
		var pagetitleLI = pagetitle.replace(/ /g, "+");

		var fblink = "http://www.facebook.com/share.php?u=http%3A%2F%2Fwww."+wlhost+wlpathnew;
		var twlink = "http://twitter.com/share?url=http%3A%2F%2Fwww."+wlhost+wlpathnew+"&text="+pagetitle;
		var lilink = "http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fwww"+wlhost+wlpathnew+"&title="+pagetitleLI+"&ro=false&summary=&source="
		var dilink = "http://digg.com/submit?url=http%3A%2F%2Fwww."+wlhost+wlpathnew
		var sulink = "http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww."+wlhost+wlpathnew+"&title="+pagetitleLI;
		
		$('a#bmfb').attr('href',fblink);
		$('a#bmtw').attr('href',twlink);
		$('a#bmli').attr('href',lilink);	
		$('a#bmdi').attr('href',dilink);	
		$('a#bmsu').attr('href',sulink);
        
        // Load third-party scripts
        // calls RSS function for homepage
        // $.getScript('http://www.legalrss.co.uk/feed/newssynd2.js', function() {
        //     $.getScript('http://www.legalrss.co.uk/advantageemploymentlaw/feed/', function() {
        //         // yet to find a limit to send to legalrss
        //         // hide all but the first three items in the list
        //         $('.newssynd-items li:not(:nth-child(-n+3))').hide();
        //     });
        // });
        
        
    });


