/*******************************************************************************
Function htmlspecialchars
*******************************************************************************/
function htmlspecialchars(string) {
return (string + '').replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
/*******************************************************************************
Function preg_quote
*******************************************************************************/
function preg_quote(string) {
return (string + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, "\\$1");
}
/*******************************************************************************
Function rel2abs
Source: http://d.hatena.ne.jp/brazil/20070103/1167788352
*******************************************************************************/
function rel2abs(relUrl) {
var span = document.createElement('span');
span.innerHTML = '<a href="' + htmlspecialchars(relUrl) + '" />';
return span.firstChild.href;
}
/*******************************************************************************
Function normalizeUrl
*******************************************************************************/
function normalizeUrl(url) {
url = rel2abs(url);
url = url.split('#')[0];
url = url.split('?')[0];
url = url.replace('/index.html', '/');
return url;
}
/*******************************************************************************
Class URI
Source: http://d.hatena.ne.jp/javascripter/20090309/1236590529
*******************************************************************************/
function URI(uri) {
uri = String(uri);
var parser = /^([^:/?#]+:)?\/\/(([^/?#:]*):?(\d*))?([^?#]*)(\?[^#]*)?(#.*)?$/;
var m = uri.match(parser);
if (!m) throw new URIError("malformed URI given");
this.href = m[0];
this.protocol = m[1] || "";
this.host = m[2] || "";
this.hostname = m[3] || "";
this.port = m[4] || "";
this.pathname = m[5] || "";
this.search = m[6] === "?" ? "" : m[6] || "";
this.hash = m[7] || "";
}
URI.prototype.toString = function () {
return this.href;
};
/*******************************************************************************
Class Site
*******************************************************************************/
/* 本当はSingletonパターンにすべき。 */
function Site() {
var href = $('link[rel="start"]').attr('href');
if (typeof href != 'undefined') {
href = rel2abs(href);
this.URL = href.replace('/index.html', '/');
}
this.commonFolder = new Object();
var src = $('script[src$="/js/jquery.js"]').attr('src');
if (typeof src != 'undefined') {
src = rel2abs(src);
this.commonFolder.URL = src.replace('/js/jquery.js', '/');
}
}
/*******************************************************************************
Object imageCache
*******************************************************************************/
var imageCache = new Object();
/*******************************************************************************
Object location.queryParams
*******************************************************************************/
location.queryParams = $.parseQuery({'f':function(v){return decodeURIComponent(v).replace(/\+/g,' ');}});
/*******************************************************************************
小画面／印刷向けスタイルシートを有効化
*******************************************************************************/
(function() {
if (location.queryParams['style'] == 'minimum') {
/*
for (var i = 0; i < document.styleSheets.length; i++) {
var styleSheet = document.styleSheets[i];
if (styleSheet.title == '\u5c0f\u753b\u9762\uff0f\u5370\u5237\u5411\u3051') {
styleSheet.disabled = false;
}
}
*/ /* WebKitで効かない */
$('link[rel="alternate stylesheet"][title="\u5c0f\u753b\u9762\uff0f\u5370\u5237\u5411\u3051"]').each(function() {
this.disabled = false;
this.rel = 'stylesheet'; /* for WebKit and IE */
});
}
if (document.referrer) {
var referrer = new URI(document.referrer);
referrer.queryParams = $.parseQuery(referrer.search, {'f':function(v){return decodeURIComponent(v).replace(/\+/g,' ');}});
if (referrer.hostname == location.hostname && referrer.queryParams['style'] == 'minimum' && location.queryParams['style'] != 'minimum') {
var protocol = location.protocol;
var host = location.host;
var pathname = location.pathname;
var search = location.search;
if (!search) {
search = '?style=minimum';
} else {
search += '&style=minimum';
}
var hash = location.hash;
location.href = protocol + '//' + host + pathname + search + hash;
}
}
})();
/*******************************************************************************
画像ロールオーバー
*******************************************************************************/
$(function() {
$('[src*="-normal."]').each(function() {
var srcNormal = this.src;
var srcHover = srcNormal.replace('-normal.', '-hover.');
imageCache[srcHover] = new Image();
imageCache[srcHover].src = srcHover;
var srcActive = srcNormal.replace('-normal.', '-active.');
imageCache[srcActive] = new Image();
imageCache[srcActive].src = srcActive;
$(this).hover(
function() { this.src = srcHover; },
function() { this.src = srcNormal; }
);
$(this).mousedown(
function() { this.src = srcActive; }
);
$(this).mouseup(
function() { this.src = srcNormal; }
);
});
});
/*******************************************************************************
画像ポップアップ
*******************************************************************************/
$(function() {
var site = new Site();
var $a = $('a.popup');
if ('lightBox' in $a) {
$a.lightBox({
imageLoading: site.commonFolder.URL + 'images/lightbox-ico-loading.gif'
, imageBtnPrev: site.commonFolder.URL + 'images/lightbox-btn-prev.gif'
, imageBtnNext: site.commonFolder.URL + 'images/lightbox-btn-next.gif'
, imageBtnClose: site.commonFolder.URL + 'images/lightbox-btn-close.gif'
, imageBlank: site.commonFolder.URL + 'images/lightbox-blank.gif'
});
} else if ('colorbox' in $a) {
$a.colorbox({
initialWidth: 200
, initialHeight: 200
});
}
});
/*******************************************************************************
現在地表示
*******************************************************************************/
$(function() {
/*
var flag = false;
var href1 = location.href;
href1 = href1.replace(location.hash, '');
href1 = href1.replace(location.search, '');
href1 = href1.replace('/index.html', '/');
$('#GLOBALNAV ul.menu a[href]').each(function() {
var href2 = rel2abs(this.href).replace('/index.html', '/');
if (href1 == href2) {
$(this).wrap('<strong/>');
flag = true;
}
});
if (!flag) {
$('link[rel="up"]').each(function() {
var href1 = rel2abs(this.href).replace('/index.html', '/');
$('#GLOBALNAV ul.menu a[href]').each(function() {
var href2 = rel2abs(this.href).replace('/index.html', '/');
if (href1 == href2) {
$(this).wrap('<strong/>');
}
});
});
}
*/
var flag = false;
var highlight = function(href1) {
href1 = normalizeUrl(href1);
$('#GLOBALNAV ul.menu a[href]').each(function() {
var href2 = this.href;
href2 = normalizeUrl(href2);
if (href1 == href2) {
$(this).wrap('<strong/>');
flag = true;
}
});
}
highlight(location.href);
if (!flag) {
$('link[rel="up"]').each(function(){ highlight(this.href); });
}
});

