

if(window.Cufon && !(!!$.browser.msie && $.browser.version<8)){
 Cufon.replace('#nav li>a',{fontFamily:'futura'});
 Cufon.replace('#newsletter p.title',{fontFamily:'futura'});
 Cufon.replace('#header p.title',{fontFamily:'futura'});
 Cufon.replace('#content h2',{fontFamily:'futura'});
 Cufon.replace('#content h3',{fontFamily:'futura'});
 Cufon.replace('#tertiary .big',{fontFamily:'futura'});
 Cufon.replace('#trade .place',{fontFamily:'futura'});
 Cufon.replace('#footer ul li a',{fontFamily:'futura'});
}
 
$(function(){

 function correct_heights(){
  $('#image,#content').css({minHeight:'',height:''});
  var set=Math.max($(window).height()-$('#footer').height(),$('#image').height(),$('#content').height());

  if($.support.minHeight())
   $('#image,#content').css({minHeight:set});
  else
   $('#image,#content').css({height:set});
 }
 correct_heights();
 
 $('#footer ul').css({marginLeft:($('#footer .wrap').outerWidth()-$('#footer ul').outerWidth())});
 
 $('#nav>ul>li>a').click(function(){
  var $ul=$(this).parent().find('ul:not(.nope)');

  if($ul.length){
   if(!$ul.is(':visible'))
    $('#nav ul ul:visible').slideUp();

   $ul.slideToggle(function(){});
   return false;

  }else if($(this).attr('href')=='#')
   return false;
 });
 
 $('#product .image a.lightbox').each(function(){
  $(this).lightBox();
 });

 $('#product p.images a').click(function(){
  $('#product .image > a').hide();
  $('#product .image > a.'+$(this).attr('data-type')).show();
  
  $(this).siblings('a').removeClass('on');
  $(this).addClass('on');
  return false;
 });
 
 $('img.swap').each(function(){
  var images=[$(this).attr('src'),$(this).attr('rel')],i=1,obj=this,
   swap=function(){$(obj).attr('src',images[(i++)%2]||images[0]);};
  
  $(this).parent().bind('mouseover mouseout',swap);
  (new Image()).src=images[1];
 });

 if($('#header').length){
  var header_current=0,header_timer=parseInt($('.header-block','#header').first().attr('data-timer'),10),
   header_width=$('.header-block','#header').first().width(),header_to=null;

  $('a.prev,a.next','#header').live('click',function(){
   window.clearTimeout(header_to);
   var dir=$(this).is('.prev')?-1:+1;

   header_current+=dir;
   if(header_current<0) header_current=$('.header-block','#header').length-1;
   if(header_current>$('.header-block','#header').length-1) header_current=0;
   
   $('#header-runner').stop().animate({left:-header_current*header_width},{duration:600,easing:'swing'});
   return false;
  });
  
  function auto(){
   header_current++;
   if(header_current>$('.header-block','#header').length-1) header_current=0;
   $('#header-runner').stop().animate({left:-header_current*header_width},{duration:600,easing:'swing'});

   header_to=window.setTimeout(auto,header_timer*1000);
  }
  
  if(header_timer>0)
   header_to=window.setTimeout(auto,header_timer*1000);
 }
 
 var pb_index=0;
 $('#product-belt').append('<a href="#" class="left"></a><a href="#" class="right"></a>').find('>a').click(function(){
  var dir=$(this).is('.left')?-1:+1;
  pb_index=Math.max(0,Math.min(pb_index+dir,Math.ceil($('#product-belt .result').length/5)-1));
  $('#product-belt-runner').stop().animate({left:-pb_index*748},{duration:600,easing:'swing'});
  
  return false;
 });
 
 $('input[type=text]').each(function(){
  var def=$(this).attr('data-default');
 
  if(def) $(this)
   .focus(function(){if($(this).val()==def) $(this).val('');})
   .blur(function(){if($(this).val()=='') $(this).val(def);});
 });
 
 $('.advanced-search').each(function(){
  var div=this;
  
  $('li:has(input)',this).addClass('click');

  $('ul.all li',this).click(function(e){
   if(e.target.tagName.toLowerCase()!='input')
    $('input[type=checkbox]',this).attr('checked',!$('[type=checkbox]',this).attr('checked'));

   $('ul.list input[type=checkbox]',div).attr('checked',false);
   return $.browser.msie;
  });

  $('ul.list li',this).click(function(e){
   if(e.target.tagName.toLowerCase()!='input')
    $('input[type=checkbox]',this).attr('checked',!$('input[type=checkbox]',this).attr('checked'));

   $('ul.all input[type=checkbox]',div).attr('checked',false);
   return $.browser.msie;
  });
  
  var uncheck=false;
  $('ul.list li',this).each(function(){uncheck=uncheck||$('input[type=checkbox]',this).attr('checked');});
  $('ul.all li input[type=checkbox]',this).attr('checked',!uncheck);
 });
 
 var _search=new search(path.local+'products/search_design_name',$('#quick-design_name input[type=text]'),$('#quick-design_name ul'));

 
 $('.location a.map').live('click',function(){
  if($('#google-map').length){
   $('#google-map').remove();
  }
  
  var $l=$(this).parents('.location'),a=$l.find('.address').html(),$n=$l.next('.location');
  if(!$n.length) $n=$l;
  
  ($l.index()%2?$l:$n).after('<div id="google-map" style="width:748px;height:300px;"></div>');

  var map=new google.maps.Map(document.getElementById('google-map'),{zoom:16,mapTypeId:google.maps.MapTypeId.ROADMAP});
  var geocoder=new google.maps.Geocoder();
  geocoder.geocode({'address':a},function(results,status){
   if(status==google.maps.GeocoderStatus.OK){
    map.setCenter(results[0].geometry.location);
    var marker=new google.maps.Marker({map:map,position: results[0].geometry.location});
   }else
    alert('Geocode was not successful for the following reason: '+status);
  });
  
  correct_heights();
  return false;
 });
 
 $('.location').equalHeights();
 $(window).load(correct_heights);
});





