// ==========================================================
// 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/habotan.jp/';
// anchor class
var blankWindowClass = '.blankWindow';
var miniWindowClass = '.miniWindow';
// 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 = 'インターネットエクスプローラのバージョン６以下では表示が乱れます。ご了承下さい。';

// onload event =============================================
$(document).ready(function () {
  setAnchor();// anchor
  setCeebox();// ceebox
  setShuffle();// jqshuffle
  setPicture();// picture
  if ($('#fade')) $('#fade').fadeTo(1000, 0).hide(100);// fadein
  if ($('#ie6')) $('#ie6').text(ie6);
  //
  $('#swfobject').css("background-image", "none");
});

// 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-540x540').length != 0) $('.ceebox-video-540x540').ceebox({videoRatio:false, videoWidth:540, videoHeight:540, imageWidth:540, imageHeight:540});
  if ($('.ceebox').length != 0) $('.ceebox').ceebox();
}

// shuffle =====================
function setShuffle () {
  if ($('.shuffle').length != 0) $('.shuffle').jqShuffle({
    width:180,
    speed:500,
    auto:0,
    random:0,
    easing:null,
    coords:null,
    delay:0,
    timeout:4000
  });
}
// css =========================
function setCSS () {
  var tags = '<link rel="stylesheet" href="' + root + 'css/ceebox.css" type="text/css" />';
  document.write (tags);
}

// picture
function setPicture () {
  var margin = 5;
  var border = 5;
  if ($('.picture').size()) {
    $('.picture').each(function () {
      var img = $(this).find('img');
      var w = img.width();
      var h = img.height();
      // tagging
      img.before('<span class="picture-shadow-top picture-shadow-tb"></span><span class="picture-shadow-right picture-shadow-lr"></span><span class="picture-shadow-bottom picture-shadow-tb"></span><span class="picture-shadow-left picture-shadow-lr"></span>');
      img.after('<span class="picture-reflect"></span><span class="picture-mark"></span>');
      // wrapper
      var box = margin * 2 + border * 2;
      $(this).css('display', 'block').css('width', w + box).css('height', h + box);
      // shadow
      var shadowW = w + border * 2 + 'px';
      var shadowH = h + border * 2 + 'px';
      $(this).find('.picture-shadow-tb').css('margin', '0 ' + margin + 'px').css('width', shadowW).css('height', margin + 'px');
      $(this).find('.picture-shadow-lr').css('margin', margin + 'px' + ' 0').css('width', margin + 'px').css('height', shadowH);
      // reflect
      $(this).find('.picture-reflect').css('margin', margin * 2 + 'px').css('width', w + 'px').css('height', h + 'px');
      // marking
      // $(this).find('.picture-mark').
    });
  }
}


// external interface
// ==========================================================
// set navigation bar
function callBack () {
  if (location.href.indexOf('/about') > -1) return 'about';
  else if (location.href.indexOf('/menu') > -1) return 'menu';
  else if (location.href.indexOf('/feast') > -1) return 'feast';
  else if (location.href.indexOf('/detail') > -1) return 'detail';
  else return 'index';
}

// sound
window.onunload = function () {
  try{
    if(navigator.cookieEnabled){
      var str = document.swfobject.swfSound();
      var result = 'bgm=' + str + '; ';
          result += "path=/;";
          document.cookie = result;
    }
  }
  catch(e){}
}
function indexFlag () {
  var index = callBack();
  if(index == 'index') return true;
  else return false;
}
function readCookie () {
	if(navigator.cookieEnabled && $('#swfobject')){
		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';
}



