// ==========================================================
// 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/break-night.jp/';
// anchor class
var blankWindowClass = '.blankWindow';
var miniWindowClass = '.miniWindow';
// mini window size
var mwW = 840;// width
var mwH = 660;// height
// flash player version
var flashVersion = 9.0;

// 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
  setScrollTo();// scrollTo
  if ($('#fade')) $('#fade').fadeTo(1000, 0).hide(100).empty();// fadein
  if ($('#ie6')) $('#ie6').text(ie6);
});

// 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');
}

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

// 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 =======================================
function ToTop() { location.href = root; }
function Close() { window.close(); }

