/*
 * common.js
 * depends jquery.js (v1.3.2);
 * 
 */


// セレクタ拡張
$.extend($.expr[':'], {

	// 外部リンク
	external: function(a,i,m) {
		if (!a.href) {
			return false;
		}
		return a.hostname && a.hostname !== window.location.hostname;
	}
	
});

// メソッド拡張
$.fn.extend({

	// 新規ウィンドウを開く
	openWindow: function() {
		$(this).click(function() {
			window.open(this.href);
			return false;
		});
	}
	
});


// グローバルナビアクティブ処理[プラグイン]
$.fn.globalPath = function(options) {
	var o = $.extend({
		root: '/',
		ignoreFiles: '/index\.html|index\.htm|index\.shtml|index\.php|index\.cgi/i'
	}, options);
	$(this).each(function() {
		if (this.hostname != location.hostname) {return this;}
		this.path = this.pathname.replace(o.ignoreFiles, '');
		if (!this.path.match(/^\//)) {
			this.path = '/' + this.path;
		}
		if (this.path == o.root) {
			if (this.path == location.pathname.replace(o.ignoreFiles, '')) {
				$(this).find('img').addClass('active').swapImg();
				$(this).addClass('active');
			}
		}
		else if (location.pathname.search(this.path) == 0) {
			$(this).find('img').addClass('active').swapImg();
			$(this).addClass('active');
		}
	});
	return this;
};


// ローカルナビアクティブ処理[プラグイン]
$.fn.path = function() {
	$(this).each(function() {
		if (this.href == window.location.href) {
			$(this).addClass('active');
		}
	});
	return this;
};


$.fn.swapImg = function(options) {
	var o = $.extend({
		swapImgPostfix: '_on'
	}, options);
	$(this).each(function() {
		this.swapImgSrc = $(this).attr('src').replace(/(\.gif|\.jpeg|\.jpg|\.png)/i, o.swapImgPostfix + '$1');
		$(this).attr('src', this.swapImgSrc);
	});
	return this;
};

$.fn.rollover = function(options) {
	var o = $.extend({
		swapImgPostfix: '_on'
	}, options);
	$(this).not('.active').each(function() {
		this.defaultSrc = $(this).attr('src');
		this.hoverSrc = this.defaultSrc.replace(/(\.gif|\.jpeg|\.jpg|\.png)/i, o.swapImgPostfix + '$1');
		this.hoverImg = new Image;
		this.hoverImg.src = this.hoverSrc;
	}).hover(function() {
		$(this).attr('src', this.hoverSrc);
	}, function() {
		$(this).attr('src', this.defaultSrc);
	});
	return this;
};


// タブ切り替え[プラグイン]
$.fn.tabs = function(initial) {
	$(this).each(function() {
		$(this).find('.tab-naviOn').removeClass('tab-naviOn');
		var tabsBody = $(this).children('div');
		var tabsNav = $(this).children('ul');
		var tabsNavInitial = initial? 'nth-child(' + initial + ')': 'first';
		var tabsNavSelected = $(tabsNav).children('li:' + tabsNavInitial);
		var tabsNavLink = $(tabsNav).find('[href^="#"]');
		$(tabsBody).addClass('tabs-body').hide();
		$(tabsNav).addClass('tabs-nav');
		$(tabsNavSelected).addClass('tab-naviOn').each(function() {
			$($(this).find('[href^="#"]').attr('href')).show();
		});
		
		$(tabsNavLink).click(function() {
			$(tabsBody).hide();
			$(tabsNav).find('.tab-naviOn').removeClass('tab-naviOn');
			$(this).parent('li').addClass('tab-naviOn');
			$($(this).attr('href')).show();
			return false;
		});
	});
};


//IE6用 position調整
$(window).resize(function(){
    $('#ProductNavi').attr("style", "margin-top:20px");
});



$(function() {

	// JavaScript 有効判定
	$('body').addClass('js-enabled');
	
	// ブラウザ判別
	var browserName;
	var browserVer;
	if ($.browser.msie) {
		browserName = 'msie';
		switch ($.browser.version) {
			case '6.0': browserVer = 'v6'; break;
			case '7.0': browserVer = 'v7'; break;
			case '8.0': browserVer = 'v8'; break;
			default: browserVer = 'v5';
		}
		
		$('body').addClass(browserVer);
	} else if ($.browser.mozilla) {
		browserName = 'mozilla';
	} else if ($.browser.safari) {
		browserName = 'safari';
	} else if ($.browser.opera) {
		browserName = 'opera';
	} else {
		browserName = 'unknown';
	}
	$('body').addClass(browserName);

	// リンク
	$('a:external:not(a[href^="javascript:"]):not(a[href^="https:"])').openWindow();
	$('area:external:not(area[href^="javascript:"]):not(a[href^="https:"])').openWindow();
	$('a.external').openWindow();
	$('a[href$=".pdf"]').addClass('pdf').openWindow();
	$('a[href$=".zip"]').addClass('zip');
	$('a[href$=".exe"]').addClass('exe');
	$('a[href^="https:"]').addClass('https');
	$('a[href^="ftp:"]').addClass('ftp');
	$('a[href^="mailto:"]').addClass('mailto');

	// グローバルナビのアクティブ処理
	$('#GlobalNavi a').globalPath();

	// プロダクトサイトナビのアクティブ処理
	$('#ProductNavi a').globalPath();

	// プロダクトサイトサブナビのアクティブ処理
	$('#ProductSubNaviArea a').globalPath();
	
	// ローカルナビのアクティブ処理
	$('#LocalNavi a:not([href*="#"])').path();

	//ロールオーバー
	$('.over').rollover();

	//文字サイズ
	$('#Switcher a').click(function() {
		switchStyle($(this).attr('title'));
		return false;
	});
	var c = $.cookie('style');
	if (c) switchStyle(c);
	function switchStyle(styleName) {
		$('link[rel*="stylesheet"][title]').each(function() {
			this.disabled = true;
			if ($(this).attr('title') == styleName) this.disabled = false;
		});
		// 選択した設定をクッキーに保存します
		$.cookie('style', styleName, {
			expires: 30,  // 有効日数
			path: '/'     // 有効ディレクトリ
		});
	}

	// タブ切り替え
	$('#tabChange').tabs();

});



//開閉モジュール
function showHideAnswer()
{
	var numID      = this.id.replace(/[^\d]/g,'');
	var obj        = document.getElementById('ShowDtl' + numID);
	var icon_plus  = document.getElementById('ShowIcoDwn' + numID);
	var icon_minus = document.getElementById('ShowIcoUp' + numID);
	
	if(obj.style.display=='block',icon_plus.style.display=='none',icon_minus.style.display=='inline'){
		obj.style.display='none';
		icon_plus.style.display='inline';
		icon_minus.style.display='none';
	}else{
		obj.style.display='block';
		icon_plus.style.display='none';
		icon_minus.style.display='inline';
	}
	//alert(obj_icon);
}
function initShowHideContent()
{
	var divs = document.getElementsByTagName('DIV');
	
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='showHide'){
			divs[no].onclick = showHideAnswer;
		}
	
	}
}
window.onload = initShowHideContent;



