// Array indexOf fix for IE because IE is lame
// Source: http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    };
}

// Reference: http://css-tricks.com/3458-perfect-full-page-background-image/
$(window).load(function() {    

        var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {

                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");

});

$(document).ready(function () {
  var hideWaiver = Cookies.get('waiver');
  
  if(!hideWaiver) {
    $.fancybox($('#waiver'));
    
    $('#close').click(function () {
      $.fancybox.close();
    });
    
    $('#close-noshow').click(function () {
      Cookies.set('waiver', true);
      $.fancybox.close();
    });
  }
});

var Cookies = {
  expirationDays: 365,
  
  set: function (name, value) {
    var date = new Date();
    date.setDate(date.getDate() + Cookies.expirationDays);
    
    value = escape(value) + ";expires=" + date.toUTCString();
    document.cookie = name + "=" + value;
  },
  
  get: function (name) {
    var i, x, y, cookies = document.cookie.split(';');
    for(i = 0; i < cookies.length; i++) {
      x = cookies[i].substr(0, cookies[i].indexOf('='));
      y = cookies[i].substr(cookies[i].indexOf('=') + 1);
      x = x.replace(/^\s+|\s+$/g,"");
      if(x == name) {
        return unescape(y);
      }
    }
  }
};
