// ==========================================================
// with 'jquery.js'
// Y.Morita <mail@emwai.jp>
// copyright(c) my. all rights reserved.
// ==========================================================

// variables ================================================
// root directory
var root = 'http://' + document.domain + '/';
if ((root.indexOf('localhost') > -1) || (root.indexOf('192.168.24.51') > -1)) root += '~my/katsuotataki.net/';
// anchor class
var blankWindowClass = '.blankWindow';
var miniWindowClass = '.miniWindow';
var miniWindowClass2 = '.blankMini';
// mini window size
var mwW = 720;// width
var mwH = 560;// height
// flash player version
var flashVersion = 9.0;
// cookie life
var cookieLife = 1;// 日数

// environment ==============================================
// user agent
var ua = navigator.userAgent;
var ms_ie5or6 = new Boolean();// IE5 ~ 6
var winFirefox = new Boolean();// Windows Firefox
if (ua.indexOf("Win") > -1) { ms_ie5or6 = ((ua.indexOf("MSIE 5") > -1) || (ua.indexOf("MSIE 6") > -1)) ? true : false; winFirefox = (ua.indexOf("Firefox") > -1) ? true : false; }
// safari
function safari () { return ((ua.indexOf("Safari")) > -1) ? true : false; }

var ie6 = 'インターネットエクスプローラのバージョン６以下では表示が乱れます。ご了承下さい。';

// cookie life
var cookieLife = 1;

// onload event =============================================
$(document).ready(function () {
  setAnchor();// anchor
  setCeebox();// ceebox
  setScrollTo();// scrollTo
  uiTabsSet();// ui.tabs
  if ($('#fade')) $('#fade').fadeTo(1000, 0).hide(100);// fadein
  if ($('#ie6')) $('#ie6').text(ie6);
  if ($('#javascriptEnabled')) $('#javascriptEnabled').html('<span class="green">ただいま JavaScript は有効になっています。</span>');// enabled check
});

// meta tag ====================
setCSS(); // css

// anchor ======================
function setAnchor () {
  // blank window
  if ($(blankWindowClass).size()) {
    $(blankWindowClass).each(function () {
      $(this).attr('target', '_blank');
    });
  }
  // mini window
  if ($(miniWindowClass).size()) {
    $(miniWindowClass).each(function () {
      $(this).click(function () {
        miniWindow($(this).attr('href'), mwW, mwH, false);
        return false;
      });
    });
  }
}
function miniWindow (url, w, h, swfCall) {
  if (w > screen.width) w = screen.width;
  if (h > screen.height) h = screen.height;
  var x = screen.width / 2 - w / 2;
  var y = (screen.height / 2 - h / 2) - 50;
  if (y < 0) y = 0;
  window.open(url, 'mini',"top=" + y + ", left=" + x + ", width=" + w + "px, height=" + h + "px, toolbar=0, directories=0, status=0, scrollbars=1, resizable=0");
}

// ceebox ======================
function setCeebox () {
  if ($('.ceebox-video-480x300').length != 0) $('.ceebox-video-480x300').ceebox({videoRatio:false, videoWidth:480, videoHeight:300, imageWidth:480, imageHeight:300});
  if ($('.ceebox-video-360x300').length != 0) $('.ceebox-video-360x300').ceebox({videoRatio:false, videoWidth:360, videoHeight:300, imageWidth:360, imageHeight:300});
  if ($('.ceebox').length != 0) $('.ceebox').ceebox();
}

// scrollTo ====================
function setScrollTo () {
  if ($('.index').length != 0) {
    $('.index').click( function(event) {
      if ( $(this).attr('href') == '#') $(this).attr('href', '#wrapper');
      $.scrollTo($(this).attr('href'), 500);
      evtCncl(event);
    });
  }
}
function evtCncl(event) {
  if (!event) event=window.event;
  if (event.preventDefault) event.preventDefault();
  else event.returnValue = false;
}

// ui.tabs =====================
function uiTabsSet() {
  try {
    if ($('#menubook-container').length != 0) {
      $('#menubook-container').tabs({
        selected:0,
        fx:{ opacity:"toggle", duration:"normal" }
      });
      // footer adjust
      $('#menubook-container #tabs a').mouseout(function() {
        $('#footer').css('bottom', '1px');
        $('#footer').css('bottom', '0');
      });
    }
  }
  catch (e) { }
  finally { }
}

// css =========================
function setCSS () {
  var tags = '<link rel="stylesheet" href="' + root + 'css/ceebox.css" type="text/css" />';
  document.write (tags);
}

// cookie ======================
// read cookie
function readCookie (req) {
  if (!req) req = 'swf';
  var values = document.cookie.split('; ');
  for (var i = 0; values.length > i; i++) {
    var pair = values[i].split("=");
    if (pair[0] == req) return pair[1];
  }
  return null;
}
// get format
function getCookieFormat (param, value, life) {
  var expires = new Date();
  expires.setTime(expires.getTime() + 1000 * 60 * 60 * 24 * life);
  var str = param + '=' + value + '; ';
      str += 'expires=' + expires.toGMTString() + '; ';
      //str += 'path=' + root + ';';
      str += 'path=/;';
  return str;
}

// external interface =======================================
// set navigation bar
function forNavigation() {
  if (location.href.indexOf('/home') > -1) return 'home';
  else if (location.href.indexOf('/food') > -1) return 'food';
  else if (location.href.indexOf('/drink') > -1) return 'drink';
  else if (location.href.indexOf('/course') > -1) return 'course';
  else if (location.href.indexOf('/guide') > -1) return 'guide';
  else if (location.href.indexOf('/tennai') > -1) return 'tennai';
  else return 'home';
}