//プロダクトナビプルダウン
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Konstantin Jagello | http://javascript-array.com/ */

var TimeOut         = 1000;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

function mopen(n) {
	var l  = document.getElementById("menu"+n);
	var mm = document.getElementById("mmenu"+n);

  if(l) {
		mcancelclosetime();
		l.style.visibility='visible';
		if(currentLayer && (currentLayerNum != n))
		currentLayer.style.visibility='hidden';
		currentLayer = l;
		currentitem = mm;
		currentLayerNum = n;
	} else if(currentLayer) {
		currentLayer.style.visibility='hidden';
		currentLayerNum = 0;
		currentitem = null;
		currentLayer = null;
	}
}

function mclosetime() {
	closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
	if(closeTimer) {
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}

function mclose() {
	if(currentLayer && noClose!=1)   {
		currentLayer.style.visibility='hidden';
		currentLayerNum = 0;
		currentLayer = null;
		currentitem = null;
	} else {
		noClose = 0;
	}
	currentLayer = null;
	currentitem = null;
}

document.onclick = mclose;



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};




/*
 * Pulldown
 */

/* ---------------------------------
 static variable  : SP_XxxXxx
 global variable  : gLg_xxxxxx
--------------------------------- */

var aaa = 'test';

var SP_PullList = 'SpPullList'; /* プルダウンのID名 */
var SP_PullBtn = 'SpPullBtn';   /* プルダウン表示ボタンのID名 */
var gLg_flg = false;            /* プルダウンの開閉フラグ(初期値) */
var gLg_flg_close = false;      /* プルダウンのオンマウスフラグ(初期値)*/
var SP_PullHref;                /* リンク先 */

$(function(){

	/* プルダウンがクリックされたとき */
	$("#" + SP_PullBtn).click(
		function(){ var gLg_flg_close = false; spSrcPullDown(); return false; } //プルダウンを表示する
	);
	
	$(".pl-item").hover(
		function(){ gLg_flg_close = true; },
		function(){ gLg_flg_close = false; }
	);
	
	$(".pl-item").click(
		function(){
			var SP_PullHref = this.href;
			spSrcPullDown();
			location.href = SP_PullHref;
			return false;
		}
	);
	
	/* 画面のどこかクリックされたとき */
	$("body").click(
		function(){
			if((gLg_flg == true)&&(gLg_flg_close == false)){
				spSrcPullDown();
			}
		}
	);
});


/* ====================================================================
 Name        : spSrcPullDown()
 Description : 選択プルダウン
 Parameter   : なし
 Return      : なし
==================================================================== */
function spSrcPullDown(){

	/* プルダウンが閉じていればtrue、開いていればfalseを代入 */
	gLg_flg = (!gLg_flg) ? true : false;
	gLg_flg_close = false;

	/* プルダウンを表示 */
	if (gLg_flg) {
		$("#" + SP_PullList).css({ display : 'block' });
		
	/* プルダウン非表示 */
	} else {
		$("#" + SP_PullList).css({ display : 'none' });
	}
}



