$(document).ready( function() {
    //form validation
    $("#consultation").validate({
        invalidHandler: function(form, validator) {
          var errors = validator.numberOfInvalids();
          if (errors) {
            $.blockUI({ css: { 
              border: 'none', 
              padding: '15px', 
              backgroundColor: '#fff', 
              '-webkit-border-radius': '10px', 
              '-moz-border-radius': '10px', 
              opacity: .8, 
              color: '#fff' 
            },
            message: '<span class="error_message">Please fill in the fields with a <img src="../images/core/icon-cross.gif" alt="x" /> and press submit</span>'
          }); 
            
          setTimeout($.unblockUI, 5000);
          }
        },
        rules: {
          sCapText: {
            remote: {
              url: "../captcha/remot_vatidation.asp",
              type: "post"
            }
          }
        }
     });
    
    $("li#cap a.change").click(function() {
      var MyTime = new Date()

      $("li#cap").each(function() {
        $(this).find("div.image").find("img").attr("src","http://www.viatek.com.au/captcha/cap_image.asp?time=" + MyTime.getTime() + "")
      });

      return false;
    });
    
    //email replacement
    $("span.safemail").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, ".");
        emaillink = match[2] ? match[2] : addr;
        subject = $(this).attr('title') ? "?subject=" + $(this).attr('title').replace(/ /g, "%20") : "";
        $(this).after('<a id="nav-email" href="mailto:' + addr + subject + '">' + emaillink + '</a>');
        $(this).remove();
    });
});


//Calculates Slide Timeout
function calculateTimeout(currElement, nextElement, opts, isForward) {
  
  //default time out 4secs
  var timeout = 4000;
  
  //gets current slide 0 based index
  var slide = opts.currSlide;
  switch(slide)
  {
    case 1:
    timeout = 10000
    break; 
    case 2:
    timeout = 10000
    break;
    case 3:
    timeout = 10000
  }
  
  return timeout;
}
