/*
  Snowflakes plugin
  (P) PSNet, 2008 - 2011
  http://psnet.lookformp3.net/
*/

var ls = ls || {};

ls.nycheck = (function ($) {

  this.Settings = {
    'Update_Time': 60000,
    'Min_Before_Din_Din': 5
  },

  this.ProcId = '';
  
  // ---

  this.NYCheck = function () {
    Now = new Date ();
    if (
        (
          // before NY
          (Now.getMonth () == 11) &&                                            // 0..11
          (Now.getDate () == 31) &&                                             // 1..31
          (Now.getHours () == 23) &&                                            // 0..23
          (Now.getMinutes () + ls.nycheck.Settings.Min_Before_Din_Din >= 59)    // 0..59
        )
        ||
        (
          // few minutes after NY
          (Now.getMonth () == 0) &&                                             // 0..11
          (Now.getDate () == 1) &&                                              // 1..31
          (Now.getHours () == 0) &&                                             // 0..23
          (Now.getMinutes () <= ls.nycheck.Settings.Min_Before_Din_Din)         // 0..59
        )
       ) 
    {
      // Din Din Din!!! NY
      ls.nycheck.StopTimer ();
      
      $.cookie ('run_ny_party', '1');

      if (confirm (Snowflakes_NY_Msg)) {
        window.location.href = Snowflakes_URL_To_Go;
      }
    }
  }
  
  // ---
  
  this.StopTimer = function () {
    clearInterval (this.ProcId);
  }
  
  // ---
  
  this.RunAutoCheckUp = function (New_Settings) {
    AlreadyDone = $.cookie ('run_ny_party');
    if (AlreadyDone) return false;
    
    if (New_Settings) {
      this.Settings = $.extend ({}, this.Settings, New_Settings);
    }
    this.ProcId = setInterval (this.NYCheck, this.Settings ['Update_Time']);
  }

  // ---
  
  return this;

}).call (ls.nycheck || {}, jQuery);

