(function($){$(document).ready(function(){$('nav ul').find('li:last').addClass('last');var subMenu=$('header nav ul ul');var wasShown=subMenu.parent().hasClass('active');wasShown||subMenu.parent().addClass('active');var itemsWidth=0;subMenu.find('li').each(function(){itemsWidth+=$(this).outerWidth()
+parseInt($(this).css('padding-left'))
+parseInt($(this).css('padding-right'));});subMenu.css('width',itemsWidth+'px');wasShown||subMenu.parent().removeClass('active');subMenu.css('left',-(subMenu.outerWidth()/2+45));$('.share-item').find('.showshare').click(function(event){event.preventDefault();$(this).parent().find('.share-buttons').fadeIn(200);$(this).hide();});$('.share-buttons').hide();setupSectionNavigation();function setupSectionNavigation(){var articleElement=$('#main article');if(articleElement.find('section').length>1){articleElement.find('section').addClass('minheight');articleElement.find('section').first().addClass('center');articleElement.find('section:not(.first)').addClass('hidden');var dots=$('<ol>');for(var a=0;a<articleElement.find('section').length;a+=1){dots.append($('<li>',{"class":(a==articleElement.find('section').length-1)?'last':''}).html($('<a>',{"href":'#s'+(a+1)}).html(a+1)));}
dots.find('li:first-child').addClass('active');function showSection(index){var articleElement=$('#main article');if(articleElement.find('section').length<=index){index=articleElement.find('section').length-1;}
var chosenSection=$(articleElement.find('section')[index]);if(chosenSection.is(':hidden')){fadeReplace(articleElement.find('section:not(:hidden)'),chosenSection);articleElement.find('#section-nav li.active').removeClass('active');$(articleElement.find('#section-nav li')[index]).addClass('active');if(index<articleElement.find('section').length-1){articleElement.find('#section-nav a.more').attr('href','#s'+(index+2)).html('Read more');}
else{articleElement.find('#section-nav a.more').attr('href','#s1').html('Back to start');}
if(index==0){$('#section-nav').addClass('first').find('.more').html('Find out more');$('.newsletter, .share-item').addClass('center');}
else{$('#section-nav').removeClass('first');$('.newsletter, .share-item').removeClass('center');}}}
articleElement.append($('<div>',{"id":'section-nav',"class":'first'}).append($('<a>',{"href":'#s2',"class":'more'}).html('Find out more'),$('<div>',{"class":'wrap'}).html(dots),$('<div>',{"class":'clearfix'})));$('#section-nav',articleElement).insertBefore($('.newsletter',articleElement));articleElement.find('#section-nav  a').click(function(event){event.preventDefault();var sectionNumber=$(this).attr('href').substr(2);showSection(sectionNumber-1);if(typeof(window.history.pushState)!=='function'){window.location.hash='#s'+sectionNumber;}
else{window.history.pushState({"section":sectionNumber},window.title,'#s'+sectionNumber);}});$('.newsletter, .share-item').addClass('center');}
window.onpopstate=function(event){if(typeof showSection=='function'){var sectionMatch=/^#s(\d+)$/i.exec(window.location.hash);var activeSection=sectionMatch?sectionMatch[1]:1;showSection(activeSection-1);}}
if(typeof showSection=='function')
{var sectionMatch=/^#s(\d+)$/i.exec(window.location.hash);var activeSection=sectionMatch?sectionMatch[1]:1;showSection(activeSection-1);}}
function fadeReplace(original,replacement,callBack){$(original).fadeOut(300,function(){$(original.parent().find('section')).addClass('hidden');$(replacement).removeClass('hidden').hide();$(replacement).fadeIn(300,typeof(callback)=='function'?callback:function(){});});}
$('a[href="/products/sample"]').click(function(event){event.preventDefault();var doLoad=function(){$.ajax({"url":'/api/sample/form.json',"type":'get','dataType':'json','success':function(data){if(data.status==200){$('body').append(data.data.html);Recaptcha.create("6Lcd0cwSAAAAAI9CscUUykvgySDAbAhw6XfPv2sM","recaptcha_placeholder",{"theme":"white","callback":function(){}});$('#order-sample input').first().focus();$('#order-sample .close, #darkenlayer').click(function(event){event.preventDefault();$('#order-sample, #darkenlayer').fadeOut(150,function(){$(this).remove();});});}
else{window.location=$(this).attr('href');}},'error':function(){window.location=$(this).attr('href');}})}
if(typeof Recaptcha=='undefined'){$.getScript("http://www.google.com/recaptcha/api/js/recaptcha_ajax.js",doLoad);}
else{doLoad();}})});})(jQuery);

