$(document).ready(function() {
  // Add class for javascript enabled, allows for easy css manipulation etc.
  $("body").addClass("javascript-enabled");
  
  // Email replacement using .mailto technique
	$("span.mailto").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>').remove();
	});
	
	// Open links in new window when rel="external" is present
	$('a[rel~=external]').each(function(){ this.target = "_blank"; });
  
  // Contact Form
  $('form#contact-form').validate();
  
  // Head heart
  $('#head').prepend('<div class="heart"></div>');
  
  // Whats new
  $("#whats_new").append('<ul class="navigation"><li class="previous"><a href="#">previous</a></li><li class="next"><a href="#">next</a></li></ul>');
  
  $("#whats_new ul.products").jcarousel({
    initCallback: setupCarousel,
    auto: 3,
    wrap: 'last',
    buttonNextHTML: null,
    buttonPrevHTML: null,
    scroll: 4
  });
  
  function setupCarousel(carousel) {
    $("#whats_new .navigation .previous a").bind('click',function() {
      carousel.prev();
      return false;
    })
    
    $("#whats_new .navigation .next a").bind('click',function() {
      carousel.next();
      return false;
    })
  }
  
  // Footer links
  $("div#foot ul.navigation").find("li:gt(0)").prepend('<span>/</span>').end().find('li a[href=terms_and_conditions.asp]').siblings('span').text('-');
  
  // Contact Form
  $("#contact-form").validate();  
  
  $('.thickbox').lightBox();
  
})
