// ==========================================================
// 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/hanakoromo.com/';
// anchor class
var blankWindowClass = '.blankWindow';
var miniWindowClass = '.miniWindow';
// mini window size
var mwW = 720;// width
var mwH = 560;// height
// flash player version
var flashVersion = 10.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 = 'インターネットエクスプローラのバージョン6以下では表示が乱れます。ご了承下さい。';

// event ====================================================
// onload
$(document).ready(function () {
  setAnchor();// anchor
  bgmSet();// sound
  jflowSet();// jflow
  swfLightboxSet();
  mapBtnSet();
  if ($('#fade')) $('#fade').fadeTo(1000, 0).hide(100);// fadein
  if ($('#ie6')) $('#ie6').text(ie6);
  if($('#javascriptEnabled')) $('#javascriptEnabled').html('<p class="center green bold">ただいま JavaScript は有効になっています。</p>');// enabled check
});
// unload
window.onunload = function (e) {
  if (navigator.cookieEnabled && $('#bgm')) {
    var str = document.bgm.swfSound();
    var result  = 'bgm=' + str + '; ';
        result += "path=/;";
    document.cookie = result;
  }
}
// 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");
}
// sound =======================
function bgmSet(){
  if ($('#navi')) $('#navi ul').css('width', '540px');
  if ($('#bgm-container')) $('#bgm-container').css('display', 'inline');
}

// jflow =======================
function jflowSet () {
  if ($('#slider').length != 0) {
    $("#slider").jFlow({
slides:"#slides",
controller:".slide-control",
slideWrapper:"#slide",
selectedWrapper:"slide-selected",
easing:"swing",
duration:500,
width:"510px",
height:"350px",
prev:".slide-prev",
next:".slide-next"
    });
    $('#slider a').attr('href', 'javascript:void(0);');
  }
}

// ==========================================================
// document title
var titles = [
'土佐自然嗜好　花ころも',
'土佐自然嗜好　花ころも／ホーム',
'花ころも／旬のおすすめ',
'花ころも／お知らせ',
'花ころも／おしながき',
'花ころも／お飲みもの',
'花ころも／ご宴会料理',
'花ころも／お店ご案内'
];
var num = 0;
var frames = ['', 'home', 'today', 'info', 'menu', 'drink', 'course', 'guide'];
for (var i = 1; i <= frames.length; i++) { if (location.href.indexOf('.com/'+ frames[i]) > -1) num = i; }
if (location.href.indexOf('.com/cgi/info.cgi') > -1) num = 3;
// document.title = titles[num];

// swf ======================================================
// read cookie
function readCookie () {
  if (navigator.cookieEnabled && $('#bgm')) {
    var values = document.cookie.split('; ');
    for (var i=0; values.length>i; i++) {
      var pair = values[i].split("=");
      if (pair[0] == 'bgm') return pair[1];
    }
  }
  return 'pos:0&volNum:2';
}
// index
function indexFlag () { 
  if (location.href.match(/\/$/) || location.href.match(/\/index\.s?html?$/)) return true;
  else return false;
}
function soundFadeOut () {
  if ($('#bgm')) document.bgm.swfFadeOut();
  return true;
}
// lightbox
function swfLightboxSet () {
  if ($(".swflightbox").size()) {
    $(".swflightbox").each( function () {
      $(this).click( function() {
        if (document.swf) document.swf.lightbox ($(this).attr('href'), $(this).attr('title'));
        return false;
      });
    });
  }
}
// guide map
function mapBtnSet () {
  if ($(".mapbtn").size()) {
    $(".mapbtn").each( function () {
      $(this).click( function() {
        if (document.route) document.route.routine($(this).attr('rel'));
        return false;
      });
    });
  }
}
// course
function swflightboxTimer (ref, title) {
  var timerID = setTimeout( function () {
    if (document.swf) document.swf.lightbox(ref, title);
    clearTimeout(timerID);
  }, 1000);
}
// callback
function callBack () { return frames[num]; }
function getRoot () { return root; }


