var yokoteUi = {
	href: location.href,
	query: location.search,
	toggleMenu: function(target){
		$(target).bind("click",function(){
			$(this).parent().find("ul").slideToggle("fast");
			return false;
		})
	},
	LetterSizing: function(){
		this.cookieName = "letterSize";
		this.current = ($.cookie(this.cookieName) == null) ? 0 : $.cookie(this.cookieName);
		this.max = 5;
		this.step = 10;
		this.target = $("body");
		this.normalSwitch = $("#lsNormal");
		this.biggerSwitch = $("#lsBigger");
		this.setSize = function() {
			var s = 100 + this.current * this.step + "%";
			this.target.css("font-size",s);
			$.cookie(this.cookieName,this.current,{expires:60,path:'/'});
		};
		this.change = function(event) {
			var lso = event.data.obj;
			var lsa = event.data.act;
			if(lsa == 0) lso.current = 0;
			else if(lso.current < lso.max) lso.current++;
			else {
				alert("これ以上大きくすることはできません");
				return false;
			}
			lso.setSize();
		}
		
		this.setSize();
		this.normalSwitch.bind("click",{obj:this,act:0},this.change);
		this.biggerSwitch.bind("click",{obj:this,act:1},this.change);
	},
	InvertColor: function(){
		this.cookieName = "invertColor";
		this.current = ($.cookie(this.cookieName) == null) ? 0 : $.cookie(this.cookieName);
		this.normalSwitch = $("#dcNormal");
		this.invertSwitch = $("#dcInvert");
		this.invertLinkId = 'invert';
		this.invert = function() {
			$("#invert").removeAttr('disabled');
			this.current = 1;
			$.cookie(this.cookieName,this.current,{expires:60,path:'/'});
		};
		this.normal = function() {
			$("#invert").attr('disabled','disabled');
			this.current = 0;
			$.cookie(this.cookieName,this.current,{expires:60,path:'/'});
		};
		this.change = function(event) {
			var dco = event.data.obj;
			var dca = event.data.act;
			if(dca == 0) dco.normal();
			else if(dca == 1) dco.invert();
		}
		
		if(this.current == 1) this.invert();
		this.normalSwitch.bind("click",{obj:this,act:0},this.change);
		this.invertSwitch.bind("click",{obj:this,act:1},this.change);
	},
	tabSwitcher: function(target){
		$(target).find("a#news").bind("click",function(){
			tgtid = $(this).attr("href");
			$(tgtid).show().siblings().hide();
			$("img",this).attr("src","/files/000010900.jpg");
			$("img","a#topics").attr("src","/files/000000142.jpg");
			return false;
		}).end().find("a#topics").bind("click",function(){
			tgtid = $(this).attr("href");
			$(tgtid).show().siblings().hide();
			$("img",this).attr("src","/files/000010901.jpg");
			$("img","a#news").attr("src","/files/000000133.jpg");
			return false;
		});
	},
	printView: function(target){
		$(target).bind("click",function(){
			var query = (location.search=="") ? "?print" : "&print";
			window.open(location.href + query,"printView","width=765,height=765,location=yes,status=yes,menubar=yes,scrollbars=yes")
		});
	},
	fixCaptionWidth: function(target){
		$("div.sectionImage.left,div.sectionImage.right").each(function(){
			var img = $("img",this);
			if(img.length == 0) return;
			var largest = 0;
			for(var i=0;i<img.length;i++) {
				if(img[i].width > largest) largest = img[i].width
			}
			$(this).width(largest);
		})
	},
	languageSelect: function(){
		$("#languages").hover(function(){
			$("#languageSelect").show()
		},function(){
			$("#languageSelect").hide()
		});
		$("#languageSelect a").click(function(){
			if(location.href.match(/(.+?)#.*/)) location.href = RegExp.$1 + $(this).attr("href");
			location.href = location.href + $(this).attr("href");
			location.reload();
		});
	}

};


jQuery(function($){
	ls = new yokoteUi.LetterSizing();
	dc = new yokoteUi.InvertColor();
	yokoteUi.languageSelect();
	cont = $("#contents");
	if(cont.hasClass('contents') || cont.hasClass('faqContents') || cont.hasClass('eventContents') || cont.hasClass('movieContents')) window.onload = yokoteUi.fixCaptionWidth;
	if(document.getElementById('printBtn')) yokoteUi.printView("a#printBtn");
	if(document.getElementById('newsAndTopics')) yokoteUi.tabSwitcher("#newsAndTopics");
	if(document.getElementById('navigation')) {
		if($("body").hasClass('faq')) yokoteUi.toggleMenu('a.slideSwitch');
		else yokoteUi.toggleMenu('a#thirdCatLink');
	}
})

