/**
* Main Modal Tools for Revolution Golf
*
* REQUIRES:
*	 jQuery: http://jquery.com/
*	 jQuery UI: http://jqueryui.com/
*
* AUTHOR:
*	 Brian Manning <bmanning@bootsoft.com>
*/

var modal = {
  CUSTOM_TEXT: {
    COMMENTS: "<span>Got something to say? Have an important question on a video lesson?</span> " +
                "Join in on the conversation with our teaching professionals and other experts! " +
                "Registering for your free membership at Revolution Golf gives you the power to " +
                "leave comments, ask questions and help others. You'll also be able to fully control " +
                "and customize the types of alerts the system will send to your email box or mobile " +
                "phone when our experts or other members respond to your comments. " +
                "<a href=\"/Home/MembershipPrivileges\">Click here</a> for a " +
                "complete listing of all the benefits included in your free membership!",
    RATING: "<span>Rate each video by clicking the Stars!</span> Here's how it works:" +
                "<ul>" +
                "<li>After rating a video on a scale of 1 to 5 stars, your rating will added to other " +
                "member scores to send the highest rated videos into the \"Most Popular\" section for all to see.</li>" +
                "<li>Once you register for your free membership, you'll be shown your \"Personal Star Ratings\" " +
                "for each video as you surf through our library... and you'll also be able to send the videos " +
                "into your personal \"Favorites\" library with a simple click!</li>" +
                "</ul>" +
                "Register now to gain these features and dozens of other powerful tools that will " +
                "turbo-charge your time at our website and enhance your viewing experience. " +
                "<a href=\"/Home/MembershipPrivileges\">Click here</a> " +
                "to see a complete listing of these and other membership benefits!",
    FAVORITES: "<span>You know what you like!</span> Why not have it at your fingertips. Once you register for " +
                "your free membership at Revolution Golf, you'll be able to send your \"Favorite\" videos into your " +
                "personal Favorites Library with one simple click. You'll also be able to organize and sort your " +
                "Favorites by Expert, by Interest, and by Playing Level (Free or Purchased videos). These features " +
                "will prove invaluable when you want to re-watch your Favorite videos in the future. " +
                "<a href=\"/Home/MembershipPrivileges\">Click here</a> " +
                "for a complete listing of all the benefits included in your free membership!",
    INVITATIONS: "<span>It's good to have friends!</span> Once you register for your free membership at " +
                "Revolution Golf, every time you invite a friend who registers -- you'll  earn \"Stroke Saving " +
                "Reward Points\" to purchase our premium golf instruction programs. Registration is quick, easy, " +
                "and loaded with powerful members-only tools. <a href=\"/Home/MembershipPrivileges\">Click here</a> " +
                "for a complete listing of all the benefits " +
                "included in your free membership!",
    ACCOUNT: "<span>Take control of your game!</span> Register for your free membership to gain complete " +
                "control over your golf improvement experience at Revolution Golf. As a member of Revolution Golf you can:" +
                "<ul>" +
                "<li>Rate videos (your both your, and the community's benefit)</li>" +
                "<li>Add videos to your Favorites list (to easily re-visit our favorites later)</li>" +
                "<li>Engage our teaching professionals, our experts, and other members in the discussions " +
                "you'll find below each video</li>" +
                "<li>Get automatic alerts (either by email or text-to-phone) when important events take place " +
                "on the site (that you are interested in).</li>" +
                "<li>Earn valuable \"Stroke Saving\" Reward Points to get our premium instructional productions " +
                "for free...and much, much more. )</li>" +
                "<li><a href=\"/Home/MembershipPrivileges\">Click here</a> for a complete listing of membership benefits.</li>" +
                "</ul>",
    GAME_TRACKER: "<span>If you can't measure it, you can't manage it!</span> Register for your free " +
                "membership and start tracking where you're losing your shots. As a member of Revolution " +
                "Golf, using our Game Tracker application, you can:" +
                "<ul>" +
                "<li>Keep track of fairways and greens in regulation, how many putts and your average first " +
                "putt length, how often you get the ball up and down, and much, much more.</li>" +
                "<li>See how your longer term stats stack up. Are there two areas you can improve in that " +
                "would cut 4-8 strokes from your game? Do you 3 putt multiple times during your average round? " +
                "Do you miss most of your fairways on one direction? Do you miss most greens in a particular " +
                "direction? Wouldn't it be nice to know?</li>" +
                "<li>Once the courses you play are in the system, it only takes minutes to keep track of this " +
                "valuable data.</li>" +
                "<li>With our upcoming mobile app, you can \"push\" all this valuable data to the Game Tracker " +
                "application with your smart phone. With just a few clicks, you know exactly what you need " +
                "to be working on. </li>" +
                "<li><a href=\"/Home/MembershipPrivileges\">Click here</a> for a complete listing of membership benefits.</li>" +
                "</ul>",
    REGISTRATION: " for registering with <b>Revolution Golf!</b> We have sent you an email with your password for your records.</p><br />" +
                      "<p>We've designed this website to help you get better at the game of golf, and help you improve in a whole new way!</p><br />" +
                      "<p>The video player you see on our home page is the heart of the website. In this player, you'll be able to view our <b>Daily Free Video Tips</b> (from our teaching professionals and other golf related experts), as well as your <b>\"Premium Golf Instruction Products\"</b> that you have purchased. You'll find a <b>\"Your Products\"</b> link right above the main video player where you can access all of your <b>Premium Products</b>. You can also ask questions about each video and get answers directly from our experts. To the right of the video player is a <b>\"Playlist\"</b>, with other videos designed to help you improve your game.</p><br />" +
                      "<p><a id=\"enjoy\" class=\"registerLink\" onclick=\"modal.close();return false;\" href=\"#\">Enjoy!</a></p>",
    BLANK: ""
  },
  modalWindow: null,
  registerModalWindow: null,
  loginModalWindow: null,
  thankYouModalWindow: null,
  orderProcessingModalWindow: null,
  init: function () {
    this.modalWindow = $("#modal");
    this.thankYouModalWindow = $("#thankYouModal");
    this.loginModalWindow = $("#loginModal");
    this.registerModalWindow = $("#registerModal");
    this.orderProcessingModalWindow = $("#orderProcessingModal");
    this.initModal();
  },

  initModal: function () {
    this.modalWindow.dialog({
      autoOpen: false,
      modal: true
    });
  },

  setHtml: function (html) {
    this.modalWindow.html(html);
  },

  setTitle: function (title) {
    this.modalWindow.dialog("option", "title", title);
  },

  setText: function (text) {
    this.modalWindow.dialog("destroy");
    this.initModal();
    this.setHtml("<p class='simpleText'>" + text + "</p>");
  },

  setWidth: function (width) {
    this.modalWindow.dialog("option", "width", width);
  },

  getWidth: function () {
    return this.modalWindow.dialog("option", "width");
  },

  setPosition: function (position) {
    this.modalWindow.dialog("option", "position", position);
  },

  open: function () {
    this.modalWindow.dialog("open");
  },
  openOrderProcessingModal: function () {
    this.setHtml(this.orderProcessingModalWindow.html());
    //destroying and rebuilding it to adjust to new html

    this.modalWindow.dialog("destroy");
    this.initModal();
    this.modalWindow.dialog("option", "width", 700);
    this.modalWindow.dialog("option", "height", 420);
    this.modalWindow.dialog("option", "position", ["center", 200]);
    this.modalWindow.dialog("open");
    $('.ui-dialog-titlebar-close').hide();
  },
  openRegisterModal: function () {
    this.setHtml(this.registerModalWindow.html());

    //destroying and rebuilding it to adjust to new html
    this.modalWindow.dialog("destroy");
    this.initModal();

    this.modalWindow.dialog("option", "width", 700);
    this.modalWindow.dialog("option", "height", 600);
    this.modalWindow.dialog("option", "position", ["center", 200]);
    this.modalWindow.dialog("open");
  },
  openRegisterSpecialModal: function (modalContent, callback) {
    this.setHtml(modalContent.html());

    //destroying and rebuilding it to adjust to new html
    this.modalWindow.dialog("destroy");
    this.initModal();

    var modalWidth = modalContent.find(".modalWidth").val();
    var modalHeight = modalContent.find(".modalHeight").val();

    if (undefined == modalWidth) {
      modalWidth = 700;
    }

    if (undefined == modalHeight || "" == modalHeight) {
      modalHeight = modalContent.height() - 13;
    }

    $("div.ui-dialog").css("width", modalWidth)
            .css("height", modalHeight);

    $("#modal").css("width", modalWidth)
            .css("height", modalHeight);

    $("div.registerModal").css("width", modalWidth)
            .css("height", modalHeight)
            .css("background-color", "White");

    this.modalWindow.dialog(
        {
          close: function (event, ui) {
            $(this).dialog("destroy");
            if (callback) {
              callback.apply();
            }
          }
        });

    this.modalWindow.dialog("option", "width", modalWidth);
    this.modalWindow.dialog("option", "height", modalHeight);
    this.modalWindow.dialog("option", "position", ["center", 200]);
    this.modalWindow.dialog("open");
  },
  openthankYouModal: function (customTextKey, returnUrl) {
    if (customTextKey && this.CUSTOM_TEXT[customTextKey]) {
      this.thankYouModalWindow.find(".customText").html(this.CUSTOM_TEXT[customTextKey]);
    }
    else {
      this.thankYouModalWindow.find(".customText").html(this.CUSTOM_TEXT.ACCOUNT);
    }
    this.setHtml(this.thankYouModalWindow.html());

    //destroying and rebuilding it to adjust to new html
    this.modalWindow.dialog("destroy");
    this.initModal();

    if (returnUrl) {
      // A desired return url was specified
      // Set the return url value in the ReturnUrl hidden-field
      $("input#ReturnUrl").val(returnUrl);
    }
    else {
      // A desired return url wasn't specified
      // Clean ReturnUrl hidden-field
      $("input#ReturnUrl").val("");
    }

    this.modalWindow.dialog("option", "width", 750);
    this.modalWindow.dialog("option", "height", this.loginModalWindow.height());
    this.modalWindow.dialog("option", "position", ["center", 200]);
    this.modalWindow.dialog("open");
  },
  openLoginModal: function (customTextKey, returnUrl) {
    if (customTextKey && this.CUSTOM_TEXT[customTextKey]) {
      this.loginModalWindow.find(".customText").html(this.CUSTOM_TEXT[customTextKey]);
    }
    else {
      this.loginModalWindow.find(".customText").html(this.CUSTOM_TEXT.ACCOUNT);
    }
    this.setHtml(this.loginModalWindow.html());

    //destroying and rebuilding it to adjust to new html
    this.modalWindow.dialog("destroy");
    this.initModal();

    if (returnUrl) {
      // A desired return url was specified
      // Set the return url value in the ReturnUrl hidden-field
      $("input#ReturnUrl").val(returnUrl);
    }
    else {
      // A desired return url wasn't specified
      // Clean ReturnUrl hidden-field
      $("input#ReturnUrl").val("");
    }

    this.modalWindow.dialog("option", "width", 750);
    this.modalWindow.dialog("option", "height", this.loginModalWindow.height());
    this.modalWindow.dialog("option", "position", ["center", 200]);
    this.modalWindow.dialog("open");
  },

  close: function () {
    this.modalWindow.dialog("close");
  }
};

// after load, initialize
$(document).ready(function () {
    modal.init();
});
