function QuestInfo()
{
   this.user_name = "";
   this.book_name = "";
   this.page_number = 0;
   this.page_progress = 0;
   this.page_time = 0;

   this.rebuild = function(jq_node)
   {
      this.parse(jq_node);
      if ("undefined" == typeof(GUEST))   {
         this.build();
      }  else  {
         this.showSettings();
         this.showColor();
      }
   }

   this.parse = function(jq_node)
   {
      this.user_name = jq_node.attr("user_name");
      this.book_name = jq_node.attr("book_name");
      this.book_color = jq_node.attr("book_color");
      this.book_color_ssaver = jq_node.attr("book_color_ssaver");
      this.book_pages_count = jq_node.attr("book_pages_count");
      this.page_number = Number(jq_node.attr("page_number"));
      this.page_progress = Number(jq_node.attr("page_progress"));
      this.page_time = Number(jq_node.attr("page_time"));
      this.coins = Number(jq_node.attr("coins"));
      this.repeat_mode = Number(jq_node.attr("repeat_mode"));

      this.total_score = Number(jq_node.attr("total_score"));
      this.day_score = Number(jq_node.attr("day_score"));
      this.week_score = Number(jq_node.attr("week_score"));

      this.total_place = jq_node.attr("total_place");
      this.day_place = jq_node.attr("day_place");
      this.week_place = jq_node.attr("week_place");

      if ("undefined" == typeof(this.rating_kind)) {
         this.rating_kind = jq_node.attr("rating_kind");
      }
   }

   this.bookColor = function()
   {
      return ("undefined" == typeof(SCREENSAVER)) ? this.book_color : this.book_color_ssaver;
   }

   this.turnSound = function()
   {
      ENABLE_SOUND = !ENABLE_SOUND;
      this.showSettings();
      $("#sound-setting").blur();
      $.get(HOME + "/serv/store_option.php?" + Math.random(), { sound: (ENABLE_SOUND ? 1 : 0) });
   }

   this.changeRatingKind = function()
   {
      switch(this.rating_kind)   {
         case "day":
         default:
            this.rating_kind = "week";
            break;
         case "week":
            this.rating_kind = "total";
            break;
         case "total":
            this.rating_kind = "day";
            break;
      }
      this.showRating();
   }

   this.showRating = function()
   {
      var score, place, text;
      switch(this.rating_kind)   {
         case "day":
         default:
            score = this.day_score;
            place = this.day_place;
            text = "today";
            this.rating_kind = "day";
            break;
         case "week":
            score = this.week_score;
            place = this.week_place;
            text = "week";
            break;
         case "total":
            score = this.total_score;
            place = this.total_place;
            text = "total";
            break;
      }

      $("#score b").text(score);
      $("#score a:eq(0)").text(place + " place");
      $("#score a:eq(0)").attr("href", HOME + "/rating/" + this.rating_kind + "/my");
      $("#score a:eq(1)").text(text);
   }

   this.showSettings = function()
   {
      if (ENABLE_SOUND) {
         if ("undefined" == typeof(SCREENSAVER))   {
            $("#sound-setting").text("Sound: on");
         }  else  {
            $("#sound-setting img").attr("src", "images/sound-on.gif");
         }
         $("#sound-setting").addClass("on");
      }  else  {
         if ("undefined" == typeof(SCREENSAVER))   {
            $("#sound-setting").text("Sound: off");
         }  else  {
            $("#sound-setting img").attr("src", "images/sound-off.gif");
         }
         $("#sound-setting").removeClass("on");
      }
   }

   this.showColor = function()
   {
      if ("undefined" != typeof(SCREENSAVER))   {
         $(".spec-color").css("color", "#" + this.bookColor());
         $(".spec-color").css("border-color", "#" + this.bookColor());
      }
   }

   this.buildPhoto = function(jq_node)
   {
      var file = jq_node.attr("file");
      file = HOME + "/ssaver/photos/" + file;
      var name = jq_node.attr("name");
      var img = new Image();
      img.src = file;
      $("#city img").attr("src", file);
      $("#city h1").text(name);
   }

   this.build = function(jq_node)
   {
      //$("#game-info-user").text(this.user_name);
      page_time = this.page_time;
      this.showRating();
      this.showSettings();
      $("#score").add("#game-info-settings").removeClass("hidden");

      $("#game-info-progress h3").text("page " + this.page_number);
      
      $("#game-info-progress #percent-progress").text(this.page_progress + "%");
      var max_width = $("#game-info-progress #progress-bar").width() - 4;
      $("#game-info-progress #progress-bar img").css("width", max_width*this.page_progress/100 + "px");
      $("#game-info-progress #progress-bar img").css("background-color", "#" + this.bookColor());
      $("#game-info-progress #coins").text(this.coins);

      $("#game-info-book .name").text(this.book_name.toUpperCase());
      $("#game-info-book-img").attr("src", HOME + "/images/books/"+ this.book_name.toLowerCase() + "-active.png");
      $("#game-info-book div").text("page: " + this.page_number + "/" + this.book_pages_count);
      
      //$("#game-info").removeClass("hidden");
      if (this.repeat_mode)   {
         $("#repeat-mode").removeClass("none");
      }  else  {
         $("#repeat-mode").addClass("none");
      }

      this.showColor();
   }
}