﻿/*------------------------------------------------------------------------------------
 * CookieTab JavaScript (jQuery version)
 *
 * Creative Commons License - Attribution
 * http://www.skyld.net (2009.8.29)
 *------------------------------------------------------------------------------------
	
------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------

変数設定(CookieTabモジュールを使用)

------------------------------------------------------------------------------------*/
var CookieTab = {
	cookieName: 'select', //cookieに書き込むプロパティ名
	cookieExpires: 10, //cookieの有効期限（単位：日）
	tabHeadId: 'tabs-nav', //タブheadのID名
	tabBodyId: 'tabbody', //タブbodyのID名
	tabHdPrefix: 'head-', //タブheadリストのID接頭語
	tabBdPrefix: 'body-', //タブbodyリストのID接頭語
	tabAnPrefix: 'anchor-'	 //タブheadアンカーのID接頭語
};


/*------------------------------------------------------------------------------------

タブ＋クッキーのメイン処理

------------------------------------------------------------------------------------*/

//DOM読込完了後、tab制御開始
$(document).ready(function(){
	CookieTab.setting();
});

//tabの初期制御
CookieTab.setting = function() {	
	this.tabValue = $.cookie(this.cookieName);
	if(!this.tabValue || this.tabValue==undefined){
		this.tabValue = 'tab0';
	}
	this.tabControl();
}

//tabの初期設定
CookieTab.tabControl = function() {
	this.tabDisplay();
	$('#' + this.tabHeadId + ' li a').each(function(value){
		$(this).click(function(){//tabクリック時の動作設定
			value+='';//数値型→文字列型変換
			$.cookie(CookieTab.cookieName, 'tab' + value, { expires: CookieTab.cookieExpires });  
			CookieTab.tabValue = $.cookie(CookieTab.cookieName);
			CookieTab.tabDisplay();
			return false;
		});
	});
}

//tabの表示制御
CookieTab.tabDisplay = function() {
	$('#' + this.tabHeadId + ' li').each(function(){
		$(this).removeClass('on');
	});
	$('#' + this.tabBodyId + ' div').each(function(){
		$(this).removeClass('current');
	});
	$('#' + this.tabHdPrefix + CookieTab.tabValue).addClass('on');
	$('#' + this.tabBdPrefix + CookieTab.tabValue).addClass('current');
}
