jQuery(document).ready(function($) {
  
  $(".obf").each(function(){  
    var self = $(this);
    var email = this.tagName.toLowerCase() == 'a' ? self.attr('href') : self.html();
    email = email.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
    if(this.tagName.toLowerCase() == 'a'){
      if(self.html() == self.attr('href')){
        self.html(email);
      }
      self.attr('href','mailto:'+email);
    }else{
      self.html(email)
    }
  });
  
  
	$("#panel-toggle").click(function(e){
	  e.preventDefault();
	  var self = $(this);
	  self.toggleClass('on').html(self.hasClass('on') ? self.html().replace('+', '-') : self.html().replace('-', '+'))
		$('#links-panel').slideToggle('fast');
		
		if(self.hasClass('on')){
		  $('#contact-tab.on').click()
		}
	});
	
	$('#contact-tab').toggle(function(){
	  var right = $(this).parent();
	  $(this).addClass('on');
	  right.animate({right: 0}, 300);
	  if(right.height() > $('#main').height()) {
	    $('#main').height(right.height() + parseInt(right.css('top')));
	  }
	  
	  $('#panel-toggle.on').click()
	},function(){
	  $(this).removeClass('on')
	  var right = $(this).parent()
	  right.animate({right: -230}, 300)
	})
	  
	
	$("ul#nav .li1").hover(
    function () {
      $(this).addClass("hover");
    },
    function () {
      $(this).removeClass("hover");
    }
  );
  
  $('#bookmark').jFav();
  
  
  
  $('#enquiry-form').validate({
    rules: {
      'enquiry[captcha]': {
        required: true,
        rangelength: [4, 4],
        remote: {
          url: '/captcha-check',
          type: 'post',
          data: {
            form: 'enquiry'
          }
        }
      }
    },
    messages: {
      'enquiry[captcha]': {
        rangelength: 'Exacly 4 characters.',
        remote: 'You enterd wrong code.<br />Click the image to reload.'
      }
    }
  });
  $('#subscribe-form').validate();
  $('#home-subscribe-form').validate();
  $('#invoice-form').validate();
});