var gnav;

function init_gnav(elem)
{
	elem.css("opacity",0);
	elem.after("<div class='aft'></div>");
	gnav = elem;
}

$(document).ready(function()
{
	/* Extarnal links */
	$("a[rel$='external']").click(function(){ this.target = "_blank"; });

	/* Textarea resizer */
	$('textarea.resizable:not(.processed)').TextAreaResizer();
//	$('iframe.resizable:not(.processed)').TextAreaResizer();

	/* Set keyvisual */
	var imgsrc = $("div#footer div.decor div.keyvisual").css("background-image");
	var header = $("#header");
	header.prepend("<div class='decor'><div class='keyvisual'></div></div>");
	var keyvisual = $("div.decor div.keyvisual");
	$(keyvisual,header).css("background-image", imgsrc);
	$(keyvisual)
		.css("opacity", 0)
		.animate({ opacity: 1 }, 1000);

	/* Set effect -- Go to page-top */
	var gotop = $("#gotop a");
	effect_gotop(gotop, 32, 22, 200);

	/* Set effect -- Global navigation */
	$.timer(400, function (timer)
	{
		effect_gnav(gnav, 45, 15, 200, 1);
		timer.stop();
	});
});

function effect_gnav(elem, pad_out, pad_in, time, multiplier)
{
	var timer = time;
	$("li a",elem).each(function(i)
	{
		timer = (timer*multiplier + time);
		$(this)
			.css("padding-right",pad_out)
			.animate({ paddingRight: pad_in }, timer)
			.hover(function()
			{
				$(this).stop().animate({ paddingRight: pad_out }, time);
			},
			function()
			{
				$(this).animate({ paddingRight: pad_in }, time*2);
			});
			$(this).click(function()
			{
				$(this).stop().animate({ paddingRight: pad_out }, time);
			});
	});
	elem.animate({ opacity: 1 }, 600);
}

function effect_gotop(elem, height_over, height_out, time)
{
	elem
		.click(function ()
		{
			$('html,body').animate({ scrollTop: 0 }, 'fast');
			this.blur();
			return false;
		})
		.each(function(i)
		{
			$(this)
				.wrapInner("<span class='str'></span>")
				.append('<span class="arw" />');
			var arw = $("span.arw",this);
			var str = $("span.str",this);
			str.css({ opacity: "0" });
			$(this).hover(function()
			{
				arw.animate({ height: height_over }, time);
				str.animate({ opacity: "1" }, time);
			},
			function()
			{
				str.animate({ opacity: "0" }, time);
				arw.animate({ height: height_out }, time);
			});
		});
}
