//font-change
$(function(){

//フォントサイズ設定
	var FontSize = [];
	FontSize["S"] = '1.2';
	FontSize["M"] = '1.4';
	FontSize["L"] = '1.6';

//フォントサイズ変更ボタン設定
	var ChangeBtn = "#fontSize img";
	var SearchImg = ["#fontS img","#fontM img","#fontL img"];

//フォントサイズ変更関数
	function FontSizeSet(fs){
		$('#main p').css("font-size",fs+"em");
		$('#main pre').css("font-size",fs+"em");
		$('#main dt').css("font-size",fs+"em");
		$('#main dd').css("font-size",fs+"em");
		$('#main address').css("font-size",fs+"em");
		$('#main li').css("font-size",fs+"em");
		$('#main td').css("font-size",fs+"em");
		$('#main th').css("font-size",fs+"em");
	};

//画像置換関数
	function OnFont(){
		$(this).attr("src",$(this).attr("src"));
	};
	function OvFont(io){
		$(io).attr("src",$(io).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));
	};
	function OffFont(io){
		$(io).attr("src",$(io).attr("src").replace(/^(.+)_ov(\.[a-z]+)$/,"$1$2"));
	};

//クッキー設定関数
	function FontCookie(ck){
		$.cookie("fontsize",ck,{path:'/',expires:7});
	};

//クッキー確認関数
	function CookieChack(fs){
		return $.cookie("fontsize")==fs;
	};

//ロード時表示設定
	function LoadFont(fs,si){
		FontSizeSet(FontSize[fs]);
		OvFont(SearchImg[si]);
	};
	if(CookieChack("fontS")){
		LoadFont("S",0);
	}
	else if(CookieChack("fontM")){
		LoadFont("M",1);
	}
	else if(CookieChack("fontL")){
		LoadFont("L",2);
	}
	else {
		FontCookie("fontM");
		LoadFont("M",1);
	};

//画像プリロード設定
	function ImgPreload(io){
		$(ChangeBtn).not(SearchImg[io]).each(function(){
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_ov$2"));
		});
	};
	if(CookieChack("fontS")){
		ImgPreload(0);
	}
	else if(CookieChack("fontM")){
		ImgPreload(1);
	}
	else if(CookieChack("fontL")){
		ImgPreload(2);
	};

//ホバーイベント
	$(ChangeBtn)
	.hover(
	function(){
		if(!$(this).attr("src").match("_ov")){
			OvFont(this);
		};
	},
	function(){
		if($(this).attr("src").match("_ov")){
			if(CookieChack("fontS")){
				OffFont(SearchImg[1]),OffFont(SearchImg[2]);
			}
			else if(CookieChack("fontM")){
				OffFont(SearchImg[0]),OffFont(SearchImg[2]);
			}
			else if(CookieChack("fontL")){
				OffFont(SearchImg[0]),OffFont(SearchImg[1]);
			};
		};
	});

//クリックイベント
	function ClickFont(ck,fs,io1,io2){
		FontCookie(ck);
		FontSizeSet(FontSize[fs]);
		OffFont(SearchImg[io1]),OffFont(SearchImg[io2]);
		OnFont();
	};
	$(SearchImg[0]).click(function(){
		ClickFont("fontS","S",1,2);
	});
	$(SearchImg[1]).click(function(){
		ClickFont("fontM","M",0,2);
	});
	$(SearchImg[2]).click(function(){
		ClickFont("fontL","L",0,1);
	});
});


// ROLLOVER

$(function(){
    $("img.rollover").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
    }).each(function(){
        $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
    });
});

// TAB
$(document).ready(function(){
$('#news-container div').hide();
$('#news-container div:first').show();
$('#news-tab li:first').addClass('active');
$('#news-tab li a').click(function(){ 
$('#news-tab li').removeClass('active');
$(this).parent().addClass('active'); 
var currentTab = $(this).attr('href'); 
$('#news-container div').hide();
$(currentTab).show();

return false;
});
});

// TAB
$(document).ready(function(){
$('#event-container div').hide();
$('#event-container div:first').show();
$('#event-tab li:first').addClass('active');
$('#event-tab li a').click(function(){ 
$('#event-tab li').removeClass('active');
$(this).parent().addClass('active'); 
var currentTab = $(this).attr('href'); 
$('#event-container div').hide();
$(currentTab).show();

return false;
});
});

// DropDown
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#global-navigation > li').bind('mouseover', jsddm_open);
	$('#global-navigation > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;
