/*	// サイト内オブジェクトの設定まとめ
	// の JSON
*/
var bmObjects = {
	// ロゴ画像
	'topLogo':{
		'src':'images/bm_logo3.png',
		'width':350,
		'height':139
	},
	// googleカレンダー
	'gCal':{
		'src':'http:\/\/www.google.com\/calendar\/embed?height=330&amp;wkst=1&amp;hl=ja&amp;bgcolor=%23FFFFFF&amp;src=k48dqiutqgo0q2ij7o72gqsi94%40group.calendar.google.com&amp;color=%23A32929',
		'style':'border:0px none #ffffff;',
		'frameborder':0,
		'width':400,
		'height':330,
		'titleStr':'ぶるーめん定休日 - Googleカレンダー',
		'altStr':'ぶるーめんの定休日'
	}
};
// bmObjects.topLogo.src	…みたいに参照

/* スタイルシートにルール追加 */
function insetRule(selector,declarations){
	var sheets=document.styleSheets;
	if (sheets){
		for (var i=0; i < sheets.length; i++){
			if ((sheets[i].disabled == false)||(!sheets[i].title)) {
			if ((!!window.ActiveXObject)&&(navigator.userAgent.indexOf("MSIE"))||((navigator.userAgent.indexOf("WebKit")>0)&&(navigator.userAgent.indexOf("like Gecko")>0))) sheets[i].addRule(selector,declarations);
			else sheets[i].insertRule(selector+"{"+declarations+"}",sheets[i].cssRules.length);
			}
		}
	}
}

// スタイルシートに追加するルール
// insetRule('dd#banner-sec dl dd','display:none;');

/* 検索ビューを表示(use jQuery and ThickBox) */
var ppSearchWin = function (target) {
	var trg = $(target);
	for (var i=0;i<trg.length;i++) {
		trg[i].href = trg[i].href+'?keepThis=true&amp;TB_iframe=true&amp;height=300&amp;width=550';
	}
};

// jQuery Plug-ins (自作)
//  .attrAppend('対象属性','追加文字列') : Attribute に文字列を追加
//  .openNewWin('title文字追加') : 外部サイトを新規ウィンドウで開く
(function($){
 $.fn.extend({
  attrAppend : function(attrName,text){
   return this.each(function (){
    $(this).attr(attrName,$(this).attr(attrName)+text);
   });
  },
  openNewWin : function(phrase){
   return this.each(function (){
    var trg = $(this);
    trg.attrAppend('title', phrase || $.fn.openNewWin.details.defaultcomment);
    trg.click(function(e){window.open(this.href);e.preventDefault();});
    trg.keypress(function(e){window.open(this.href);e.preventDefault();});
   });
  }
 });
 $.fn.openNewWin.details = {defaultcomment:'(Open as new window)'};	// openNewWin の標準設定
})(jQuery);


// 透過 PNG に代替（主にロゴ）
//	altAlphaImg(ElementID,ObjectProperty)
var altAlphaImg = function (altElm,objPrp) {
	var imgAttr = objPrp;
	var altTrg = document.getElementById(altElm);
	if ((!!window.ActiveXObject) && (!!navigator.userAgent.match('MSIE 6.0'))) {
		while (altTrg.childNodes.length) altTrg.removeChild(altTrg.childNodes[0]);
		altTrg.style.display = 'block';
		altTrg.style.width = objPrp.width+'px';
		altTrg.style.height = objPrp.height+'px';
		altTrg.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true",sizingMethod="crop",src="'+objPrp.src+'");';
	} else {
		altTrg = altTrg.firstChild;
		altTrg.width = objPrp.width;
		altTrg.height = objPrp.height;
		altTrg.src = objPrp.src;
	}
};

/* google calendre を追加 */
var appendGC = function (appID) {
	var appObj = document.getElementById(appID);
	var defInnerObj = appObj.innerHTML;
//	while (appObj.childNodes.length) appObj.removeChild(appObj.childNodes[0]);	// 内容をクリア
	var wrapperWidth = bmObjects.gCal.width+20;	//外周の div の widht を +20 で自動的に拡張
	insetRule('div#container div.contents-body div div#'+appID,'width:'+wrapperWidth+'px;');
	appObj.innerHTML = '<p><a id="show-calender" title="カレンダーを表示/非表示"><img alt="[カレンダーを表示]" src="common/img/application_get.png" width="16" height="16" />定休予定を Google カレンダーで表示</a></p><div id="calendar-table" style="margin:0px;padding:0px;"><iframe src="'+bmObjects.gCal.src+'" style="'+bmObjects.gCal.style+'" frameborder="'+bmObjects.gCal.frameborder+'" width="'+bmObjects.gCal.width+'" height="'+bmObjects.gCal.height+'">'+defInnerObj+'</iframe></div>';
	insetRule('p a#show-calender','font-size:150%;');
	insetRule('p a#show-calender img','display:inline;margin-left:1ex;');
//	$('div#calendar-table').hide();
	$('a#show-calender').click(function(){$('#calendar-table').toggle(1000);});
};

