/*
 * Timer Script
 */


var Timer = 
{
	now : function(){
		var d = new Date();
		return d * 1 / 1000;
	},
	val : 0,
	starttime : 0,
	timerid  : false, //  current timer id
	elm : null,
	clear_timer : function()
		{
			if (this.timerid){
				clearTimeout(this.timerid);
				this.timerid = false;
			}
			this.starttime = 0;
		},
	set_opacity : function(val)
		{
			if (val < 0) val = 0;
			if (val > 100) val = 100;
			this.elm.style.filter="alpha(opacity=" + val + ")";
			this.elm.style.opacity= 0.0 + val / 100;
			this.elm.style.MozOpacity= 0.0 + val / 100;
		},
	start : function(idstr)
		{
			this.starttime = this.now();
			this.elm = document.getElementById(idstr);
			if (this.elm){
				this.elm.style.display = "block";
				this.set_opacity(100);
				this.timerid = setTimeout("Timer.run()", 15);
			}
		},
	run : function()
		{
			var current = (this.now() - this.starttime);
			if (current >= 1.6){
				// end
				this.set_opacity(0);
				this.elm.style.display = "none";
				this.clear_timer();
			}else{
				// scroll
				if (current >= 0.6){
					this.set_opacity(100 - parseInt( (current - 0.6) * 100));
				}
				this.timerid = setTimeout("Timer.run()", 15);
			}
		}
}

/*
 * Up Down Script
 */


var Rate =
{
	i : false,
	str : false,
	on : function(elm)
	{
		elm.parentNode.style.backgroundColor="#FFFFCC";
		var e = document.getElementById("rate");
		if (e){
			e.style.display = "block";
		}
		if (!this.str){
			this.str = document.createElement("span");
			this.str.appendChild(document.createTextNode("評価する"));
			elm.insertBefore(this.str, elm.firstChild);
		}
	},
	off : function(elm)
	{
		elm.parentNode.style.backgroundColor="";
		var e = document.getElementById("rate");
		if (e){
			e.style.display = "none";
		}
		if (this.str){
			elm.removeChild(this.str);
			this.str = false;
		}
	},
	ng : function(url, title, onurl, aid)
	{
		var r = confirm("「" + title + "」\nを [ あわせて読みたく ない ] サイトとして評価します。\n※評価は匿名で行われ評価内容は一切公開しません。");
		if (r){
			Timer.start("ratefin");
			this.send(url, onurl, "1");
			var e1 = document.getElementById("g" + aid);
			var e2 = document.getElementById("n" + aid);
/*
			if (e1 && e2){
				e1.style.display="inline";
				e2.style.display="none";
			}
*/
		}
	},
	ok : function(url, title, onurl, aid)
	{
		var r = confirm("「" + title + "」\nを [ あわせて読みたい ] サイトとして評価します。\n※評価は匿名で行われます。");
		if (r){
			Timer.start("ratefin");
			this.send(url, onurl, "0");
			var e1 = document.getElementById("g" + aid);
			var e2 = document.getElementById("n" + aid);
/*
			if (e1 && e2){
				e1.style.display="none";
				e2.style.display="inline";
			}
*/
		}
	},
	send : function(url, onurl, flag)
	{
		this.i = new Image();
		this.i.src = "rate.phtml?u=" + encodeURIComponent(url) + "&s=" + encodeURIComponent(onurl) + "&f=" + flag;
	}
}



