var lightboxColor = "#000000";

var opacity = 0.8;



$(document).ready(function() {

  

  $(window).resize(function() {

    setMaxHeight();

  });

  

  $("form#contact-form").submit(function(e) {

    var validated = true;

    var errorMsg = "Please fill in the following to send your message: ";

    var missing ;

    $("form#contact-form .kbcontact").each(function() {

      if ( $.trim($(this).val()).length == 0 ) {

        $(this).val("");

        if ( typeof missing == "undefined") {

          // first in the list

          missing = $(this).attr("name");

          validated = false;

        } else {

          missing = missing + ", " + $(this).attr("name");

        }

      }

    });

    if ( !validated ) {

      alert(errorMsg + missing);

      e.preventDefault();

    }

  });

  

  contactFormFeedback();

  

  /********************************************

    Fancybox:

    For image, specify width and height of

    enlarged image. Replace "a.flyer-img"

    with element class name or ID.

    

    For video, specify width and height. Title

    attribute in the anchor tag will display as

    video title below the video.

  ********************************************/

    

  $("a#video-promo").click(function() {    

    $.fancybox({

       'padding'       : 0,

       'autoScale'     : false,

       'transitionIn'  : 'none',

       'transitionOut' : 'none',

        'overlayColor'  : lightboxColor,

        'overlayOpacity': opacity,

        'centerOnScroll': true,

       'title'         : this.title,

       'width'         : 640,

       'height'        : 385,

       'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),

       'type'          : 'swf',

       'swf'           : {'wmode'             : 'transparent',

                          'allowfullscreen'   : 'true'}

    });

    return false;

  });

  

  $("a.flyer-img").fancybox({

        'width'         : 466,

       'height'        : 700,

        'padding'       : 0,

        'centerOnScroll': true,

        'overlayColor'  : lightboxColor,

        'overlayOpacity': opacity

  });

});



$(window).load(function() {

  setMaxHeight();

});



function setMaxHeight() {

  var winHeight = $(window).height();

  var docHeight = $("#body-content-wrapper").height();

  if ( winHeight > docHeight ) {

    $("#body-content-wrapper, #main-container").height($(document).height());

  }

}

function setMaxHeightWidget(h) {

  var winHeight = $(window).height();

  var docHeight = $("#body-content-wrapper").height()+h;

  if ( winHeight > docHeight ) {

    $("#body-content-wrapper, #main-container").height($(document).height());

  }

}

function contactFormFeedback() {

  var feedbackType = document.location.hash;

  switch (feedbackType) {

  case "#error":

    $(".error").show();

    break;

  case "#success":

    $(".success").show();

    break;

  }

}