/* ページ内でスクロールを設定する class とスクロール先 */
///* jQuery::interface.js::ifxscrollto.js(fixed) */
$(function() {
	$('a.to-page-title').click(	//ページ先頭へ
	function(e){
		$('#header').ScrollTo(1000,'easeout');
		e.preventDefault();
	});
	$('a.to-page-con').click(	//コンテンツ先頭へ
	function(e){
		$('#container').ScrollTo(1000,'easeout');
		e.preventDefault();
	});
	$('a.to-page-link').click(	//リンクへ
	function(e){
		$('#navigation').ScrollTo(1000,'easeout');
		e.preventDefault();
	});
	$('a.to-schedule').click(	//カレンダーへ
	function(e){
		$('#schedule').ScrollTo(1000,'easeout');
		e.preventDefault();
	});
	$('a.to-telnum').click(	//電話番号へ
	function(e){
		$('#tel').ScrollTo(1000,'easeout');
		e.preventDefault();
	});
});

/* ロード完了時実行 */
$(document).ready(function(){
	ua = navigator.userAgent;
	if (document.getElementById('to-mobile')) {	// Smartphoneページのフルブラウザテスト用
		$('#to-mobile').attrAppend('href','?keepThis=true&amp;TB_iframe=true&amp;height=480&amp;width=320');
		if((!!window.ActiveXObject)&&(ua.indexOf("MSIE"))) $('#to-mobile').hide();
	}
	$('#to-help').attrAppend('href','?keepThis=true&amp;TB_iframe=true&amp;height=400&amp;width=500');
	if (document.getElementById('qrcode-sect')) $('p#qrcode-sect a').openNewWin('（新規ウィンドウ→）');
	$('a.external').openNewWin('（新規ウィンドウ→）');
//	ppSearchWin('a.in-search'); // （旧）
	$('a.in-search').attrAppend('href','?keepThis=true&amp;TB_iframe=true&amp;height=300&amp;width=550');	// 検索結果のモーダル表示
	$('a.phone-number').removeAttr('href').attr('title','お電話はこちらの番号まで').click(function(){alert('Sorry! for your access...\n\n大変恐れ入ります。\n\n　今のところ、インターネットでのご連絡はお受けしておりません。\n　当店へのご連絡は\n\n　　023(631)2876\n\nの番号まで、営業時間内でお電話いただければ助かります。')});
	if (document.getElementById('logoimage')) altAlphaImg('logoimage',bmObjects.topLogo);
	if (document.getElementById('google-calendar')){
		insetRule('dd#banner-sec dl dd','display:none;');
		appendGC('google-calendar');
	}
	// var chkstat=ua.search('iPad')?'true':'false'; alert('ua.search("iPad") is '+chkstat);
	if ((ua.indexOf("iPhone")>0)||(ua.indexOf('iPad')>0)||(ua.indexOf('Android')>0)||(ua.indexOf('BlackBerry')>0)) {	// ||(ua.search('iPad'))||(ua.search('Android'))||(ua.search('BlackBerry'))||(ua.search('Chrome'))
		$('<button type="button" id="sp" title="スマートフォン用ページへ移動">⇒ to Smart Phone</button>').insertBefore('#global-frame').hide();
		insetRule('#sp','margin:20px auto;padding:35px;width:100%;color:#fff;text-shadow:3px 3px 7px #000;background:#000 -webkit-gradient(linear,left top,left bottom,color-stop(0.2,rgb(204,204,204)),color-stop(1,rgb(102,102,102)));background:-moz-linear-gradient(center top,rgb(204,204,204) 20%,rgb(102,102,102) 100%);text-align:center;font:normal normal bold 60px/1.1em sans-serif;border-radius:50px;-moz-border-radius:50px;-webkit-border-radius:50px;');
		$('#sp').click(function(){window.location.href='./iphone.html'}).show(1500);
	}
});
	// && window.location.href.match('\/barblumen')	// Tickbox 考察用

