/**
 * www.talesweb.com JavaScript
 * talesweb.js 
 */ 
Talesweb = {};

Talesweb.timer = {
	timer_func: function () {}, interval: null,
	start: function (func, time) {
		var _my = this;
		this.timer_func = function () {
			func();
			_my.stop();
		}
		
		this.inerval = setInterval(this.timer_func, time);
	},
	startObj: function (obj, funcname, time) {
		var _my = this;
		this.timer_func = function () {
			obj[funcname]();
			_my.stop();
		}
		
		this.inerval = setInterval(this.timer_func, time);
	},
	stop: function () {
		clearInterval(this.inerval);
	}
};

Talesweb.info = {
	swap: function (id) {
		if ($('info_' + id).visible()) {
			$('info_b_' + id).innerHTML = '[+]'; $('info_' + id).hide();
		} else {
			$('info_b_' + id).innerHTML = '[-]'; $('info_' + id).show();
		}
	}
}

Talesweb.kdedit = {
	onLoadinitLink: function () {
		var _my = this;
		$A(document.getElementsByTagName('a')).each(function (o) {
			if (!o.target) o.onclick = function () {return _my.confirm();};
		});
	},
	confirm: function () {
		return window.confirm('このページから移動します。保存していないデータは消えますがよろしいですか？');
	}
}

Talesweb.bannerchanger = {
	idx: 0, time: 1000*30, type: 'turn', id: 'HdBanner', classname: 'HdBanners',
	getInitElem : function () {
		var bs = document.getElementsByClassName(this.classname, this.id);
		for (var i in bs) if (bs[i].style) bs[i].style.display = 'none';
		return bs;
	},
	turn: function () {
		var bs = this.getInitElem();
		bs[this.idx].style.display = '';
		this.idx = (++this.idx>=bs.length) ? 0 : this.idx;
	},
	rand: function () {
		var bs = this.getInitElem();
		bs[Math.floor(Math.random()*bs.length)].style.display = '';
	},
	active: function (_time, _type) {
		this.time = (_time) ? _time : this.time;
		this.type = (this[_type]) ? _type : this.type;
		this.loop();
	},
	loop: function () {
		this[this.type]();
		timer.startObj(this, 'loop', this.time);
	}
}

Talesweb.search = {
	submit: function () {
		var _f = $('formKaodraSearch');
		_f.submit();
	},
	submitTag: function () {
		var _f = $('formKaodraSearchTag');
		var _fe = $('formKaodraSearchTagSel');
		_f.action = _f.action + _fe.value;
		_f.submit();
	},
	name : 'search'
}
