
(function($){

	"use strict";

	$(document).ready(function(){

		/* Set rollover. */
		$('img.over, input.over').rollover();

		/* Activate current page. */
		$('img.current').each(function(){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_on$2');
		});

		/* Nav effects. */
		$('#gnav > ul a > img:not(.current), #aside > div.nav a > img:not(.current)').hover(
			function(){
				$(this).stop().animate({
					opacity: 0.01
				}, 150);
			},
			function(){
				$(this).stop().animate({
					opacity: 1
				}, 200);
			}
		);

		/* External link handler. */
		$('a')
			.filter(function(){
				var re = new RegExp("^http(?:s?):\/\/(?!"+ location.host +")|\.pdf$");
				return re.test(this.href);
			})
			.click(function(){
				window.open(this.href, '_blank');
				return false;
			})
			/* Add icon with link type. */
			/*.each(function(){
				var href;

				if ($(this).find('img').length > 0) {
					return;
				}

				href = this.href.toLowerCase();
				if (/\.pdf$/.test(href)) {
					$(this).after('<img src="/common/icon_pdf.png" class="icon" />');
				}
				else if (/^http/.test(href)) {
					$(this).after('<img src="/common/icon_blank_02.png" class="icon" />');
				}
			})*/
		;

		/* Font size scaler. */
		(function(){
			/* Const values. */
			var FONT_SIZE_DEFAULT = 10,	// in pixel.
				FONT_SIZE_MIN = 8,	// in pixel.
				FONT_SIZE_MAX = 24,	// in pixel.
				FONT_SIZE_STEP = 2,	// in pixel.
				COOKIE_NAME = 'font_size_cookie',
				COOKIE_EXPIRES = 14	// per day.
			;

			/* Initialize font size. */
			var fontSize = parseInt($.cookie(COOKIE_NAME), 10) || FONT_SIZE_DEFAULT;
			setFontSize(fontSize);
			
			/* Set font size scaler handler. */
			$('#header div.font_size')
				/* Reset. */
				.find('p')
					.dblclick(function(){
						fontSize = FONT_SIZE_DEFAULT;
						setFontSize(fontSize);
						saveFontSize(fontSize);
					})
				.end()
				/* Larger. */
				.find('a[rel="larger"]')
					.click(function(){
						fontSize += FONT_SIZE_STEP;
						setFontSize(fontSize);
						saveFontSize(fontSize);
						return false;
					})
				.end()
				/* Smaller. */
				.find('a[rel="smaller"]')
					.click(function(){
						fontSize -= FONT_SIZE_STEP;
						setFontSize(fontSize);
						saveFontSize(fontSize);
						return false;
					})
				.end()
			;
			
			/**
			 * Save font size to cookie.
			 * @param {Number} Font size value.
			 */
			function saveFontSize(fontSize) {
				$.cookie(COOKIE_NAME, fontSize, {
					expires: COOKIE_EXPIRES,
					path: '/'
				});
			}
			
			/**
			 * Set font size.
			 * @param {Number} Font size value.
			 */
			function setFontSize(fontSize) {
				var size = fontSize;
				if (size < FONT_SIZE_MIN) {
					size = FONT_SIZE_MIN;
				}
				if (size > FONT_SIZE_MAX) {
					size = FONT_SIZE_MAX;
				}
				$('body').animate({
					fontSize: size
				}, 200);
			}

			
		}());

	});

}(jQuery));



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(d,c,a){if(typeof c!="undefined"){a=a||{};if(c===null)c="",a.expires=-1;var b="";if(a.expires&&(typeof a.expires=="number"||a.expires.toUTCString))typeof a.expires=="number"?(b=new Date,b.setTime(b.getTime()+a.expires*864E5)):b=a.expires,b="; expires="+b.toUTCString();var e=a.path?"; path="+a.path:"",f=a.domain?"; domain="+a.domain:"",a=a.secure?"; secure":"";document.cookie=[d,"=",encodeURIComponent(c),b,e,f,a].join("")}else{c=null;if(document.cookie&&document.cookie!=""){a= document.cookie.split(";");for(b=0;b<a.length;b++)if(e=jQuery.trim(a[b]),e.substring(0,d.length+1)==d+"="){c=decodeURIComponent(e.substring(d.length+1));break}}return c}};



/*
 * jQuery tiny rollover plugin.
 *
 * @param {Object} Several options.
 * @return {Object} jQuery object.
 */
(function(a){a.fn.rollover=function(c){var d="$1"+a.extend({suffix:"_on"},c).suffix+"$2";return a(this).each(function(){var b=new Image;b.src=this.src.replace(/^(.+)(\.[a-z]+)$/,d);a(this).data("rolloverImage",{defaultImage:this.src,hoverImage:b.src}).hover(function(){this.src=a(this).data("rolloverImage").hoverImage},function(){this.src=a(this).data("rolloverImage").defaultImage})})}})(jQuery);



