/*****************************************************************
/*
/* 起動時移動
/*
/*****************************************************************/
$(document).ready(function() {


	var content_subtitle = $(".content_subtitle");

	if( jQuery.browser.msie ) {
		if( jQuery.browser.version < 8.0){
			content_subtitle.css("padding-top", "11px");
			content_subtitle.css("padding-bottom", "10px");
		}

		if( jQuery.browser.version < 7.0){
			content_subtitle.css("background-image", "url('images/common/subtitle_ie6.png')");
		}
	}

	content_subtitle.each(function() {
			temp_width = 600 - $(this).find("span, h1").width() - 30;
			$(this).css("background-position", "-" + temp_width + "px 0px");
	});

	var mobile_qr_url = $("#mobile_qr_url");
	
	if( mobile_qr_url.width() > 140 )
	{
		mobile_qr_url.html( (mobile_qr_url.html()).replace(".",".<br />")  );
	}
	else 	if( mobile_qr_url.height() > 20 )
	{
		mobile_qr_url.html( (mobile_qr_url.html()).replace(".",".<br />")  );
	}

	var navi_object = $("#navi");
	var navi_inquiry = $("#navi_inquiry");
	
	if( navi_object.size()>0 &&  navi_inquiry.size()>0 )
	{
		navi_inquiry.prependTo(navi_object);
	}
});	

/*****************************************************************
/*
/* スマートフォン判定
/*
/*****************************************************************/
function check_smartphone() {


	if( $.cookie("smart_phone_jumped") == undefined ||  $.cookie("smart_phone_jumped") == null || $.cookie("smart_phone_jumped") != "true" )
	{
		var agent = navigator.userAgent;
	
		if(agent.indexOf("Android") > -1 ||
				agent.indexOf("iPhone") > -1 )
		{
				$.cookie("smart_phone_jumped", "true");
				location.href = "sp/";
		}
	}

}

/*****************************************************************
/*
/* ポップアップ表示用
/*
/*****************************************************************/
function popup(path, name, width, height, position, scrollbars, resizable) {

	if( typeof(position) == "undefined" ) {
		position = "center";
	}

	if( typeof(scrollbars) == "undefined" ) {
		scrollbars = "no";
	}

	if( typeof(resizable) == "undefined" ) {
		resizable = "yes";
	}

	if(position == "center") {
		lf= (window.screen.availWidth - width) / 2;
		tp = (window.screen.availHeight - height) / 2;
	} else if(position == "right") {
		lf = window.screen.availWidth - width - 10;
		tp= 0;
	} else {
		lf= 0;
		tp = 0;
	}

	window.open("/popup.html?src="+path, name, "top="+tp+",left="+lf+",width="+width+",height="+height+",resizable="+resizable+",scrollbars="+scrollbars+",status=no,toolbar=no,directories=no,menubar=no");
}


/*****************************************************************
/*
/* ソーシャルブックマークの登録用
/*
/*****************************************************************/
function addSocialBookmark(SMB, Link, Title) {

	var title;
	var link;
	var open_url;

	// タイトルの指定が無ければ現在のHTMLのタイトルを使用
	if( Title != undefined || Title=="" )
	{
		title = encodeURIComponent(Title);
	}
	else
	{
		title = encodeURIComponent(document.title);
	}

	// リンクの指定が無ければ現在のホスト名を利用
	if( Link != undefined || Link=="" )
	{
		link = encodeURIComponent(Link);
	}
	else
	{
		link = encodeURIComponent("http://" + window.location.hostname + "/");
	}


	switch( SMB )
	{
		case "Yahoo":
			open_url = "http://bookmarks.yahoo.co.jp/bookmarklet/showpopup"
									+ "?t=" + title
									+ "&u=" + link
									+ "&opener=bm&ei=UTF-8";
			break;

		case "Google":
			open_url = "http://www.google.com/bookmarks/mark"
									+ "?op=edit"
									+ "&title=" + title
									+ "&bkmk=" + link;

			break;

		case "Hatena":
			open_url = "http://b.hatena.ne.jp/append"
									+ "?" + link;
			break;

		case "Nifty":
			open_url = "http://clip.nifty.com/create"
									+ "?title=" + title
									+ "&url=" + link;
			break;
							

		case "livedoor":
			open_url = "http://clip.livedoor.com/redirect"
									+ "?title=" + title
									+ "&link=" + link;
			break;
							

		case "delicious":
			open_url = "http://del.icio.us/post"
									+ "?title=" + title
									+ "&url=" + link;
			break;

		
		default:
			open_url = ""
			break;
	}

	window.open(open_url);
	//alert(open_url);
}


/*****************************************************************
/*
/* ブックマークの登録用
/*
/*****************************************************************/
function addBookmark(URL, Title) {
	try {
		window.external.AddFavorite(URL, Title);
	} catch(e) {
		alert("このリンクはIE(Internet Exploler)専用です");
	}
}

/*****************************************************************
/*
/* 動きのあるTOPに戻る用
/*
/*****************************************************************/
function ScrollToTop( target_obj ) {
	var scroll_obj;
	var scroll_position = 0;
	
	if( target_obj != undefined && target_obj != null )
	{
		scroll_position = target_obj.position().top;
	}

	if( $.browser.safari )
	{
		scroll_obj = $("body");
	}
	else
	{
		scroll_obj = $("html");
	}
	
	scroll_obj.animate({ scrollTop: scroll_position });
}


/*****************************************************************
/*
/* ブラウザ強制閉じスクリプト
/*
/*****************************************************************/

function WindowForceClose() {

	window.opener = window;
	window.open(location.href,'_self');
	window.close();

}


/*****************************************************************
/*
/* XHTMLの為のIframe動的呼び出し
/*
/*****************************************************************/

function ShowIframe(Width, Height, Src, ID, Text, Scrolling) {
	
	if( typeof(Width) == "undefined" || Width=="" ) {
		Width = "100%";
	}

	if( typeof(Height) == "undefined" || Height=="" ) {
		Height = "100%";
	}

	if( typeof(Text) == "undefined" || Text=="" ) {
		Text = "ここはインラインフレームです";
	}

	if( typeof(Scrolling) == "undefined" || Scrolling=="" ) {
		Scrolling = "no";
	}

	var tag = "<iframe id='" + ID +"' src='" + Src +"' frameborder='0' width='" + Width + "' height='" + Height +"' scrolling='" + Scrolling + "'>"
							+ Text
							+ "</iframe>";
	
	document.write(tag);

}

