// JavaScript Document

/*

// blogEntries は外部ファイルから取得。

// div 等構造

                   main
+-----------------------------------------+
                container
+-----------------------------------------+
              container-inner
+-----------------------------------------+
              container-inbox
      +-----------------------------+
          mL               mR
+--------------+--------------------------+
           cL       cC         cR
      +--------+----------+---------+

+-----+--------+----------+---------+-----+
|     |logo    |gMenu-box |sMenu-box|     |
+     +--------+----------+---------+     +
|     |utility |menu      |contents |     |
+     +--------+----------+---------+     +
|     |        |common-box|         |     |
+-----+--------+----------+---------+-----+

body
  main
    grandBanner
      container-opening
        container-opening-inner
    container
      container-inner
        container-inbox
          mL
            cL
              logo
              utility
          mR
            cC
              gMenu-box
              menu
              common-box
            cR
              sMenu-box
              contents
              printMapF
*/

$(function(){

      ////////////////////////////////////////////
      // デバッグモード
      ////////////////////////////////////////////
      var debug             = false;
//      if(location.search.match("debug")){
//          debug = true;
//          mydebuglog("debug mode on.");
//      }

      $('.social_bnr').hide();
      ////////////////////////////////////////////
      // カレンダー内で使っているユーティリティ関数
      ////////////////////////////////////////////
      function array_key_exists ( key, search ) {
          
          // Checks if the given key or index exists in the array  
          // 
          // version: 1004.1212
          // discuss at: http://phpjs.org/functions/array_key_exists
          // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
          // +   improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
          // *     example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
          // *     returns 1: true
          // input sanitation
          if (!search || (search.constructor !== Array && search.constructor !== Object)){
              
              return false;
          }
          
          return key in search;
      }

      ////////////////////////////////////////////
      // Date オブジェクト拡張
      ////////////////////////////////////////////
      // http://la.ma.la/blog/diary_200610232213.htm
      // http://blog.livedoor.jp/dankogai/archives/50668882.html
      var set_month = Date.prototype.setMonth;
      Date.prototype.setMonth = function(num){
          if(num <= -1){
              var n = Math.ceil(-num);
              var back_year = Math.ceil(n/12);
              var month = (n % 12) ? 12 - n % 12 : 0 ;
              this.setFullYear(this.getFullYear() - back_year);
              return set_month.call(this, month);
          } else {
              return set_month.apply(this, arguments);
          }
      };

      Date.prototype.getLastDayOfTheMonth = function() {
          var d = new Date(this.getYear(), this.getMonth(), this.getDate());
          d.setMonth(d.getMonth() + 1);
          d.setDate(1);
          d.setTime(d.getTime() - 1);
          return d.getDate();
      };

      Date.prototype.getMonthMM = function(){
          return ("0" + (this.getMonth() + 1)).slice(-2); // 0 = 01, 1 = 02, 2 = 03 ... 11 = 12
      };
      Date.prototype.setMonthMM = function(mmh){
          this.setMonth(parseInt(mmh, 10) - 1);
      };
      Date.prototype.getDateDD = function(){
          return ("0" + this.getDate() ).slice(-2);
      };
      Date.prototype.setDateDD = function(ddh){
          this.setDate(parseInt(ddh, 10));
      };
      ////////////////////////////////////////////
      // Date オブジェクト拡張終わり
      ////////////////////////////////////////////

      ////////////////////////////////////////////
      // カレンダークラス
      ////////////////////////////////////////////
      var calendarClass = function(){


          this.rebuildToday = function (){
              var today = new Date();

              // ひとつめ
              xxF.setDate     (1);
              xxF.setFullYear (today.getFullYear());
              xxF.setMonth    (today.getMonth());
              // ふたつめ
              xxS.setDate     (1);
              xxS.setFullYear (today.getFullYear());
              xxS.setMonth    (today.getMonth());
              xxS.setMonth    (xxS.getMonth() + 1);

              loadCalendar(buildCalendar(xxF) + buildCalendar(xxS));

          };

          // prev/next ボタン用テンプレート
          var htmlTmplButtons = '<div id="calBtn" style="height: 33px;">'
              + '<div id="calPrev">'
              + '  <a id="btnCalBackA"  href="#"><img id="btnCalBack"  src="/_common/img/cal/next_prev/Prev.png" width="37" height="12" alt="prev"  style="float: left; margin: 10px 0 0 9px;" /></a>'
              + '</div>'
              + '<div id="calToday">'
              + '  <a id="btnCalTodayA" href="#"><img id="btnCalToday" src="/_common/img/cal/btn_today.png"      width="37" height="12" alt="today" style="float: left; margin: 10px 0 0 18px;" /></a>'
              + '</div>'
              + '<div id="calNext">'
              + '  <a id="btnCalNextA"  href="#"><img id="btnCalNext"  src="/_common/img/cal/next_prev/Next.png" width="37" height="12" alt="next"  style="float: left; margin: 10px 9px 0 0;" /></a>'
              + '</div>'
              + '</div>';

          // カレンダーデータ構造を作成
          // mm は0-11
          // 上述の Date.getLastDayOfTheMonth() に依存
          var calendarStructure = function (yyyy, mm){
              var d = new Date(yyyy, mm, 1);
              var lastDayOfThisMonth = d.getLastDayOfTheMonth();
              
              var monthData = new Array();
              var weekData  = new Array();

              for(var i = 0; i < d.getDay(); i++){
                  weekData.push("");
              }
              //for (var i = 1; i <= d.getLastDayOfTheMonth(); i++ ){
              for (var i = 1; i <= lastDayOfThisMonth; i++ ){
                  d.setDate(i);
                  weekData.push(i);
                  if(d.getDay() == 6){
                      monthData.push(weekData);
                      weekData = new Array();
                  }
              }
              for(var i = 0; i < (6 - d.getDay()); i++){
                  weekData.push("");
              }

              monthData.push(weekData);
              return monthData;
          };
          
          // 与えられたDate オブジェクトに基づいてdiv に囲われたtable タグを返す
          var buildCalendar = function(dateObj){
              var today    = new Date();
              var todayYmd = today.getFullYear() + "/" + today.getMonthMM() + "/" + today.getDateDD(); // 今日の日付を "2010/01/01" 形式で。
              var yyyy     = dateObj.getFullYear();
              var mm       = dateObj.getMonth();
              var mmh      = dateObj.getMonthMM();

              // 当月のカレンダーのヘッダ
              var appendStr  = '<a href="' + '/calendar/' + yyyy + "/" + mmh + '" class="calMonth"><img src="/_common/img/cal/calendar/month/' + mmh + '.png"></a>';
              // table 部分のhtml の生成・追加
              appendStr += '<table>'
                  + '  <tr>'
                  + '    <th abbr="Sunday" class="sunday"><img src="/_common/img/cal/calendar/week/1.png" alt="sunday"></th>'
                  + '    <th abbr="Monday"><img src="/_common/img/cal/calendar/week/2.png" alt="Monday"></th>'
                  + '    <th abbr="Tuesday"><img src="/_common/img/cal/calendar/week/3.png" alt="Tuesday"></th>'
                  + '    <th abbr="Wednesday"><img src="/_common/img/cal/calendar/week/4.png" alt="Wednesday"></th>'
                  + '    <th abbr="Thursday"><img src="/_common/img/cal/calendar/week/5.png" alt="Thursday"></th>'
                  + '    <th abbr="Friday"><img src="/_common/img/cal/calendar/week/6.png" alt="Friday"></th>'
                  + '    <th abbr="Saturday" class="saturday"><img src="/_common/img/cal/calendar/week/7.png" alt="Saturday"></th>'
                  + '  </tr>';

              // 当月のカレンダーデータ構造を作成
              // 7列 x ?行 のデータ構造、日曜があたま
              var monthData = calendarStructure(yyyy, mm);

              // tr タグからの本体
              for (var i = 0; i < monthData.length; i++ ) {
                  appendStr += "<tr>";
                  var tmpLine = monthData[i];
                  for(var j = 0; j < tmpLine.length; j++){
                      var currentDay = tmpLine[j];
                      var currentDayH = ("0" + currentDay).slice(-2); // currentDay Human readable(0 でパディング)
                      if(currentDay == ""){
                          appendStr += '<td><div class="dayImgBox">&nbsp;</div></td>'; // 月初と月末
                      } else {
                          var img_type = ""; // _no.png, _now.png などを切り替えるため
                          // calendarEntries はMT で吐いたデータファイルで定義しているので注意
                          if( array_key_exists(yyyy, calendarEntries) &&
                              array_key_exists(mmh,  calendarEntries[yyyy]) &&
                              array_key_exists(currentDayH, calendarEntries[yyyy][mmh])
                            ){
                                // 日別のurl は #/calendar/2010/05/17 形式
                                var url = "/calendar/" + yyyy + "/" + mmh + "/" + currentDayH;
                                if(todayYmd == yyyy + "/" + mmh + "/" + currentDayH){
                                    img_type = "_now";
                                }
                                appendStr += '<td><div class="dayImgBox"><a href="' + url + '"><img src="/_common/img/cal/calendar/day/' + ("0" + currentDay).slice(-2) + img_type + '.png"></a></div></td>';
                            } else { 
                                if(todayYmd == yyyy + "/" + mmh + "/" + currentDayH){
                                    img_type = "_now";
                                } else {
                                    img_type = "_no"; // リンク無しなので。
                                }
                                // リンク無し、薄い画像
                                appendStr += '<td><div class="dayImgBox"><img src="/_common/img/cal/calendar/day/' + ("0" + currentDay).slice(-2) + img_type + '.png"></div></td>';
                            }
                      }
                  }
                  appendStr += "</tr>";
              }
              // table タグを閉じて終了
              appendStr += "</table>";

              appendStr = "<div style=\"height: 195px;\">" + appendStr + "</div>";

              return appendStr;
          };

          this.getDateObjF = function(){
              return xxF;
          };
          this.getDateObjS = function(){
              return xxS;
          };

          this.prevMonth = function(){
              xxF.setMonth(xxF.getMonth() - 1);
              xxS.setMonth(xxS.getMonth() - 1);
              loadCalendar(buildCalendar(xxF) + buildCalendar(xxS));
              return false;
          };
          
          this.nextMonth = function(){
              xxF.setMonth(xxF.getMonth() + 1);
              xxS.setMonth(xxS.getMonth() + 1);

              loadCalendar(buildCalendar(xxF) + buildCalendar(xxS));
              return false;
          };

          function loadCalendar(setString){

              calendarInner.children("div.newCalendarBox").stop();
              calendarInner.children("div.newCalendarBox:gt(0)").remove();
              
              var newBox = $('<div class="newCalendarBox" style="position: absolute; left:    -154px; width: 154px; "></div>');
              
              newBox.html(setString);
              
              calendarInner.children("div.newCalendarBox").animate({left: "180px"}, 1000, "easeOutExpo", function(){
                                                                       calendarInner.children("div.newCalendarBox:gt(0)").remove(); // よくないけど、ひとまず。
                                                                   });
              calendarInner.prepend(newBox);
              newBox.animate({left: "7px"}, 1000, easings);
          };

          //////////////////////////////////
          // イニシャライズ
          //////////////////////////////////
          var xxF = new Date(); // 当月分
          var xxS = new Date(); // 翌月分
          xxS.setDate(1);
          xxS.setMonth(xxS.getMonth() + 1);

          var calendar = $("#calendar");
          calendar.html('<div id="calendarInner" class="widget-calendar widget"></div>');
          var calendarInner = $("#calendarInner");
          calendarInner.height(398); // 暫定的に。 // 205 + 205 , prev / next ボタンはheight : 37

          // prev/next ボタンをDOM に追加
          calendar.append(htmlTmplButtons);

          // 現在の日付でカレンダーを構築
          loadCalendar(buildCalendar(xxF) + buildCalendar(xxS));
          //////////////////////////////////
          // イニシャライズ 終わり
          //////////////////////////////////
      };
      ////////////////////////////////////////////
      // カレンダークラス 終わり
      ////////////////////////////////////////////

      var calendarObj = new calendarClass();
      $("#calendar").hide();
      //      $("#calendarInner").hide(); // IE 8 でカレンダーが表示されちゃうので一旦無理矢理直す
      // と思ったけどutility の高さが狂う？と思ったけど#calendarを消す

      // 当月と来月のカレンダーメニュー用html を取得するユーティリティ関数
      function twoMonthCalMenu(targetMonth){
          var dateFrom = new Date(targetMonth.getTime());    //
          dateFrom.setDate(1);                               // 当月一日から
          var dateTill = new Date(dateFrom.getTime());       // 複製
          dateTill.setMonth(dateTill.getMonth() + 1);        // 翌月の
          dateTill.setDate(dateTill.getLastDayOfTheMonth()); // その月の最後の日まで。
          return buildMenu("", dateFrom, dateTill);
      }

      // カレンダーのBACK/NEXT ボタン
      $("#btnCalBackA").click(function(){
                                  calendarObj.prevMonth(); // 前月にセット
                                  var menu = twoMonthCalMenu(calendarObj.getDateObjF());
                                  mainPageObj.menuInitAndAnimation(menu);
                                  return false;
                              }
                             );
      $("#btnCalNextA").click(function(){
                                  calendarObj.nextMonth(); // 翌月にセット
                                  var menu = twoMonthCalMenu(calendarObj.getDateObjF());
                                  mainPageObj.menuInitAndAnimation(menu);
                                  return false;
                              }
                             );
      $("#btnCalTodayA").click(function(){
                                   calendarObj.rebuildToday(); // 今日に戻す
                                   var menu = twoMonthCalMenu(calendarObj.getDateObjF());
                                   mainPageObj.menuInitAndAnimation(menu);
                                   return false;
                               }
                              );
      
      function mydebuglog(str){
          if (debug == true && (! $.browser.msie) && window.console != undefined){
              console.log(str);
          }
      }
      
      // メインの構造を取得
      var _window           = $(window);
      var _main             = $('#main');
      
      var _container        = $('#container');
      var _containerInner   = $('#container-inner');
      var _containerInBox   = $('#container-inbox');

      var _containerOpening = $('#container-opening'); // オープニングムービー
      var _containerOpeningGrandBanner = $('#grandBanner'); // オープニングムービー格納場所変更

      var _mL               = $('#mL');
      var _mR               = $('#mR');

      var _cL               = $('#cL');
      var _cC               = $('#cC');
      var _cR               = $('#cR');
      
      var _logo             = $('#logo');
      var _utility          = $('#utility');
      var _utilityInner     = $('#utility-inner');

      var _gMenuBox         = $('#gMenu-box');
      var _gMenu            = $('#gMenu');
      var _menu             = $('#menu');

      var _commonBox        = $('#common-box');

      var _sMenu            = $('#sMenu');
      var _rsMenu           = $('#sMenu-box');
      var _contents         = $('#contents');

      var _contentsAsset    = $('div.changebox', _contents);

      // 個別のid ものを取得
      var _cal              = $('#cal');
      var _bannerBox        = $('#banner-box'); // utility の中のcal の次の要素

      var _link             = $('#link');       // 画面一番上部左から3列目ブロックのメニュー部分(sMenu の中の要素)
      var _listBox          = $('#list-box');

      var easings = 'easeOutExpo';

      //オープニング後の左下バナー事前読み込み _iwaki追加
      var _bannerContents = "/sidebanner.html"; // sidebanner 読み込み先//
      $(_bannerBox).load(_bannerContents).hide();

      // メインページ
      var mainPageClass = function(){

          var currentMenuName    = "initialTop"; // dummy name
          var currentSubMenuName = "";
          var needNextOpeningAnimation = false; // オープニングアニメーションをするか否か

          this.preparePage = function(url){
              var windowH = $(window).height();

//$('#fb-data').attr('href','http://womb.co.jp/#!'+url);

              if(url == ""){ // ハッシュ無しのときはトップページと見なす。
                  ///////////////////////////////////////////////
                  // オープニング画面
                  ///////////////////////////////////////////////

                  // すべてのアニメーション、ページロードを停止
                  $.each([_mL, _mR, _cL, _cC, _cR, _logo, _utility, _gMenuBox, _menu, _commonBox, _rsMenu, _contents], function(){ this.clearQueue(); this.stop(); });
                  cancelPageRequests();
                  
                   needNextOpeningAnimation = true;

                  _containerOpeningGrandBanner.show();
                  _main.height($(window).height());
                  _container.hide();


                  _cL.hide();
                  _cC.hide();
                  _cR.hide();

                  // オープニングアニメーション用に高さを設定しておく
                  _mL.height(windowH);
                  _mR.height(windowH);

                  _logo.hide();
                  _utility.hide();
                  _gMenuBox.hide();
                  _menu.hide();
                  _commonBox.hide();
                  _rsMenu.hide();
                  _contents.hide();

              } else if(url.match("^/.*")){ // ハッシュを元にページをロード
                  if(needNextOpeningAnimation){
                      ///////////////////////////////////////////////
                      // オープニングアニメーション
                      ///////////////////////////////////////////////
                      soundManager.play('wombSndEnter');
                      _container.show();

                      var yohakuMargin = 50;
                      var yohaku = (_container.width() - _containerInBox.width()) / 2 + yohakuMargin;

                      _commonBox.hide();


                      // アニメーション（フェーズ1 _mL, _mR を扉と見立てて扉を閉めるアニメ）
                      var animationDelayPhase1 = 1000;
                      _mL.css({"left":   "-" + ( _mL.width() + yohaku ) + "px",         display: "block"});
                      _mR.css({"left":   _containerInBox.width() + (yohaku * 2) + "px", display: "block"});
                      _mL.css({'width': (_container.width() / 2) - 320}).animate({left:0},                                        animationDelayPhase1, 'easeOutExpo');
                      _mR.css({'width': (_container.width() / 2) + 328}).animate({left:( (_container.width() - 890) / 2 ) + 125}, animationDelayPhase1, 'easeOutExpo',function(){ 
                                                                                     _containerOpeningGrandBanner.hide(); // オープニングコンテナの削除 ここ削除しないでhide にして再利用はどうか。
                                                                                     _mR.css({'border-left':'1px solid #ddd'});
                                                                                 });
                      // _mR.css({'border-left':'1px solid #ddd'});
                      // _cC.css({'border-right':'1px solid #ddd', width: "227px"});
                      // _main.css({'background-image':'url(/_common/img/bg.gif)','background-position':'right 1px'}); // 必要か不明

                       // アニメーション（フェーズ2 描画領域を展開）
                      var animationDelayPhase2 = 1000;
                      _cL.show();
                      _cR.show();
//                      _cR.css({border: "solid red 1px"});
                      _cL.css({height: windowH});
                      _cC.css({height: windowH});
                      _cR.css({height: windowH});

                      _cL.css("left", "-" + _cL.width() + "px")                                                        // 位置初期化処理。自分の幅の分だけ外に出ておく
                          .delay(animationDelayPhase1)                                                                 // アニメーションフェーズ1の分、遅延して開始
                          .animate({left: _container.width() / 2 - 320 - 168}, animationDelayPhase2,'easeOutExpo');    // cL 領域を寄せる

                      _cC.css({"width": 0, height: windowH, 'border-right':'1px solid #ddd'})                          // 位置初期化処理。cC はwidth 0 から広げていく。
                          .delay(animationDelayPhase1)                                                                 // アニメーションフェーズ1の分、遅延して開始
                          .animate({width: "227px"},                           animationDelayPhase2, 'easeOutExpo', function(){ 
                                       // アニメーション（フェーズ3 各パーツをスライドイン）
                                       $("#calendar").show();            // in utility block
                                       $('#cL .cal1, #cL .cal2').show(); // in utility block
                                       $(_bannerBox).show();             // in utility block
                                       _gMenu.show();
                                       _sMenu.show();

                                       function openingAnimationPhase3(obj, startLeft){
                                           var animationDelayPhase3 = 1000;
                                           obj.css({display: "block", position: "relative", left: startLeft}).animate({left: "0px"}, animationDelayPhase3, 'easeOutExpo');
                                       }
                                       openingAnimationPhase3(_logo,      "-170px");
                                       openingAnimationPhase3(_utility,   "-170px");
                                       openingAnimationPhase3(_gMenuBox,  "-280px");
                                       openingAnimationPhase3(_menu,      "-280px");
                                       openingAnimationPhase3(_commonBox, "-280px");
                                       openingAnimationPhase3(_rsMenu,    "-581px");
                                       openingAnimationPhase3(_contents,  "-581px");

                                       // オープニングアニメーションの分遅延しないといけないのでここで実施。
                                       loadAll(url);

                                   }); // cC を広げて(結果的に)cR を右側に展開する
                      needNextOpeningAnimation = false;
                  } else {
                          
                      _containerOpeningGrandBanner.hide(); // オープニングコンテナ隠す

                      _container.show();

                      _mL.css({'width': (_container.width() / 2) - 320, left:0});
                      _mR.css({'width': (_container.width() / 2) + 328, left:( (_container.width() - 890) / 2 ) + 125, 'border-left':'1px solid #ddd'});
                      _mL.show();
                      _mR.show();

                      _cL.css({left: (_container.width() / 2) - 320 - 168});
                      _cC.css({'border-right':'1px solid #ddd', width: "227px"});
		      _main.css({'background-image':'url(/_common/img/bg.gif)','background-position':'right 1px'}); // 必要か不明
                      _cL.show();
                      _cC.show();

                      showPageElement();
                      loadAll(url);
                  }

              }
    
          };

          var xhrQueue = new Array(); // 後から来たリクエストが前のリクエストをキャンセルできるようにキューしておくためのメンバ。
          function cancelPageRequests(){
              var tmpXhr;
              while((tmpXhr = xhrQueue.shift()) != undefined){
                  tmpXhr.abort();
              }
          }

          function printFlyer(withmap){
/*
 * この処理を無効化する際には
 * return 0;
 * 等で処理します。
 */

              if(withmap){
                  $("body").append('<link rel="stylesheet" href="/_common/css/print-flyer.css" type="text/css" media="print" />');
              } else {
                  $("body").append('<link rel="stylesheet" href="/_common/css/print-non-flyer.css" type="text/css" media="print" />');
//                  $("head").remove('<link rel="stylesheet" href="/_common/css/print.css" type="text/css" media="print" /> ');
              }
          }

          // url を引数にとって適切なメニューとコンテンツをロードするよう振り分ける。
          // url は/ で始まるパスにするよう各イベントハンドラで設定。
          var loadAllMenuName = "";
          function loadAll(url){
	      url.match("(http://www.womb.co.jp|)/([^/]+)/");
              if(loadAllMenuName == ""){ // 初回ロード時だったらurl からメニューを推測する
                  loadAllMenuName = RegExp.$2; // artists / members / rentalspace / womb / lounge / live / adventure / cruise / voice / company
                  printFlyer(0);
              }
              // トップページ
	      if(url.match("^/schedule/(index.html|)$") || url.match("^/womb/map.html$")){ // index.html はあってもなくても良い。map.html 追加
                  loadAllMenuName = "top";
                  calendarObj.rebuildToday();
                  printFlyer(0);
              // 各カテゴリスケジュール
	      } else if(url.match("^/([^/]+)/information/(index.html|)$")){ // 各カテゴリスケジュールリンクがクリックされたと見なす
                  loadAllMenuName = RegExp.$1; // womb / lounge / live / adventure / cruise のいずれかになる
                  printFlyer(0);
              // 各カテゴリスケジュール
	      } else if(url.match("^/(womb|lounge|live)/(information-menu.html|access.html|information-equipmentlist.html)")){
														// WOMB/LOUNGE/LIVEの特定ページのみ
																		printFlyer(0);
	      } else if(url.match("^/(womb|lounge|live|adventure|cruise)/.*$")){ // 各カテゴリスケジュールの個別ページ表示中。この場合の"artist" などからの戻りを処理するために追記。
                  var tmpLoadAllMenuName = RegExp.$1; // womb / lounge / live / adventure / cruise のいずれかになる
                  if(tmpLoadAllMenuName != loadAllMenuName && ( ! loadAllMenuName.match("^/calendar/") )){ // カレンダーを除いたurl からのreturn、移動の際に。主にartists からの戻りなどを念頭に置く。
                      loadAllMenuName = tmpLoadAllMenuName; // この場合のみ、メニューをtmpLoadAllMenuName で置き換える。（上書きする）
                  }
                  printFlyer(1);
              // members / rentalspace / voice / company
	      } else if(url.match("^/(members|rentalspace|voice|company)/")){
                  loadAllMenuName = RegExp.$1; // members / rentalspace / voice / company のいずれか
                  printFlyer(0);
              // artists
	      } else if(url.match("^/(artists)/(womb-management.html|all-artists.php|[a-z]/)$")){
                  loadAllMenuName = RegExp.$1; // artists
                  printFlyer(0);
              // artists の個別ページ（上記にマッチしないartists のページは個別ページと考えられる）
	      } else if(url.match("^/(artists)/.*")){
                  // loadAllMenuName は空で渡し、close_count だけカウンタをインクリメントしておく。
                  close_count ++;
                  //loadAllMenuName = RegExp.$1; // artists
                  printFlyer(0); 
             // カレンダークリック（月）
	      } else if(url.match("^/calendar/([0-9]{4})/([0-9]{2})$")){ // 当月のカレンダーメニュー表示
                  loadAllMenuName = url; // for Menu
	          url = "http://www.womb.co.jp/schedule/"; // ひとまずheadline を読み込む、月の最初の記事が理想か？
                  printFlyer(0); 
              // カレンダークリック（日）
	      } else if(url.match("^/calendar/([0-9]{4})/([0-9]{2})/([0-9]{2})$")){ // 当日のカレンダーメニューのみ。
	          var yyyy = RegExp.$1;
	          var  mmh = RegExp.$2;
	          var  ddh = RegExp.$3;

                  loadAllMenuName = url; // for Menu
	          url = "http://www.womb.co.jp/schedule/"; // ひとまずheadline を読み込む
                  // calendarEntries から当日のデータを一件取得してurl にセット
                  if( array_key_exists(yyyy, calendarEntries) &&
                      array_key_exists(mmh,  calendarEntries[yyyy]) &&
                      array_key_exists(ddh, calendarEntries[yyyy][mmh])
                    ){
                        for (var k in calendarEntries[yyyy][mmh][ddh]) {
                            url = calendarEntries[yyyy][mmh][ddh][k]["Permalink"];
                            break;
                        }
                    }
                  printFlyer(0); 
              }

              newnewLoadMenu(loadAllMenuName, url); // voice 等のsubmenu ロードもこのなかで。
	      _newLoadContents(url);
              toggleVoice(url);

              return false;
          }

          function showPageElement(){
                  _logo.css(     {left: "0px"});
                  _utility.css(  {left: "0px"}); //これしちゃうとtoggle voice に
                  _gMenuBox.css( {left: "0px"});
                  _menu.css(     {left: "0px"});
                  _commonBox.css({left: "0px"});
                  _rsMenu.css(   {left: "0px"});
                  _contents.css( {left: "0px"});

                  _logo.show();
                  _utility.show();
                  _gMenu.show();
                  _gMenuBox.show();
                  _menu.show();
                  _commonBox.show();
                  _rsMenu.show();
                  _sMenu.show();
                  _contents.show();

                  $("#calendar").show();
                  $('#cL .cal1, #cL .cal2').show();
                  $(_bannerBox).show();
          }
          this.init = function() {
              // オープニングの読み込み
              //$('#grandBanner').load('/grandTopBanner-test-kt2.html #container-opening');
			  if(location.href.match("pregrandbanner.html") ){ 
			  $('#grandBanner').load('/grandTopBanner-test.html #container-opening');
			  mydebuglog("0"+location.href);
			  }else{
			  $('#grandBanner').load('/grandTopBanner.html #container-opening');
			  mydebuglog("1"+location.href);
			  }
			  //_openingBanner;

//              if(location.hash.match("^#/.*") ){ 
              if(location.hash.match("^#\!/.*") ){ 
                  soundManager.play('wombSndEnter');
//                  this.preparePage(location.hash.slice(1));
                  this.preparePage(location.hash.slice(2));
              } else if (location.hash == ""){
                  this.preparePage("");
              }

          };


          //////////////////////////////////////////////////////////////////// 
          // gMenu を表示する/しない
          //////////////////////////////////////////////////////////////////// 
          var isGMenuBoxHidden = 0;
          function voiceHyoujiDeBannerToMenuKesu(){
              if(isGMenuBoxHidden == 0){
                  _utilityInner.stop().css({position: "relative", left: "0px"}).animate({left: "170px"}, 600, "easeOutExpo");
	          _gMenu.stop().css({left: "0px"}).animate(  {left: "227px"}, 600, "easeOutExpo");
	          isGMenuBoxHidden = 1; 
                  
	          var _rssVoice = "'SubMenu', 'RSS', 'RSS-VOICE'"; //100504 追加
	          $('#rssBox').html('<span class="rssWomb"><a href="http://feeds.feedburner.com/WombVoiceRss" target="_blank" onClick="pageTracker._trackEvent('+_rssVoice+');"><img src="/_common/img/sMenu/rss_voice.png" alt="" width="59" height="18" /></a></span>');
	          $('#rssBox').live('mouseover',function(){$('#rssBox img').attr("src","/_common/img/sMenu/rss_voice_on.png");});
	          $('#rssBox').live('mouseout',function(){$('#rssBox img').attr("src","/_common/img/sMenu/rss_voice.png");});
              }
          }
          function voiceHyoujiDeBannerToMenuDasu(){
              if(isGMenuBoxHidden == 1){
                  _utilityInner.stop().css({position: "relative", "left": "-170px"}).animate({left: "0px"}, 600, "easeOutExpo");
                  _gMenu.stop().css({"left": "-227px"}).animate({left: "0px"}, 600, "easeOutExpo");
                  isGMenuBoxHidden = 0;
		  
	          var _rssSchedule = "'SubMenu', 'RSS', 'RSS-SCHEDULE'"; //100504 追加
	          $('#rssBox').html('<span class="rssWomb"><a href="http://feeds.feedburner.com/WombScheduleRss" target="_blank" onClick="pageTracker._trackEvent('+_rssSchedule+');"><img src="/_common/img/sMenu/rss_schedule.png" alt="" width="59" height="18" /></a></span>');
	          $('#rssBox').live('mouseover',function(){$('#rssBox img').attr("src","/_common/img/sMenu/rss_schedule_on.png");});
	          $('#rssBox').live('mouseout',function(){$('#rssBox img').attr("src","/_common/img/sMenu/rss_schedule.png");});
              }
          }
          function toggleVoice(url){
              if(url.match("^/voice/.*")){
                  voiceHyoujiDeBannerToMenuKesu(); // メニューが表示されてたら消す
              } else {
                  voiceHyoujiDeBannerToMenuDasu(); // メニューが消えてたら出す
              }
          }

          function setMenuName(str){
              currentMenuName = str;
          }

          //「本日」と「前日」以前のスケジュールは表示しない
          function getMenuByThisMonthCalendarAfterToday2(category){
              var dateFrom = new Date();
              dateFrom.setDate(dateFrom.getDate() - 1 );         // 一日前から。
              var dateTill = new Date();                         // 今日を起点に
              dateTill.setDate(1);                               // 一旦、1日にする。（31 などだった場合に余計に月が進むのを避けるため）
              dateTill.setMonth(dateTill.getMonth() + 1);        // 翌月の
              dateTill.setDate(dateTill.getLastDayOfTheMonth()); // その月の最後の日まで。

              return buildMenu2(category, dateFrom, dateTill);
          }

          // string category  : ブログ名
          // Date   inDateFrom: 開始日時
          // Date   inDateTill: 終了日時
          // category ブログのdateFrom からdateTill までのエントリ情報をリストタグにいれて月次ヘッダをつけてString として返す
          function buildMenu2(category, inDateFrom, inDateTill){

              var ret        = ""; // 返り値
              var currentMmh = ""; // 月次ヘッダを表示する際のフック用

              var dateFrom = new Date(inDateFrom); // 外部オブジェクトに影響を及ぼさないよう複製する。
              var dateTill = new Date();
              if(inDateTill == undefined) {
                  dateTill = new Date(dateFrom.getTime());  // dateTill が省略されたときはdateFrom を使う。
              } else {
                  dateTill = new Date(inDateTill);          // 外部オブジェクトに影響を及ぼさないよう複製する。
              }

              while(dateFrom <= dateTill) {
                  var yyyy = dateFrom.getFullYear();
                  var mmh  = dateFrom.getMonthMM();
                  var dd   = dateFrom.getDate();
                  var ddh  = dateFrom.getDateDD();


                  if( array_key_exists(yyyy, calendarEntries) &&
                      array_key_exists(mmh,  calendarEntries[yyyy]) &&
                      array_key_exists(ddh, calendarEntries[yyyy][mmh]) )
                  {
                      var daysEntries = calendarEntries[yyyy][mmh][ddh];
                      for (var j in daysEntries) { // Entry 表示ループ
                          if(category != "" && category != daysEntries[j]["BlogName"]){
                              continue; // カテゴリをフィルタ
                          }

                          // 月のヘッダ画像
                          if(currentMmh != mmh){
                              ret += '<li><span class="menuMonth"><img src="/_common/img/list/ListCalendarMonth/ListCalendarMonth' + mmh + '.png" /></span></li>';
                              currentMmh = mmh;
                          }

                          var url      = daysEntries[j]["Permalink"];
                          var title    = daysEntries[j]["EntryTitle"];
                          var blogname = "b-name" + daysEntries[j]["BlogName"];
                          var printText = title;
                          var mojisuu = 20;
                          if(printText.length > mojisuu){
                              printText = printText.substr(0, mojisuu) + "...";
                          }
                          ret += '<li class="listNum' + ddh + '">' 
                              + '<a class="btnObj clearfix" href="' + url + '">'
                              + '<span class="date ' + blogname + '"><img src="/_common/img/cal/list/' + ddh +'.png" width="24" height="22" alt="" /></span>'
                              + '<span class="title">' + printText + '</span>'
                              + '</a>'
                              + '</li>';
                      }
                  }

                  dateFrom.setDate(dateFrom.getDate() + 1 ); // 日付インクリメント
              }
              return ret;
          }

          function getSlideSubMenu(entries){
              // voice channel 等、空文字列でindex ページのみを表示させる
              if(entries == ""){
                  return "";
              }
              var ret = $("<div />");
              // エントリ用
              var entryTmpl = '<li class="listNum1"><a class="btnObj clearfix" href="#"><span class="title title-no"></span></a></li>';
              // setMenu を前提にしているときとデータ形式が違うので注意
              for (var i = 0; i < entries.length; i++){
                  var title      = entries[i].EntryTitle;
                  var url        = entries[i].Permalink;
                  // リンクごとのラベル
                  var entryLabel = $(entryTmpl);
                  $("a", entryLabel).attr("href", url);
                  $("span", entryLabel).html(title);
                  ret.append(entryLabel);
              }
              return ret.html();
          }

          var subMenuTopPosition = 0;
          var subcat = ""; // voice で保持するサブカテゴリ用
          function newnewLoadMenu(menuName, url){
              if(currentMenuName != menuName){
                  currentMenuName = menuName;
                  if(menuName == "top"){
                      setMenuName("top");
	              var tmpMenu = getMenuByThisMonthCalendarAfterToday2("");
                      menuInitAndAnimation(tmpMenu);
                  } else if(menuName == "womb" || menuName == "lounge" || menuName == "live" || menuName == "adventure" || menuName == "cruise" ) {
                      setMenuName(menuName);
                      var tmpListMenu = _listContentsMenu2(menuName);
	              var tmpMenu = getMenuByThisMonthCalendarAfterToday2(menuName);
                      menuInitAndAnimation(tmpListMenu.html() + tmpMenu);
                  } else if(menuName == "artists" || menuName == "members" || menuName == "rentalspace" ) {
              close_count ++;
                      var tmpListMenu = _listContentsMenu2(menuName);
                      var submenuaaa = getSubMenu(menuName);
                      menuInitAndAnimation(tmpListMenu.html() + submenuaaa.html());
                  } else if(menuName == "voice" || menuName == "company" ) {
                      var tmpListMenu = _listContentsMenu2(menuName);
                      menuInitAndAnimation(tmpListMenu.html());
	          } else if(menuName.match("^/calendar/([0-9]{4})/([0-9]{2})$")){ // 当月のカレンダーメニュー表示
	              var yyyy = RegExp.$1;
	              var  mmh = RegExp.$2;
                      var dateFrom = new Date();
                      dateFrom.setDate(1);                               // 当月一日、日付を先に設定すること。
                      dateFrom.setFullYear(yyyy);
                      dateFrom.setMonthMM (mmh);
                      var dateTill = new Date(dateFrom.getTime());       // dateFrom を複製
                      dateTill.setDate(dateTill.getLastDayOfTheMonth()); // その月の最後の日まで。
                      
	              var tmpMenu = buildMenu("", dateFrom, dateTill);
                      menuInitAndAnimation(tmpMenu);
	          } else if(menuName.match("^/calendar/([0-9]{4})/([0-9]{2})/([0-9]{2})$")){ // 当日のカレンダーメニューのみ。
	              var yyyy = RegExp.$1;
	              var  mmh = RegExp.$2;
	              var  ddh = RegExp.$3;
                      var theDay = new Date();
                      theDay.setDateDD  (ddh); // 日付を先。
                      theDay.setFullYear(yyyy);
                      theDay.setMonthMM (mmh);

	              var tmpMenu = buildMenu("", theDay);
                      menuInitAndAnimation(tmpMenu);
                  }
              }
              hantenMenu(url, $("ul.newMenuBox")); // currentMenuName == menuName でもhantenMenu は行う。

              // サブメニュー
              var subMenuEntries = "";
              var subMenuName = "";
	      if(url.match("^/voice/voice-top.html$")){ // トップ
              close_count ++;
                  subMenuEntries = "";
                  subMenuName    = "__VOICETOP__";
	      } else if(url.match("^/voice/([^/]+)/(index.html|)$")){ // /voice/news/ など
                  subcat  = RegExp.$1;
                  subMenuEntries = blogEntries["voice"][subcat];
                  subMenuName    = "voice-" + subcat;
	      } else if(url.match("^/voice/[0-9]{4}/[0-9]{2}/[0-9]{2}/[^/]+$")){ // voice 内のエントリ表示時
                  subMenuName = "__VOICEENTRY__";
	      } else if(url.match("^/voice/([^/]+)/([^/]+)/(index.html|)$")){ // /voice/news/artists/ など
                  subcat  = RegExp.$1;
                  subMenuEntries = blogEntries["voice"][subcat];
                  subMenuName = "voice-" + subcat;
              } else if(url.match("^/company/overview.html$")){
                  subMenuEntries = blogEntries["company"]["ABOUTUS"];
                  subMenuName = "company-aboutus";
              } else if(url.match("^/company/recruit.html$")){
                  subMenuEntries = blogEntries["company"]["WANTED"];
                  subMenuName = "company-wanted";
              } else if(url.match("^/company/.*$")){
                  subMenuEntries = blogEntries["company"]["ABOUTUS"];
                  subMenuName = "company-aboutus";
              } else {
                  subMenuName = "";
                  subMenuEntries = ""; // 上記で定義していないURL （voice, company 以外のコンテンツ）呼び出しと考えられる
              }
              if(currentSubMenuName != subMenuName && subMenuName != "__VOICEENTRY__"){
                  currentSubMenuName = subMenuName;
                  _newLoadSubMenu(subMenuEntries);
              }

          }

          function _listContentsMenu2(blogName){
              var menus = {
                  "voice":       ["news",       "voice",       "report", "channel"],
                  "artists":     ["allartists", "wombmanagement"],
                  "members":     ["members"],

                  "rentalspace": ["rentalspace"],
                  "lounge":      ["information-menu", "access"],
                  "live":        ["information-equipmentlist", "access"],
                  "adventure":   ["access"],
                  "cruise":      ["access"],

                  "company":     ["aboutus",    "wanted"],
                  "womb":        ["access"]
              };
              var ulTag = $("<ul />");
              for (var k in menus[blogName]){
                  var menu    = menus[blogName][k];
                  var liTag   = $('<li   class="list-btn" />');
                  var spanTag = $('<span class="list-btn" />');
                  var spanClassName = "btn-" + menu;
                  var aTag = $('<a />');
                  var aHref = "/" + blogName + "/" + menu + ".html";
                  var imgSrc = "/_common/img/list/ListContents" + menu.toUpperCase() + ".gif";
                  var imgTag = $('<img class="btn" height="19" width="205" />');

                  // このへんの分岐処理を解除するためにはMT および画像ファイル名での命名則の徹底が必要
                  if(blogName == "voice"){
                      spanClassName = "btn-womb" + menu;
                      aHref = "/" + blogName + "/" + menu + "/index.html";
                      imgSrc = "/_common/img/list/ListContentsWOMB" + menu.toUpperCase() + ".gif";
                  } else if(blogName == "company" && menu == "aboutus"){
                      aHref = "/" + blogName + "/overview.html";
                  } else if(blogName == "company" && menu == "wanted"){
                      aHref = "/" + blogName + "/recruit.html";
                  } else if(blogName == "artists" && menu == "allartists"){
                      aHref = "/" + blogName + "/all-artists.php";
                  } else if(blogName == "artists" && menu == "wombmanagement"){
                      aHref = "/" + blogName + "/womb-management.html";
                  } else if(blogName == "rentalspace" ){
                      aHref = "/" + blogName + "/plan.html";
                  }

                  spanTag.addClass(spanClassName);
                  aTag.attr("href", aHref);
                  imgTag.attr("src", imgSrc);

                  aTag.html(imgTag);
                  spanTag.html(aTag);
                  liTag.html(spanTag);
                  ulTag.append(liTag);
              }
              return ulTag;
          }

          // ストリングをもらってセットする。
          function menuInitAndAnimation(setObj){
              _listBox.children("ul.newMenuBox:gt(0)").stop().remove();
              _listBox.children("ul.newMenuBox").stop().css({left: "0px"}).animate({left: "227px"}, 1000, easings, function(){ $(this).remove(); /* 自分自身を削除 */ });
              var newBox = $('<ul style="position: absolute; left: -227px; top: 0px; width: 227px;" class="newMenuBox"></ul>');
              newBox.html(setObj);
              _listBox.prepend(newBox);
              subMenuTopPosition = newBox.height();

              _menu.height(10);
              heightCheckSetMax();
              newBox.animate({left: "0px"}, 1000, easings);
          }
          this.menuInitAndAnimation = menuInitAndAnimation;

          function _newLoadSubMenu(setobj){
              _listBox.children("ul.newSubMenuBox:gt(0)").stop().remove();
              _listBox.children("ul.newSubMenuBox").animate({left: "227px"}, 1000, easings, function(){
                                                                $(this).remove();
                                                            });
              var newBox = $('<ul style="position: absolute; left: -227px; width: 227px; top: ' + subMenuTopPosition + 'px;" class="newSubMenuBox"></ul>');
              newBox.html(getSlideSubMenu(setobj));
              _listBox.prepend(newBox);
              newBox.animate({left: "0px"}, 1000, easings);
          }

		  var close_count = 0;
		  
          // url を引数に取る。
          // div.entry-content があることを前提にしている
          function _newLoadContents(url){
              cancelPageRequests();

              // コンテンツをロードしてコールバック
              var xhr = $.ajax({ url: url, success: function(data){
                                     _contents.children("div.newChangeBox:gt(0)").stop(true, true).remove();
                                     _contents.children("div.newChangeBox").stop(true,true).animate({left: "583px"}, 1000, easings, function(){
                                                                                                        $(this).remove();
                                                                                                    });

                                     var newDiv = $('<div style="position: absolute; left: -583px; top: 0px; width: 583px;" class="newChangeBox"></div>');
                                     //var newDiv = $('<div style="position: relative; left: -583px; top: 0px; width: 583px;" class="newChangeBox"></div>');
                                     newDiv.html($("div.entry-content", data)); // loadするurl にはdiv.entry-content がある
                                     $("title").html($("#permalinkTitle", data)); //タイトル設定用MT テンプレート側対応必要。
                                     
                                     // permalink をinput に。
                                     var pBox = $("p.u-permalink > a", newDiv);
                                     pBox.replaceWith("<input class='permalinkInputBox' type='text' value='" + pBox.text() + "'>");

                                     // 深い階層のときに追加するクローズ用のボタン
                                     // history.back() でもどる。
                                     if(
                                         url.match("^/voice/[0-9]{4}/[0-9]{2}/[0-9]{2}/.*\.html") ||  // voice   のエントリー
                                         ( ! url.match("^/artists/womb-management.html") && url.match("^/artists/.*\.html")) ||  // artists のエントリー
                                         url.match("^/rentalspace/photo/.*\.html")                    // rentalspace のFloor ガイドの写真
                                     ){
                                         var close_btn = $('<span id="close_btn"><img src="/_common/img/contents/btn_back.gif" width="30" height="67" alt="" /></span>');
                                         close_btn.css({'display':'none','height':'67px','position':'absolute','back-ground':'#000','margin':'0px 0px 0px 0px','right':'0','z-index':'1000','cursor':'pointer'});
                                         
										if(close_count==0){
										var urls = url;
										 close_count ++;
											 if(urls.match("^/voice/.*")){
//20110716
//												 close_btn.click(function(){location.href='http://www.womb.co.jp/#/voice/voice-top.html'; return false; });
												 close_btn.click(function(){location.href='http://www.womb.co.jp/#!/voice/voice-top.html'; return false; });
											 }else if(urls.match("^/artists/.*")){
//20110716
//												 close_btn.click(function(){location.href='http://www.womb.co.jp/#/artists/all-artists.php'; return false; });
												 close_btn.click(function(){location.href='http://www.womb.co.jp/#!/artists/all-artists.php'; return false; });
											 }
										 }else{
                                         close_btn.click(function(){ history.back(); return false; });
										 }
										 
										 
										 
										 
                                         close_btn.fadeIn(1000);
                                         newDiv.prepend(close_btn);
                                     }

                                     _contents.prepend(newDiv);
                                     
                                     _tweetFunc(url);  // ロードしたコンテンツのPermalink をチェックしてTwitter 用のリンクを付加。
                                     
                                     heightCheckSetMax();
                                     $("img", newDiv).each(function(){
                                                               $(this).load(function(){
                                                                                heightCheckSetMax(); // 画像ロード完了ごとに高さが変わるかもしれないので。
                                                                            });
                                                           });
                                     newDiv.animate({left: "0px"}, 1000, easings); // コンテンツをスライドして表示

                                 }});
              xhrQueue.push(xhr);
              _goPageTop(); // トップへ。
              return;
          }

      };

      ///////////////////////////////////////////////////////////
      // イベントハンドラの設定
      ///////////////////////////////////////////////////////////
      // 頭がhttp://www.womb.co.jp/ で始まっているurl を/ で始まるurlに書き換える。
      function normalizeUrlForWomb(url){
	  var checkFullPath  = new RegExp("^http://www.womb.co.jp/");
	  if( url.match(checkFullPath)){
              url = url.replace("http://www.womb.co.jp", "");
          }
          return url;
      }

      function clickAction(){
          // ひとまずここでトラック
          wombPageTrack($(this).attr('href'),$(this).attr('id'),$(this).attr('class'));

	  var url = normalizeUrlForWomb($(this).attr('href'));
	  var className = $(this).attr('class');
	  if( className.match("popwin") || url.match("^http(s|)://") || url.match("^mailto:") || url.match("^javascript:") || url.match("\.pdf$")){ 
	  // 外部サイト、mailto、javascript、pdf は普通にリンクを効かせる
              // #/hoge がマッチしてしまっている
			  _targetBlank();
              return true;
          }

          // ページ内遷移のためのハッシュリンクに対処
          // #top, #container など。
          // #! で始まらないものを処理
//20110716
//          if($(this).attr("href").match("^#[^/].*$")){
//          if($(this).attr("href").match("^#\![^/].*$")){
          if($(this).attr("href").match("^#[^\!].*$")){

              // id が振ってないもの対策
              $("#contents a").each(function(){
                                        if($(this).attr("name") != "" && $(this).attr("id") == ""){
                                            $(this).attr("id", $(this).attr("name"));
                                        }
                                    });

              soundManager.play('wombSndMouseDown');
              $('html, body').clearQueue();
	      $('html, body').animate({scrollTop: $($(this).attr("href")).offset().top}, 300);
              return false;
          }

          // / で始まるハッシュは# を削除してセット。
//20110716
//          url = url.replace("\#", "");
//          location.href = location.pathname + "#" + url;
          url = url.replace("\!\#", "");
//alert(url);
          location.href = location.pathname + "#!" + url;
          return false;
      }
      
      // 各リンクでのクリック動作はhref で指定されているリンク先を/ からはじまるアドレスに変換して
      // hash 形式でlocation.href に設定してあとの動作はloadAll()に任せる
      $('a').live('click', clickAction); // すべてのa をいったんclickAction に渡してしまう。

      // ハッシュチェンジでページロード
      $(window).bind("hashchange", function(){
//20110716
//                         mainPageObj.preparePage(location.hash.slice(1));
//alert(location.hash.slice(2));
                         mainPageObj.preparePage(location.hash.slice(2));
                         return false;
                     });
      // ウィンドウのリサイズで描画し直し
      $(window).resize(function(){
//20110716
//                         mainPageObj.preparePage(location.hash.slice(1));
//alert(location.hash.slice(2));
                         mainPageObj.preparePage(location.hash.slice(2));
		     });

      /////////////////////////
      // pageTracker まわりはいったん根こそぎ削除しちゃったので再度追加する必要あり。
      /////////////////////////
      function wombPageTrack(url,id){
	  //pageTracker._trackEvent( "DUMMY", "DUMMY", url);
	  var _url1 = new RegExp("http://www.womb.co.jp");
		if(url.match(_url1)){ //トラッキングのURLを表示する際にhttp://www.womb.co.jpが付くと長くなるので削除
			var url = url.slice(21); 
			mydebuglog("www");
		}else{
			var url = url; 
			mydebuglog("_none");
		}
		var _blogNameScheduleWomb = new RegExp("/womb/");
		var _blogNameScheduleLounge = new RegExp("/lounge/");
		var _blogNameScheduleLive = new RegExp("/live/");
		var _blogNameScheduleAdventure = new RegExp("/adventure/");
		var _blogNameScheduleCruise = new RegExp("/cruise/");
		var _blogNameVoice = new RegExp("/voice/");
		var _blogNameArtists = new RegExp("/artists/");
		var _blogNameRentalspace = new RegExp("/rentalspace/");
		var _blogNameCompany = new RegExp("/company/");
		var _blogNameMembers = new RegExp("/members/");
		var _blogNameCalendar = new RegExp("/calendar/");
		
		if(url.match("body=")){ //shareMailの場合は削除
			mydebuglog("_ptNoneMail"); 
		}else if (url.match(_blogNameScheduleWomb)) { //womb schedule
			var blogName = 'WOMB-MENU';
			if(url.match("access.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','ACCESS');
			}else if(url.match("information-menu.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','INFORMTATION');
			}else if(url.match("information/index.html")){ 
				mydebuglog("information"); //各スケジュールのトップは各スケジュールボタンクリック時に表示されるので削除
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if (url.match(_blogNameScheduleLounge)) { //lounge schedule
			var blogName = 'LOUNGE-MENU';
			if(url.match("access.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','ACCESS');
			}else if(url.match("information-menu.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','INFORMTATION');
			}else if(url.match("information/index.html")){
				mydebuglog("information");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if (url.match(_blogNameScheduleLive)) { //live schedule
			var blogName = 'LIVE-MENU';
			if(url.match("access.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','ACCESS');
			}else if(url.match("information-equipmentlist.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','INFORMTATION');
			}else if(url.match("information/index.html")){
				mydebuglog("information");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if (url.match(_blogNameScheduleAdventure)) { //adventure schedule
			var blogName = 'ADVENTURE-MENU';
			if(url.match("access.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','ACCESS');
			}else if(url.match("information-menu.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','INFORMTATION');
			}else if(url.match("information/index.html")){
				mydebuglog("information");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if (url.match(_blogNameScheduleCruise)) { //cruise schedule
			blogName = 'CRUISE-MENU';
			if(url.match("access.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','ACCESS');
			}else if(url.match("information-menu.html")){
				pageTracker._trackEvent( "+blogName+", 'CLICK','INFORMTATION');
			}else if(url.match("information/index.html")){
				mydebuglog("information");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if (url.match(_blogNameVoice)){ //voice
			var blogName = 'WOMBVOICE-MENU';
			var _teVoice1 = "'WOMBVOICE-MENU', 'CLICK', 'WOMBVOICE'";
			var _teVoice2 = "'WOMBVOICE-MENU', 'CLICK', 'WOMBNEWS'";
			var _teVoice3 = "'WOMBVOICE-MENU', 'CLICK', 'WOMBREPORT'";
			var _teVoice4 = "'WOMBVOICE-MENU', 'CLICK', 'WOMBCHANNEL'";
			if(url.match("/voice/voice/index.html")){
				pageTracker._trackEvent( "+_teVoice1+");
			}else if(url.match("/voice/news/index.html")){
				pageTracker._trackEvent( "+_teVoice2+");
			}else if(url.match("/voice/report/index.html")){
				pageTracker._trackEvent( "+_teVoice3+");
			}else if(url.match("/voice/channel/index.html")){
				pageTracker._trackEvent( "+_teVoice4+");
			}else if(url.match("/voice/voice-top.html")){
				mydebuglog("voice-top");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if(url.match(_blogNameArtists)){ //artists
			var blogName = 'ARTISTS-MENU';
			var _etArtists1 = "'ARTISTS-MENU', 'CLICK', 'WOMBARTISTS'";
			var _etArtists2 = "'ARTISTS-MENU', 'CLICK', 'WOMBMANEGEMENT'";
			if(url.match("/artists/all-artists.php")){
				if(id.match("_artists")){
					mydebuglog("artists-top");
				}else{
					pageTracker._trackEvent( "+_etArtists1+");
				}
			}else if(url.match("/artists/womb-management.html")){
				pageTracker._trackEvent( "+_etArtists2+");
			}else if(url.match(".html")){
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CLICK',"+ url+");
			}
		}else if(url.match(_blogNameRentalspace)){ //rental space
			var blogName = 'RENTALSPACE-MENU';
			if(id.match("rentalspace")){
				mydebuglog("_ptNone");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if(url.match(_blogNameCompany)){ //rental space
			var blogName = 'COMPANY-MENU ';
			if(id.match("company")){
				mydebuglog("_ptNone");
			}else{
				pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
			}
		}else if(url.match(_blogNameMembers)){ //rental space
			var blogName = 'MEMBERS-MENU ';
			pageTracker._trackEvent( "+blogName+", 'CONTENTS',"+ url+");
		}else if(url.match(_blogNameCalendar)){  //calendar
			var blogName = 'CALENDAR';
			var url = url.slice(1);  //#を削っています
			pageTracker._trackEvent( "+blogName+", 'CLICK',"+ url+");
		}else{
			mydebuglog("_ptNone");
		}
      }


      /*
$("a").click(function(){ // で全 a で処理させてしまって、url と要素の祖先のdiv id とかに応じてpageTracker の呼び方を変える方が良さそう。
  if(this.parents() == "mainContents") {
  } else if(this.parents() == "menuBlock") {
  }
});
       */
      
      $('#close_btn').live('mouseover',function(){$('#close_btn img').attr("src","/_common/img/contents/btn_back_on.gif");});
      $('#close_btn').live('mouseout',function(){$('#close_btn img').attr("src","/_common/img/contents/btn_back.gif");});

      //「本日」と「前日」以前のスケジュールは表示しない
/*
      function getMenuByThisMonthCalendarAfterToday(category){
          var dateFrom = new Date();
          dateFrom.setDate(dateFrom.getDate() - 1 );         // 一日前から。
          var dateTill = new Date(dateFrom.getTime());       // dateFrom を複製
          dateTill.setMonth(dateTill.getMonth() + 1);        // 翌月の
          dateTill.setDate(dateTill.getLastDayOfTheMonth()); // その月の最後の日まで。
          return buildMenu(category, dateFrom, dateTill);
      };
*/

      // string category  : ブログ名
      // Date   inDateFrom: 開始日時
      // Date   inDateTill: 終了日時
      // category ブログのdateFrom からdateTill までのエントリ情報をリストタグにいれて月次ヘッダをつけてString として返す
      function buildMenu(category, inDateFrom, inDateTill){

          var ret        = ""; // 返り値
          var currentMmh = ""; // 月次ヘッダを表示する際のフック用

          var dateFrom = new Date(inDateFrom); // 外部オブジェクトに影響を及ぼさないよう複製する。
          var dateTill = new Date();
          if(inDateTill == undefined) {
              dateTill = new Date(dateFrom.getTime());  // dateTill が省略されたときはdateFrom を使う。
          } else {
              dateTill = new Date(inDateTill);          // 外部オブジェクトに影響を及ぼさないよう複製する。
          }

          while(dateFrom <= dateTill) {
              var yyyy = dateFrom.getFullYear();
              var mmh  = dateFrom.getMonthMM();
              var dd   = dateFrom.getDate();
              var ddh  = dateFrom.getDateDD();

              // 月のヘッダ画像
              if(currentMmh != mmh){
                  ret += '<li><span class="menuMonth"><img src="/_common/img/list/ListCalendarMonth/ListCalendarMonth' + mmh + '.png" /></span></li>';
                  currentMmh = mmh;
              }

              if( array_key_exists(yyyy, calendarEntries) &&
                  array_key_exists(mmh,  calendarEntries[yyyy]) &&
                  array_key_exists(ddh, calendarEntries[yyyy][mmh]) )
              {
                  var daysEntries = calendarEntries[yyyy][mmh][ddh];
                  for (var j in daysEntries) { // Entry 表示ループ
                      if(category != "" && category != daysEntries[j]["BlogName"]){
                          continue; // カテゴリをフィルタ
                      }

                      var url      = daysEntries[j]["Permalink"];
                      var title    = daysEntries[j]["EntryTitle"];
                      var blogname = "b-name" + daysEntries[j]["BlogName"];
                      var printText = title;
                      var mojisuu = 20;
                      if(printText.length > mojisuu){
                          printText = printText.substr(0, mojisuu) + "...";
                      }
                      ret += '<li class="listNum' + ddh + '">' 
                          + '<a class="btnObj clearfix" href="' + url + '">'
                          + '<span class="date ' + blogname + '"><img src="/_common/img/cal/list/' + ddh +'.png" width="24" height="22" alt="" /></span>'
                          + '<span class="title">' + printText + '</span>'
                          + '</a>'
                          + '</li>';
                  }
              }

              dateFrom.setDate(dateFrom.getDate() + 1 ); // 日付インクリメント
          }
          return ret;
      }

      // メニューエントリのみを入れる。
      function getSubMenu(blogName){
          // メニュー全体格納用のul
          var menuUl = $("<ul />");

          // エントリ用
          var entryTmpl = '<li><a class="btnObj clearfix" href="#"><span class="title title-no"></span></a></li>';

          // setMenu を前提にしているときとデータ形式が違うので注意
          // blogName に対応したデータを取得
          var entries = blogEntries[blogName]; // blogEntries は外部ファイルから。
          for (var i = 0; i < entries.length; i++){
              var title      = entries[i].EntryTitle;
              var url        = entries[i].Permalink;
              // リンクごとのラベル
              var entryLabel = $(entryTmpl);
              $("a", entryLabel).attr("href", url);
              $("span", entryLabel).html(title);
              menuUl.append(entryLabel);
          }
          return menuUl;
      }

      // メニュー画像反転adhoc fix
      function hantenMenu(url, obj){
          $('a img', obj).each(function(){
                                   var imgTag  = $(this);
                                   var imgSrc  = imgTag.attr("src");
                                   
                                   var aTag    = imgTag.parent("a");
                                   var href    = aTag.attr("href");

                                   var bgImg = aTag.css("background-image");
                                   if( ( bgImg == undefined ) || ( (! bgImg.match("_no.gif") ) && (! bgImg.match("_on.gif")) ) ) {
                                       return;
                                   }
                                   if(aTag.attr("originalBgImg") == undefined ){
                                       aTag.attr("originalBgImg", bgImg);
                                   }

                                   var onImg = bgImg.replace("_no.gif", "_on.gif");
                                   var hantenUrl = url;
                                   if(url.match("^(/voice/[^/]+)/.*")) {
                                       hantenUrl = RegExp.$1 + "/index.html";
                                   } else if(url.match("^/company/recruit.html$")) {
                                       hantenUrl = "/company/recruit.html";
                                   } else if(url.match("^/company/")) {
                                       hantenUrl = "/company/overview.html";
                                   } else if(url.match("^/rentalspace/")) {
                                       hantenUrl = "/rentalspace/plan.html";
                                   }
                                   if(hantenUrl == href || ("http://www.womb.co.jp" + hantenUrl) == href || hantenUrl == ("http://www.womb.co.jp" + href) ){ // IE向けfix とa タグの書き方による挙動の違いを吸収
                                       aTag.unbind("mouseenter");
                                       aTag.unbind("mouseleave");
                                       aTag.css({"background-image": onImg});
                                   } else {
                                       aTag.css({"background-image": aTag.attr("originalBgImg")});
                                       aTag.unbind("mouseenter");
                                       aTag.unbind("mouseleave");
                                       aTag.mouseenter(function(){
                                                      $(this).css({"background-image": onImg});
                                                  }).mouseleave(function(){
                                                      $(this).css({"background-image": $(this).attr("originalBgImg")});
                                                  });
                                   }
                               });
      }
      
       function _tweetFunc(url){
           $('#contents a.shareMail').click(function(){
                                                    pageTracker._trackEvent( 'SHAREMAIL', 'CLICK-MAIL', url);
								   // pageTracker._trackEvent( 'SHAREMAIL', 'CLICK-MAIL',_urlTE);//100504 'click'を'twitter'に変更
								    //mydebuglog("SHAREMAIL" +_urlTE);
								    });
           $('#contents a.forTwitterLink').each(function(){
                                                    var twitterImg = $('<img width="16" height="16" alt="Share on Twitter" src="/_common/img/icon/foot_btn_twitter.gif">');
								    
                                                    var permalink  = $(this).attr("href");
								    
                                                    $(this).attr("originalTitle", $(this).text());
                                                    tweettitle = $(this).text();
                                                    var login  = 'womb';
                                                    var apiKey = 'R_b36a1180be08526b341b36e3a600f1f9';
                                                    var bitly = 'http://api.bit.ly/shorten?version=2.0.1&format=json&callback=twitterCallback'+ '&login=' + login+ '&apiKey=' + apiKey + '&longUrl=';
                                                    var script = $('<script type="text/javascript"></script>');
                                                    script.attr("src", bitly + encodeURIComponent(permalink));
                                                    $("body").append(script);
                                                    
                                                    $(this).attr("target", "_blank");
                                                    $(this).html(twitterImg);
                                                    //$(this).click(tweet);
                                                    $(this).show();
								    
								    $('#contents a.forTwitterLink').click(function(){
                                                    //pageTracker._trackEvent( 'TWITTER', 'CLICK-TWITTER',permalink);//100504 'click'を'twitter'に変更
								    if(permalink.match(".html")){
									    pageTracker._trackEvent( 'TWITTER', 'CLICK-TWITTER', permalink);
								    }
								    });
								    
                                                });
       }
      
      function heightCheckSetMax(){
          // ユーティリティ、メニュー、コンテンツの一番高さの大きいものを取得しコンテンツエリア(utility, menu 含め)の高さとする。
          var contentsAreaHeight = Math.max.apply(this, [_cal.height() + _bannerBox.height(), $('ul.newMenuBox:first', _listBox).height(), $('div.newChangeBox:first', _contents).height()]);
//          $.each([_utility, _menu, _contents], function(){ this.css({'height': contentsAreaHeight}); });
          $.each([_utility, _menu], function(){ this.css({'height': contentsAreaHeight}); });
          $.each([_contents], function(){ this.css({'height': $('.newChangeBox').height()}); });
          // ヘッダ、フッタ分の高さを足して全体の高さとしコンテナの高さを設定する。
          var pageHeight = _logo.height() + contentsAreaHeight + _commonBox.height();
          $.each([_mL, _mR, _cL, _cC, _cR, _main], function(){ this.css({'height':pageHeight}); });

          //1秒後に表示させる
          $('.social_bnr').delay(1000).fadeIn(500);



      }	

      //コンテンツの下のほうでのクリック時にpageTop へ移動させる
      function _goPageTop(){
          $('html, body').clearQueue();
	  $('html, body').animate({scrollTop:0}, 300);
      }

      //contents area に permalinkがある場合は、a に target="_blank"を追加
      function _targetBlank(){
	  $('a[href^="http://"]').attr("target", "_blank"); 
	  $('a[href^="https://"]').attr("target", "_blank"); 
      }

      //soundManager2 _iwaki追加
      soundManager.url = '/_common/js/swf/';
      soundManager.useFlashBlock = false;
      soundManager.flashVersion = 9;
      soundManager.waitForWindowLoad = true;
      soundManager.useHighPerformance = true;
      soundManager.onready(function(oStatus) {
	                       if (oStatus.success) {
	                           soundManager.createSound({id:'wombSndMouseOver',    volume:20, url: '/_common/js/sound/beep/beep003.mp3', multiShot: true, autoLoad: true });
		                   soundManager.createSound({id:'wombSndMouseDown',    volume:50, url: '/_common/js/sound/beep/beep002.mp3', autoLoad: true });
		                   soundManager.createSound({id:'wombSndEnter',        volume:10, url: '/_common/js/sound/Intro/opensound01.mp3' });
                                   $('a').live(        'mouseover',  function(event){ soundManager.play('wombSndMouseOver'); }); // すべてのa にマウスオーバー時の音を。
				   $(window).bind(     'hashchange', function(event){ soundManager.play('wombSndMouseDown'); }); // url 変更時(hash 変更時に音を。
				   $("#calBtn a").live('mousedown',  function(event){ soundManager.play('wombSndMouseDown'); }); // カレンダーの移動ボタンはhashchange を伴わないページ遷移なので。
			       }
                               mainPageObj.init(); // wombEnter1 に依存。サウンドマネージャーのロードを待ってページを開始。
	                   });

      var mainPageObj    = new mainPageClass();
      
      // マウスオーバー imagename_on.jpg imagename.jpg 的な変換
      $('#common-inner  img[alt="youtube"] ').live('mouseover',function(){$('#common-inner  img[alt="youtube"] ').attr("src","/_common/img/footer/f-icon-youtube_on.gif");});
      $('#common-inner  img[alt="youtube"] ').live('mouseout',function(){$('#common-inner  img[alt="youtube"] ').attr("src","/_common/img/footer/f-icon-youtube.gif");});
      $('#common-inner  img[alt="mixi"] ').live('mouseover',function(){$('#common-inner  img[alt="mixi"] ').attr("src","/_common/img/footer/f-icon-mixi_on.gif");});
      $('#common-inner  img[alt="mixi"] ').live('mouseout',function(){$('#common-inner  img[alt="mixi"] ').attr("src","/_common/img/footer/f-icon-mixi.gif");});
      $('#common-inner  img[alt="myspace"] ').live('mouseover',function(){$('#common-inner  img[alt="myspace"] ').attr("src","/_common/img/footer/f-icon-myspace_on.gif");});
      $('#common-inner  img[alt="myspace"] ').live('mouseout',function(){$('#common-inner  img[alt="myspace"] ').attr("src","/_common/img/footer/f-icon-myspace.gif");});
      $('#common-inner  img[alt="TERMSPOLICY"] ').live('mouseover',function(){$('#common-inner  img[alt="TERMSPOLICY"] ').attr("src","/_common/img/wombSiteTop/img/TermsPolicyRed.png");});
      $('#common-inner  img[alt="TERMSPOLICY"] ').live('mouseout',function(){$('#common-inner  img[alt="TERMSPOLICY"] ').attr("src","/_common/img/wombSiteTop/img/TermsPolicyGray.png");});
      
      $('#calPrev').live('mouseover',function(){$('#calPrev img').attr("src","/_common/img/cal/next_prev/Prev_on.png");});
      $('#calPrev').live('mouseout',function(){$('#calPrev img').attr("src","/_common/img/cal/next_prev/Prev.png");});
      $('#calNext').live('mouseover',function(){$('#calNext img').attr("src","/_common/img/cal/next_prev/Next_on.png");});
      $('#calNext').live('mouseout',function(){$('#calNext img').attr("src","/_common/img/cal/next_prev/Next.png");});
      $('#calNext').live('mouseover',function(){$('#calNext img').attr("src","/_common/img/cal/next_prev/Next_on.png");});
      $('#calNext').live('mouseout',function(){$('#calNext img').attr("src","/_common/img/cal/next_prev/Next.png");});
      
      $('#link #_schedule').live('mouseover',function(){$('#link #_schedule img').attr("src","/_common/img/sMenu/SubMenuActive1.png");});
      $('#link #_schedule').live('mouseout',function(){$('#link #_schedule img').attr("src","/_common/img/sMenu/SubMenuNonActive1.png");});
      $('#link #_voice').live('mouseover',function(){$('#link #_voice img').attr("src","/_common/img/sMenu/SubMenuActive2.png");});
      $('#link #_voice').live('mouseout',function(){$('#link #_voice img').attr("src","/_common/img/sMenu/SubMenuNonActive2.png");});
      $('#link #_artists').live('mouseover',function(){$('#link #_artists img').attr("src","/_common/img/sMenu/SubMenuActive3.png");});
      $('#link #_artists').live('mouseout',function(){$('#link #_artists img').attr("src","/_common/img/sMenu/SubMenuNonActive3.png");});
      $('#link #_members').live('mouseover',function(){$('#link #_members img').attr("src","/_common/img/sMenu/SubMenuActive4.png");});
      $('#link #_members').live('mouseout',function(){$('#link #_members img').attr("src","/_common/img/sMenu/SubMenuNonActive4.png");});
      $('#link #_store').live('mouseover',function(){$('#link #_store img').attr("src","/_common/img/sMenu/SubMenuActive5.png");});
      $('#link #_store').live('mouseout',function(){$('#link #_store img').attr("src","/_common/img/sMenu/SubMenuNonActive5.png");});
      $('#link #_map').live('mouseover',function(){$('#link #_map img').attr("src","/_common/img/sMenu/SubMenuActive6.png");});
      $('#link #_map').live('mouseout',function(){$('#link #_map img').attr("src","/_common/img/sMenu/SubMenuNonActive6.png");});

      var pdfBtnImg = $('div.flyerpdf > span:eq(1) img');
      var enterBtnImg = $('div#openning-entry .btn-enter a > img');
      pdfBtnImg.live(  'mouseover',function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2")); });
      pdfBtnImg.live(  'mouseout', function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); });
      enterBtnImg.live('mouseover',function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2")); });
      enterBtnImg.live('mouseout', function(){ $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2")); });
      // トラッキング
      //$('div#openning-entry .btn-enter a').live('click',function(){ 
      //                                    var url = $(this).attr('href');
      //				    pageTracker._trackEvent( 'TOPPAGE BANNER', 'ENTER',url);
      //				});




});

function twitterCallback(bitlyResponse) {
    for (var i in bitlyResponse.results) {
        var orignUrl = i;
        var shortUrl = bitlyResponse.results[i]['shortUrl'];
        break; // 一個目を強制的に取り出す。
    }
    
    $('#contents a.forTwitterLink').each(function(){
                                             var title = $(this).attr("originalTitle");
                                             var url = 'http://twitter.com/home/?status='+ encodeURIComponent(title + ' ' + shortUrl); 
                                             var href = $(this).attr("href");
                                             if(href == orignUrl){
                                                 $(this).attr("href", url);
                                             }
                                         });

    return false;
}



// For scrolling back to top of page

$(document).ready(function(){
	$('.pagetop').click(function(){
		$('html,body').animate({'scrollTop':0}, 300, 'swing');
	});
});
