/* <3 JS */

var rubino = {};

rubino.init = function() {
  rubino.tabs();
  rubino.modals('#make-apt','#modal');
  rubino.validateForm();
  $("#date").datepicker();
};

rubino.validateForm = function() {
  $("#contactform").validate({
    rules: {
    	name: "required",
    	email: {
    		required: true,
    		email: true
    	},
    	time: "required",
    	date: "required",
    	human: {
    		minlength: 3
    	}
    },
    // messages: {
    //      firstname: "Please enter your firstname",
    //      lastname: "Please enter your lastname",
    //      username: {
    //        required: "Please enter a username",
    //        minlength: "Your username must consist of at least 2 characters"
    //      },
    //      password: {
    //        required: "Please provide a password",
    //        minlength: "Your password must be at least 5 characters long"
    //      },
    //      confirm_password: {
    //        required: "Please provide a password",
    //        minlength: "Your password must be at least 5 characters long",
    //        equalTo: "Please enter the same password as above"
    //      },
    //      email: "Please enter a valid email address",
    //      agree: "Please accept our policy"
    //     }
  });
};

rubino.tabs = function() {
  $("#main-navigation ul").tabs("div.panes > div.pane", {
  	effect: 'fade'
  });
};

rubino.modals = function(btn,modal){
  var $btn = $(btn);
  var $modal = $(modal);
  var $overlay = $('#overlay');
  var $close = $('a.close', $modal);
  
  // set overlay height
  var docHeight = $(document).height();
  $overlay.css({ height : docHeight });
  
  // open link
  $btn.live('click', function(e){      
    e.preventDefault();
    
    var $url = $(this).attr("href");
    
    $overlay.fadeTo('fast',.5,function(){
      
      // center modal
      $modal.css("top", ($(window).height() - 600) / 2+$(window).scrollTop() + "px");
      $modal.css("left", ($(window).width() - $modal.width() ) / 2+$(window).scrollLeft() + "px");
      
      //fade in modal
      $modal.fadeIn('slow');
    });
  });
  
  // overlay close
  $overlay.click(function(){
    $modal.fadeOut('slow',function(){
      $overlay.fadeOut('fast');
    });
  });
  
  // close
  $close.live("click", function(e){
    e.preventDefault();
    $modal.fadeOut('slow',function(){
      $overlay.fadeOut('fast');
    });
  });
};

$(function() { rubino.init(); });

