// copyright(c) "my". all rights reserved.
//
// ==========================================================
// use for "yoshinogawa.biz"
// ==========================================================

// environment
// **********************************************************
var root = 'http://' + document.domain + '/';

if((root.indexOf('localhost') > -1) || (root.indexOf('192.168.0.2') > -1)){
	root += '~my/yoshinogawa.biz/';
}else if(root.indexOf('my-kochi.net') > -1){
	root += 'yoshinogawa.biz/';
}

var ms_ie5or6 = new Boolean();
var winFirefox = new Boolean();
var ua = navigator.userAgent;
//'IE5~6'
if(ua.indexOf("Win") > -1){
	if((ua.indexOf("MSIE 5") > -1) || (ua.indexOf("MSIE 6") > -1)) ms_ie5or6 = true;
	else ms_ie5or6 = false;
	if(ua.indexOf("Firefox") > -1)  winFirefox = true;
	else winFirefox = false;
}
// Safari for swf
function safari(){
	if((ua.indexOf("Safari")) > -1) return true;
	else return false;
}

// for swf
// **********************************************************
// return string
function titleCall(){
	var url = location.href;
	var i = url.split('/');
	var name = i[i.length - 1];
	if(name.indexOf('.') > 1) name = name.split('.')[0];
	if(name.indexOf('#') > 1) name = name.split('#')[0];
	if(name.indexOf('?') > 1) name = name.split('?')[0];
	name = name.toUpperCase();
	return name;
}

// intialize for jquery
// **********************************************************

// lightbox
function lightboxSet(){
	if($('.lightbox a:visible').length != 0){
		$('.lightbox a:visible').lightBox({
			overlayBgColor:'#000000',
			overlayOpacity:0.7,
			imageLoading:root + 'img/lightbox/loading.gif',
			imageBtnPrev:root + 'img/lightbox/prev.gif',
			imageBtnNext:root + 'img/lightbox/next.gif',
			imageBtnClose:root + 'img/lightbox/close.gif',
			imageBlank:root + 'img/lightbox/blank.gif',
			containerBorderSize:10,
			containerResizeSpeed:500
		});
	}
}
// ui.tabs
function ui_tabsSet(){
	if($('.menulistContainer').length != 0){
		$('.menulistContainer').tabs({
			selected:0,
			fx:{opacity:"toggle", duration:"normal"}
		});
	}
}
// ui.tabs
function ui_accordionSet(){
	if($('#accordion').length != 0){
		$('#accordion').accordion({
			header:"h4"
		});
	}
}

// onload event
// **********************************************************
$(document).ready(function(){
	if($('#javascriptEnabled')) $('#javascriptEnabled').html('<p class="center green bold">ただいま JavaScript は有効になっています。</p>');// enabled check
	targetWindowSet();// anchor
	lightboxSet();// lightbox
	ui_tabsSet();// ui.tabs
	ui_accordionSet();// ui.tabs
});


// window open
// **********************************************************
function targetWindowSet(){
	// new window
	if($(".blankWindow").size()){
		var ct = 0;
		$(".blankWindow").each(function(){
			$(".blankWindow:eq(" + ct + ")").click(function(){newWindow($(this));});
			ct++;
		});
	}
	// mini window
	if($(".blankMini").size()){
		var ct = 0;
		$(".blankMini").each(function(){
			$(".blankMini:eq(" + ct + ")").click(function(){miniWindow($(this));});
			ct++;
		});
	}
}

// new window open
function newWindow(obj){
	var url = obj.attr('href');
	obj.attr('href', 'javascript:void(0);');
	obj.mouseout(function(){obj.attr('href', url);});
	window.open(url);
}

// mini window
function miniWindow(obj){
	var url = obj.attr('href');
	obj.attr('href', 'javascript:void(0);');
	// size
	var w = 640; var h = 560;
	if(w > screen.width) w = screen.width;
	if(h > screen.height) h = screen.height;
	// position
	var x = screen.width / 2 - w / 2;
	var y = (screen.height / 2 - h / 2) - 50;
	if(y < 0) y = 0;
	//
	obj.mouseout(function(){obj.attr('href', url);});
	// window
	window.open(url, 'mini',"top=" + y + ", left=" + x + ", width=" + w + "px, height=" + h + "px, toolbar=0, directories=0, status=0, scrollbars=1, resizable=0");
}
