(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
        });


        $('ul.leftudm').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:  false,                           // disable generation of arrow mark-up
            dropShadows: false                            // disable drop shadows
            
            
        });

		var pgLoc=location.pathname;

		$('.stafflistfade h2').remove();
	
                          $("a[href^='http']").attr('target','_blank');
        	
		//if(!(pgLoc=="/site/individuals/clinical_negligence_claims_essex/" || pgLoc=="/site/individuals/personal_injury_claims_essex/")) {
		//var staffCount = $('.staff_results .staffline').size();
		//var randomStart = Math.floor (Math.random() * staffCount);
		//} else {
		//var randomStart = 0
		//}
		
		var staffCount = $('.staff_results .staffline').size();
		var randomStart = Math.floor (Math.random() * staffCount);
		

		$('.stafflistfade .staff_results').before('<a name="sltop">').after('<ul id="nav"></ul>').cycle({
			startingSlide: randomStart,
			timeout: 10000,
			pager: "#nav",
			pause: true,
			pauseOnPagerHover: true,
			pagerAnchorBuilder: function(idx, slide) {  // This creates the buttons on the left hand side. "idx" = slide number,  "slide" is a way to target the slide.
				
				return '<li><a href="#sltop">'+ $(slide).children('.desc').children('.name').children('a').html() +'</a></li>';
		}
		});
	
		$('body#profile div#container-right div.default div.image img.staffimage').appendTo('#container-left');
		$('.profile_switcher').appendTo('#container-left');
		
			
		
		
		if (pgLoc.indexOf("/site/people/") != -1 ) {
			$('body').addClass('peoplearea');
		}
			
		if (pgLoc.indexOf("/site/people/profile/") != -1 ) {
			$('body').removeClass('peoplearea');
		};
			
		
		$('.delegatelist tr').each(function() {
			$(this).children('td:first').addClass('title').css({"width":"200px","padding-right":"10px"});
			$(this).children('td:last').css({"width":"200px"})
		});
		
		$('.bookingform').parent().addClass("delegatesForms")


		$('.delegateRowSeparator').html('<td colspan="2"><div class="separ"><!----></div></td>');

		$('.bookinginfo td.text:first').addClass("strongTitle");
		
		var quoteTimer = 5000 // 5 seconds
			setTimeout("$('.quote-outer').slideDown('slow');", quoteTimer); // Slides down quote after "quoteTimer" time.
			
        // don't add quote image on print pages
        function getParameterByName(name) {
          name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
          var regexS = "[\\?&]" + name + "=([^&#]*)";
          var regex = new RegExp(regexS);
          var results = regex.exec(window.location.href);
          if(results == null)
            return "";
          else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        }
        
        queryString = getParameterByName('print');
        if(!queryString) {
            $('<img class="quote-close" src="/images/quote_close.gif" alt="" />').appendTo('.quote-inner');
        }
			
		if (pgLoc.indexOf("/site/people/support_team/") != -1 ) {
		
			/* Alphabetical
			var html = '<div id="a2zFix">';
			$('table.a2z2 tr td').each(function(){
				html += $(this).html();
			});
			html += html + '</div>';
			
			$(html).insertAfter($('table.a2z2'));
			$('table.a2z2').remove();
			
			$('#a2zFix h2, #a2zFix .departments').remove();
			*/
			
			var partners = '<div id="staffline_partner_1" class="staffline">' + $('div#staffline_partner_1').html() + '</div>';
			partners += '<div id="staffline_partner_2" class="staffline">' + $('div#staffline_partner_2').html() + '</div>';
			$('div#staffline_partner_1, div#staffline_partner_2').remove();
			$('.staff_results').append($(partners));
			$('.staff_results div div.email span.emailLink').each(function(){
				jQuery('a:gt(0)', this).remove();
			});

		}
	
	});

// Accordion //

