/*==============================================
 easily RollOver
==============================================*/
$.fn.imageRollOver = function(){
	var obj = obj || {};
	$(this).each(function(){
		var src  = this.src;
		var osrc = src.replace("_off.","_on.");
		obj[src] = new Image();
		obj[src+"_d"] = new Image();
		obj[src].src = osrc;
		obj[src+"_d"].src = src;
		$(this).hover(function(){
			if($(this).attr('src').indexOf('_current.') != -1) return false; 
			this.src = obj[src].src;
		},function(){
			if($(this).attr('src').indexOf('_current.') != -1) return false; 		
			this.src = obj[src+"_d"].src;
		})
	})
}

/*==============================================
tab切り替え
==============================================*/
$.fn.tabToggle = function(opt){
	if($(this).length == 0) return false;
	var opt = $.extend({
		trigger  : 'ul.tab-list a',
		target   : 'div.showContent',
		current  : 'current'
	}, opt);
	var base  = $(this),
	    tabs  = $(opt.trigger, base),
	    targ  = $(opt.target,  base),
	    targs = targ.children('div');
	targs.not(':first').hide();
	tabs.live('click',function(){
		currentChange(tabs,$(this));
		var showSection = $(this).attr('href');
		targs.hide();
		$(showSection).show();
		return false;
	});
}

function currentChange(t,wo){
	$('img',t).each(function(){
		var osrc = $(this).attr('src').replace('_current.','_off.');
		$(this).attr('src',osrc);
	});
	$('img',wo).each(function(){
		var csrc = $(this).attr('src').replace('_off.','_current.').replace('_on.','_current.');
		$(this).attr('src',csrc);
	});
}




/*==============================================
 IE bgfix
==============================================*/
try{document.execCommand("BackgroundImageCache", false, true);} catch(e){}



/*==============================================
文字サイズ変更
==============================================*/


function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
	$('#fontsize>ul').attr('class','current-'+title);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return "middle";
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return "middle";
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