var search=function(url,input,ul){
 this.url=url;
 this.$input=input.jquery && input || $(input);
 this.$ul=ul.jquery && ul || $(ul);
 this.default_value=this.$input.val();
 
 this.position=0;
 this.q='';
 this.results=[];
 this.cache={};

 var s=this;
 this.$input
  .focus(function(){s.focus();})
  .blur(function(){s.blur();})
  .keydown(function(e){return s.keydown(e);})
  .keyup(function(e){s.keyup(e);});

 this.$ul.find('li').live('mouseover mousemove',function(){
  var index=$(this).index();
  
  if(s.position!=index){
   s.position=index;
   s.$ul.find('li').removeClass('selected');
   $(this).addClass('selected');
  }
 });

 this.$ul.find('li').live('click',function(){
  s.$ul.find('li').removeClass('selected');
  $(this).addClass('selected');
  s.$input.val(s.$ul.find('li.selected').attr('data'));
 });
};
search.prototype={
 focus:function(){
  this.$input.addClass('open');
  this.$input.val()==this.default_value && this.$input.val('');
  this.search();
 },
 blur:function(){
  this.$input.removeClass('open');
  this.$input.val()=='' && this.$input.val(this.default_value);
  var s=this;
  window.setTimeout(function(){s.$ul.hide();},100);
 },
 keydown:function(e){
  var code=e.which||e.keyCode||e.charCode||0;
  switch(code){
   case 9 : this.$input.val(this.$ul.find('li.selected').attr('data')).get(0).focus();return false;break;
   case 13 : this.go();return false;break;
   case 27 : this.$input[0].blur();return false;break;
   default : break;
  };
  return true;
 },
 keyup:function(e){
  var code=e.which||e.keyCode||e.charCode||0;
  switch(code){
   case 9 : case 13 : case 27 : break;
   case 38 : this.move(-1);return;
   case 40 : this.move(+1);return;
   default : this.search();return;
  };
 },
 move:function(d){
  this.$ul.find('li').removeClass('selected');

  if((this.position+d)<0)
   this.position=this.$ul.find('li').length-1;
  else if((this.position+d)>=this.$ul.find('li').length)
   this.position=0;
  else
   this.position+=d;
 
  this.$ul.find('li:eq('+this.position+')').addClass('selected');
 },
 search:function(){
  this.q=this.$input.val().replace(/[^0-9a-z \.-]/gi,'');
  this.position=0;
  this.results=[];

  if(this.q==''){
   this.$ul.html('').hide();
   return false;
  }
 
  if(this.cache['_'+this.q] && '_'+this.q in this.cache){
   this.results=this.cache['_'+this.q];
   this.populate();
   return;
  };
 
  this.$ul.html('<li class="loading">&nbsp;</li>').show();

  var s=this;
  $.getJSON(this.url,{q:this.q},function(json){
   if(!('_'+s.q in s.cache)){
    $.each(json||[],function(i,item){s.results.push(item);});
    s.cache['_'+s.q]=s.results;
   }
   s.populate();
  });
 },
 populate:function(){
  var html=[],item={};
 
  for(var i=0,l=this.results.length;i<l;i++){
   item=this.results[i];
   html.push('<li'+(!i?' class="selected"':'')+' data="'+item.result+'">'+
    item.result.replace(new RegExp('('+this.q+')','gi'),'<span>$1</span>')+'</li>');
  }
  this.$ul.html(html.length>0?html.join(''):'<li>No results found</li>').show();
 },
 go:function(){
  if(this.$ul.is(':hidden')){
   this.$input.parents('form')[0].submit();
  }else{
   this.$input.val(this.results[this.position].result);
   this.$ul.hide();
  }
 }
};



(function($){
 $.extend($.support,{
  minHeight:function(){
   var id='minheightsupport'+(new Date).getTime();
   $('<div></div>').attr('id',id).css({
    height:'1px',
    minHeight:'2px',
    overflow:'hidden',
    border:'none',
    padding:'0',
    margin:'0'
   }).appendTo('body');

   var iscorrectheight=document.getElementById(id).offsetHeight==2;
   $('#'+id).remove();
   return iscorrectheight;
  }
 });
})(jQuery);

(function($){
 $.fn.headings=function(opts){
 $(this).each(function(){
  var o=$.extend({
  text:$(this).html(),
  h:$(this).height(),
  font_size:parseInt($(this).css('font-size'),10),
  font_color:hex($(this).css('color')),
  bgcolor:'ffffff',
  shadow_color:'000000',
  position:'0 0',
  website:website,
  r:Math.random()
  },opts||{}),_o=[];
  
  for(var k in o)
  _o.push(k+'='+escape(o[k]));
  
  $.data(this,'text',o.text);

  $(this)
  .width($(this).width()).height($(this).height()).html('')
  .css({background:'url('+path.global+'heading.php?'+_o.join('&')+') '+o.position+' no-repeat'});
 });
 }
})(jQuery);

(function($){
 $.fn.equalHeights=function(minheight){
 var maxheight=minheight||0;
 $(this).each(function(){
  maxheight=($(this).height()>maxheight)?$(this).height():maxheight;
 });
 $(this).css('height',maxheight);
 }
})(jQuery);