var TINY={};function T$(i){return document.getElementById(i)}function T$$(e,p){return p.getElementsByTagName(e)}TINY.accordion=function(){function slider(n){this.n=n;this.a=[]}slider.prototype.init=function(t,e,m,o,k){var a=T$(t),i=s=0,n=a.childNodes,l=n.length;this.s=k||0;this.m=m||0;for(i;i<l;i++){var v=n[i];if(v.nodeType!=3){this.a[s]={};this.a[s].h=h=T$$(e,v)[0];this.a[s].c=c=T$$('div',v)[0];h.onclick=new Function(this.n+'.pr(0,'+s+')');if(o==s){h.className=this.s;c.style.height='auto';c.d=1}else{c.style.height=0;c.d=-1}s++}}this.l=s};slider.prototype.pr=function(f,d){for(var i=0;i<this.l;i++){var h=this.a[i].h,c=this.a[i].c,k=c.style.height;k=k=='auto'?1:parseInt(k);clearInterval(c.t);if((k!=1&&c.d==-1)&&(f==1||i==d)){c.style.height='';c.m=c.offsetHeight;c.style.height=k+'px';c.d=1;h.className=this.s;su(c,1)}else if(k>0&&(f==-1||this.m||i==d)){c.d=-1;h.className='';su(c,-1)}}};function su(c){c.t=setInterval(function(){sl(c)},20)};function sl(c){var h=c.offsetHeight,d=c.d==1?c.m-h:h;c.style.height=h+(Math.ceil(d/5)*c.d)+'px';c.style.opacity=h/c.m;c.style.filter='alpha(opacity='+h*100/c.m+')';if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'}clearInterval(c.t)}};return{slider:slider}}();

function showcaptcha(myElement) {
var myElement
document.getElementById(myElement).style.display='block';
}


//  ESSEX LTD RSS FEEDS   //


(function($){$.fn.rssfeed=function(url,options){var defaults={limit:2,header:false,titletag:'h4',date:false,content:true,snippet:true,showerror:true,errormsg:'',key:null,ssl:false,linktarget:'_blank'};var options=$.extend(defaults,options);return this.each(function(i,e){var $e=$(e);var s='';if(options.ssl)s='s';if(!$e.hasClass('rssFeed'))$e.addClass('rssFeed');if(url==null)return false;var api="http"+s+"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+encodeURIComponent(url);if(options.limit!=null)api+="&num="+options.limit;if(options.key!=null)api+="&key="+options.key;api+="&output=json_xml"
$.getJSON(api,function(data){if(data.responseStatus==200){_callback(e,data.responseData,options);}else{if(options.showerror)
if(options.errormsg!=''){var msg=options.errormsg;}else{var msg=data.responseDetails;};$(e).html('<div class="rssError"><p>'+msg+'</p></div>');};});});};var _callback=function(e,data,options){var feeds=data.feed;if(!feeds){return false;}
var html='';var row='odd';var xml=getXMLDocument(data.xmlString);var xmlEntries=xml.getElementsByTagName('item');if(options.header)
html+='<div class="rssHeader">'+'<a href="'+feeds.link+'" title="'+feeds.description+'">'+feeds.title+'</a>'+'</div>';html+='<div class="rssBody">'+'<ul>';for(var i=0;i<feeds.entries.length;i++){var entry=feeds.entries[i];var entryDate=new Date(entry.publishedDate);var pubDate=entryDate.toLocaleDateString()+' '+entryDate.toLocaleTimeString();html+='<li class="rssRow '+row+'">'+'<'+options.titletag+'><a href="'+entry.link+'" title="View this feed at '+feeds.title+'" target="'+options.linktarget+'">'+entry.title+'</a></'+options.titletag+'>'
if(options.date)html+='<div>'+pubDate+'</div>'
if(options.content){if(options.snippet&&entry.contentSnippet!=''){var content=entry.contentSnippet;}else{var content=entry.content;}
html+='<p>'+content+'</p>'}
if(xmlEntries.length>0){var xmlMedia=xmlEntries[i].getElementsByTagName('enclosure');if(xmlMedia.length>0){html+='<div class="rssMedia"><div>Media files</div><ul>'
for(var m=0;m<xmlMedia.length;m++){var xmlUrl=xmlMedia[m].getAttribute("url");var xmlType=xmlMedia[m].getAttribute("type");var xmlSize=xmlMedia[m].getAttribute("length");html+='<li><a href="'+xmlUrl+'" title="Download this media">'+xmlUrl.split('/').pop()+'</a> ('+xmlType+', '+formatFilesize(xmlSize)+')</li>';}
html+='</ul></div>'}
html+='</li>';}
if(row=='odd'){row='even';}else{row='odd';}}
html+='</ul>'+'</div>'
$(e).html(html);};function formatFilesize(bytes){var s=['bytes','kb','MB','GB','TB','PB'];var e=Math.floor(Math.log(bytes)/Math.log(1024));return(bytes/Math.pow(1024,Math.floor(e))).toFixed(2)+" "+s[e];}
function getXMLDocument(string){var browser=navigator.appName;var xml;if(browser=='Microsoft Internet Explorer'){xml=new ActiveXObject('Microsoft.XMLDOM');xml.async='false'
xml.loadXML(string);}else{xml=(new DOMParser()).parseFromString(string,'text/xml');}
return xml;}})(jQuery);


$(document).ready(function () {
  $('#this_is_total_essex_business_news').rssfeed('http://www.thisistotalessex.co.uk/business.rss');
  
  $('#bbc_news_essex').rssfeed('http://feeds.bbci.co.uk/news/business/rss.xml');

  
});


//   ESSEX LTD BLOG   //

$(document).ready(function () {
  $('#essexltdblog').rssfeed('http://www.birkettlong.co.uk/essexlimitedblog/?feed=rss2', {
    limit: 2,
	date: true
  });
  
  // homepage RSS
  getRSS('#wp-blog-feed', 1, true);
  
});

// RSS function
function getRSS(object, limit, date){var html = '';$.ajax({type: 'GET',url: '/blog/feed/',dataType: 'xml',success: function(xml) {$(xml).find('item').each(function(i) {if (i > (limit-1)) return false;html += '<li><h4><a href="'+$(this).find('link').text()+'">'+$(this).find('title').text()+'</a></h4>';if (date) html += '<p>'+$(this).find('pubDate').text().substring(0, 16)+'</p>';html += '<p>'+$(this).find('description').text()+'</p></li>';return html;});$('#wp-blog-feed').html('<ul>'+html+'</ul>');}});}



