// *************************************************
// ページの読み込み時に起動
// *************************************************

Event.observe( window, 'load', function(){
	setFaqToggle('news_box');
});



// *************************************************
// 汎用関数
// *************************************************


// eventSetter
var isIE = isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);

function eventSetter(obj,eventType,func){
	if(isIE) {
		obj.setAttribute(eventType,new Function(func));
	} else {
		obj.setAttribute(eventType,func);
	}
}


// open new window
function newWindow(uri,width,height){
	var myWindow = window.open(uri, 'newWindow', 'resizable=yes,scrollbars=yes,status=0,width='+width+',height='+height);
	if (myWindow.focus!=null) {
		myWindow.focus();
	}
}


// print window
function printWindow(){
	if(document.getElementById || document.layers){
		window.print();
	}
}


// Ajax recover UTF-8 (for Safari)
function recover_utf8(text){
	if(navigator.appVersion.indexOf('KHTML') > -1){
		var esc = escape(text);
		if(esc.indexOf('%u') < 0 && esc.indexOf('%') > -1){
			text = decodeURIComponent(esc);
		}
	}
	return text;
}


// input clear
function inputClear(id,txt){
	if ($(id).value == txt) $(id).value = '';
}

// scroll to top
function scrollToTop() {
	new Effect.ScrollTo("top",{duration: 0.5});
}



/*トグル*/

var NewsToggle = Class.create();
NewsToggle.prototype = {
	initialize: function(wrapper,id){
		this.qitem = wrapper.getElementsByClassName('label')[0];
		this.aitem = wrapper.getElementsByClassName('desc')[0];
		Event.observe(
			this.qitem,
			'click',
			this.click.bindAsEventListener(this)
		);
		Element.setStyle(this.qitem, {'cursor':'pointer', 'text-decoration':'underline','color':'#0066FF'});
		Element.hide(this.aitem);
	},
	click: function(){
		if(this.aitem.style.display == 'none'){
			new Effect.BlindDown(this.aitem, {duration: 0.3});
		} else {
			new Effect.BlindUp(this.aitem, {duration: 0.3});
		}
	}
}

function setFaqToggle(wrapperID){
	if($(wrapperID)){
		var wrapper = $(wrapperID);
		var lists = wrapper.getElementsByTagName("dd");
		for(var i = 0,num = lists.length;i < num;i++){
			list = lists[i];
			list.id = 'list' + i;
			new NewsToggle(wrapper,list.id);
		}
	}
}
