jQuery(function(){function stats(){this.t=_gat._getTracker('UA-4666065-1');this.t._trackPageview()};stats.prototype={trackPageview:function(url){if(url)this.t._trackPageview(url);else this.t._trackPageview()}};function storeLocator(){this.notChosen='Select';this.toggleSpeed='fast';this.countryIncrementer=0;this.cityIncrementer=0;this.init()};storeLocator.prototype={init:function(){$(document).bind('click',{scope:this},this.hide);this.replaceSelects('country');this.replaceSelects('city');$('#country-section, #city-section, #country-drop, #city-drop, .advanced').bind('click',function(e){e.stopPropagation()});$('#country-drop').disableTextSelect().bind('click',{scope:this},this.changeCountry);$('#city-drop').disableTextSelect().click(function(e){$(e.target).blur();e.preventDefault()});$('#country-select ul li a').bind('click',{scope:this},this.selectCountry);$('#city-select ul li a').bind('click',{scope:this},this.selectCity);if(!Boolean($('#search-text').val())&&!Boolean($('input:checkbox:not(:checked)').val())){$('a.advanced').bind('click',this.advanced).next().hide()}else{$('a.advanced').bind('click',this.advanced).addClass('current')}},replaceSelects:function(type){var val=this.getValue(type);var cls=this.visual(type);var markup='<input type="hidden" id="'+type+'" name="'+type+'" value="" /><div id="'+type+'-select"><div id="'+type+'-drop"><span>'+this.translateValue(val)+'</span> <a href="javascript:void(0);">v</a></div><div id="'+type+'-section" class="fold-layer'+cls+'"><ul class="column-1"></ul><ul class="column-2"></ul><ul class="column-3"></ul><div class="clear"></div></div></div>';var items=new Array();var ipc=Math.ceil($('#'+type+' option:not([value=""])').length/3);var col=0;var scope=this;$('#'+type+' option:not([value=""])').each(function(i){if((i%ipc==0)&&i>0)col++;if(items[col]==undefined){items[col]=scope.list(i,null,$(this).val(),true)}else{items[col]+=scope.list(i,null,$(this).val(),true)}});$('#'+type).replaceWith(markup);for(var i=0;i<items.length;i++)$('#'+type+'-section ul').eq(i).append(items[i]);this.setValue(type,val,true)},list:function(i,c,val,doReturn){if(val=='')return false;if(doReturn){return'<li><a href="#" title="'+val+'">'+val+'</a></li>'}else{var ipc=Math.ceil(c/3);var index=Math.floor(i/ipc);$('#city-section ul').eq(index).append('<li><a href="javascript:void(0);" title="'+val+'">'+val+'</a></li>')}},visual:function(type){if(type=='country'){var country=Boolean($('#country option:selected').val());if(country){return' hide'}else{this.countryIncrementer++}}else if(type=='city'){return' hide'}return''},getValue:function(type){var value=$('#'+type+' option:selected').val();return value},setValue:function(type,val,init){var reset=$('#'+type).val();$('#'+type).val(val);$('#'+type+'-select span:first').text(this.translateValue(val));$('#'+type+'-section ul li a[title='+reset+']').parent('li').removeClass('current');$('#'+type+'-section ul li a[title='+val+']').parent('li').addClass('current');if(type=='country'&&!init)this.resetValue();if($('#country').val()!='')$('#city-drop').bind('click',{scope:this},this.changeCity).find('span, a').css({backgroundColor:'#000'})},resetValue:function(){$('#city').val('');$('#city-select span:first').text(this.notChosen);$('#city-section ul li').removeClass('current')},translateValue:function(val){if(val=='')return this.notChosen;else return val},selectCountry:function(e){e.preventDefault();var country=$(this).attr('title');var scope=e.data.scope;scope.setValue('country',country,false);$.ajax({type:'POST',cache:false,url:'/wp-cities.php',dataType:'json',data:'country='+country,beforeSend:function(obj){$('#city-select ul').empty()},success:function(data){Stats.trackPageview('/stores/store-locator/'+country);var c=data.length;$.each(data,function(i,item){scope.list(i,c,item.city,false)});$('#city-select ul li a').bind('click',{scope:scope},scope.selectCity);$('#country-drop').trigger('click',true)}})},selectCity:function(e){e.preventDefault();e.data.scope.setValue('city',$(this).attr('title'),false);$('#store-form').triggerHandler('submit')},changeCountry:function(e,selectCountry){$(e.target).blur();e.preventDefault();var scope=e.data.scope;if(selectCountry){scope.countryIncrementer++;$('#country-section').slideToggle(scope.toggleSpeed,function(){scope.cityIncrementer++;$('#city-section').slideToggle(scope.toggleSpeed)});return true}if(scope.cityIncrementer%2==1){scope.cityIncrementer++;$('#city-section').slideToggle(scope.toggleSpeed,function(){scope.countryIncrementer++;$('#country-section').slideToggle(scope.toggleSpeed)})}else{scope.countryIncrementer++;$(this).parent().find('div:eq(1)').slideToggle(scope.toggleSpeed)}return true},changeCity:function(e){var scope=e.data.scope;if(scope.countryIncrementer%2==1){scope.countryIncrementer++;$('#country-section').slideToggle(scope.toggleSpeed,function(){scope.cityIncrementer++;$('#city-section').slideToggle(scope.toggleSpeed)})}else{scope.cityIncrementer++;$(this).parent().find('div:eq(1)').slideToggle(scope.toggleSpeed)}return true},hide:function(e){if(e.data.scope.countryIncrementer%2==1){e.data.scope.countryIncrementer++;$('#country-section').slideToggle(e.data.scope.toggleSpeed)}else if(e.data.scope.cityIncrementer%2==1){e.data.scope.cityIncrementer++;$('#city-section').slideToggle(e.data.scope.toggleSpeed)}return true},advanced:function(e){e.preventDefault();$(this).blur().toggleClass('current').next().slideToggle()}};function comments(){$('#comment-form').addClass('hide').submit(this.submit);$('#write-comment h3').wrapInner('<a></a>').find('a').attr('href','javascript:void(0);').click(this.toggle)};comments.prototype={submit:function(e){e.preventDefault();$.ajax({type:'POST',cache:false,url:'/wp-comments-ajax.php',dataType:'json',data:$(this).serialize(),timeout:60000,beforeSend:function(obj){$(e.target).find('#comment-error').remove();$(e.target).find('button').attr('disabled','disabled').after('<span></span>').next().show()},success:function(data,textStatus){Stats.trackPageview(window.location.href.toString()+'/comments/posted');$(e.target).find('button').removeAttr('disabled').next().remove();$(e.target).find('input[type="text"], textarea').val('');var header=$(data.comments_template).find('h2');var comment=$(data.comments_template).find('li:first');if(data.comment_type=='conventional'&&$('#comments-list').length>0){$('#comments-list').prepend(comment).find('li:first').show().highlightFade({color:'#d00d00',speed:3000,iterator:'sinusoidal'})}else if(data.comment_type=='conventional'){$('#comments-wrapper').prepend('<div></div>').find('div:first').attr('id','comments').append(header).append('<ol></ol>').find('ol').attr('id','comments-list').append(comment).find('li:last').show().highlightFade({color:'#d00d00',speed:3000,iterator:'sinusoidal'})}},error:function(obj,textStatus,errorThrown){Stats.trackPageview(window.location.href.toString()+'/comments/feedback');var error='';if(typeof(obj.responseText)=='string'&&obj.responseText!='')error=obj.responseText;else if(textStatus=='timeout')error='The server is taking too long to respond. Please try again later.';else error='Unknown error while submitting your comment. Try again?';$(e.target).find('fieldset').prepend('<div></div>').find('div:first').attr('id','comment-error').append('<p></p>').find('p').text(error);$(e.target).find('button').removeAttr('disabled').next().remove()}})},toggle:function(e){e.preventDefault();$(this).blur().parent('h3').next('form').slideToggle('normal')}};function forms(){this.vals=new Array();$('input.default-value').bind('focus',{scope:this},this.defaultValues);$('.async').bind('submit',this.submit)};forms.prototype={submit:function(e){e.preventDefault();$.ajax({type:'POST',cache:false,url:'/wp-form.php',dataType:'json',data:$(this).serialize(),timeout:60000,beforeSend:function(obj){$(e.target).find('#post-error').remove();$(e.target).find('button').attr('disabled','disabled').after('<span></span>').next().show()},success:function(data,textStatus){Stats.trackPageview($(e.target).find('input[name="logPath"]').val()+'/form/posted');var feedback=data.feedback;$(e.target).find('input[type="text"]').val('');$(e.target).find('fieldset').prepend('<div></div>').find('div:first').attr('id','post-error').css('background-color','#006600').append('<p></p>').find('p').text(feedback);$(e.target).find('button').removeAttr('disabled').next().remove()},error:function(obj,textStatus,errorThrown){Stats.trackPageview($(e.target).find('input[name="logPath"]').val()+'/form/feedback');var feedback='';if(typeof(obj.responseText)=='string'&&obj.responseText!='')feedback=obj.responseText;else if(textStatus=='timeout')feedback='The server is taking too long to respond. Please try again later.';else feedback='Unknown error while submitting your details. Try again?';$(e.target).find('fieldset').prepend('<div></div>').find('div:first').attr('id','post-error').append('<p></p>').find('p').text(feedback);$(e.target).find('button').removeAttr('disabled').next().remove()}})},defaultValues:function(e){var scope=e.data.scope;if(!scope.vals[$(this).attr('id')])scope.vals[$(this).attr('id')]=$(this).val();if($(this).val()==scope.vals[$(this).attr('id')])$(this).val('');$(this).blur(function(e){if($(this).val()=='')$(this).val(scope.vals[$(this).attr('id')])})}};var Stats=new stats();var StoreLocator=new storeLocator();var Comments=new comments();var Forms=new forms();$('.email a').defuscate();$('a[rel$="external"]').click(function(){window.open($(this).attr('href'));return false});$('#column-3 form').submit(function(e){e.preventDefault();var href=$(this).attr('action');var country=encodeURIComponent($(this).find('select').val()).replace(/%20/g,'+');if(country)href=href+'/'+country;window.location.href=href});$('#store-form').submit(function(e){e.preventDefault();var href=$(this).attr('action');var country=encodeURIComponent($(this).find('input[name="country"]').val()).replace(/%20/g,'+');var city=encodeURIComponent($(this).find('input[name="city"]').val()).replace(/%20/g,'+');var qs=$(this).find('input[type="checkbox"], input[name="text"]').serialize();if(country)href=href+'/'+country;if(city)href=href+'/'+city;if(qs)href=href+'/?'+qs;window.location.href=href});$('#search-form, #column-1 form').submit(function(e){e.preventDefault();window.location.href=$(this).attr('action')+'/search/'+encodeURIComponent($(this).find('input[name="s"]').val()).replace(/%20/g,'+')});$('#tools ul').prepend('<li class="print"><a href="javascript:window.print();" title="Print this page" rel="nofollow">Print</a></li>');if($('#store-list').size()>0){$('html,body').animate({scrollTop:$('#store-list').offset().top},300)}else if($('#country').val()){$('html,body').animate({scrollTop:$('#store-form').offset().top},300)}});