
(function($){

	"use strict";

	$(document).ready(function(){

		/* Setup rollover. */
		$('img.over, input.over').rollover();

		/* Activate current page. */
		$('img.on').each(function(){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_on$2');
		});

		/* Open link as '_blank'. */
		$('a[rel=external], area.external, a[href$=".pdf"]').click(function(){					
			window.open(this.href, '_blank');
			return false;
		});

		setupHeader();
		setupMain();
		setupAside();

		/**
		 * Setup header.
		 */
		function setupHeader() {
			/* Set font scaler. */
			if ($.isFunction($.fn.fontscale)) {
				$('#tools > div.font_scale')
					.find('a')
						.filter('[rel=larger]')
							.fontscale('#content', '+', {
								threshold: 3
							})
						.end()
						.filter('[rel=smaller]')
							.fontscale('#content', '-', {
								threshold: 3
							})
						.end()
					.end()
					.children('p')
						.fontscale('#content', 'reset', {
							event: 'dblclick'
						})
					.end()
				;
			}

		}

		/**
		 * Setup main contents.
		 */
		function setupMain() {
			/* Set print button. */
			$('#main a.print').click(function(){
				window.open(location.href, 'printWindow');
				return false;
			});
			/* Reset for Print window. */
			if (window.name === 'printWindow') {
				appendCssFile('/css/print_window.css');
				if ($('#aside').children().length === 0) {
					$('#container').width(960);
				}
			}
		}

		/**
		 * Setup aside contents.
		 */
		function setupAside() {
			setRoundedNav();

			/* Load service aside. */
			$('#service_nav').load('/service/sidebar.html', function(){
				/* Highlight current category nav. */
				var postId = $('#main').data('post-id');
				$('#aside div.nav a')
					/* Highlight. */
					.filter(function(){
						return $(this).data('post-id') === postId;
					})
						.addClass('on')
					.end()
					/* Image rollover. */
					.children('img')
						.rollover()
					.end()
				;
				setRoundedNav();
			});

			/**
			 * Add rounded corner to aside nav.
			 */
			function setRoundedNav() {
				$('#aside div.nav').each(function(){
					$(this)
						.css('position', 'relative')
						.append('<span class="corner_right">&nbsp;</span>')
						.append('<span class="corner_left">&nbsp;</span>')
					;
				});
			}
		}

		/**
		 * Append CSS file.
		 * @param {String} CSS URL.
		 */
		function appendCssFile(url) {
			var file = document.createElement('link');
			file.rel = 'stylesheet';
			file.type = 'text/css';
			file.href = url;
			document.getElementsByTagName('head')[0].appendChild(file);
		}
	});

}(jQuery));



/**
 * jQuery tiny rollover plugin.
 */
(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);



/**
 * 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)){if(typeof a.expires=="number"){b=new Date;b.setTime(b.getTime()+a.expires*24*60*60*1E3)}else 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++){e=jQuery.trim(a[b]);if(e.substring(0,d.length+1)==d+"="){c=decodeURIComponent(e.substring(d.length+1));break}}}return c}};



/**
 * jQuery fontscale - A plugin to alter the font size of DOM elements 
 * Copyright (c) 2010 Ben Byrne - ben(at)fireflypartners(dot)com | http://www.fireflypartners.com
 * Dual licensed under MIT and GPL.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Date: 07/21/2010
 * @author Ben Byrne
 * @author Toru Hamaguchi
 * @version 0.2.1
 *
 */
 (function(b){b.fn.fontscale=function(e,c,a){var d=b.extend(b.fn.fontscale.defaults,a);if(!b.isFunction(b.cookie))d.useCookie=!1;if(!d.cookieLoaded&&b.cookie(d.cookieName)&&d.useCookie){a=b.fn.fontscale.readcookie(d.cookieName);if(a.bounds)d.bounds=a.bounds;a.unit==d.unit&&!d.cookieLoaded&&b.fn.fontscale.scale(e,a.delta,d,!0)}return this.each(function(){b(this).bind(d.event,function(){b.fn.fontscale.scale(e,c,d,!1);if(b.isFunction(d.onAfter))d.onAfter(e,c,d)})})};b.fn.fontscale.reset=function(e,c){b(e).each(function(){b(this).css("font-size", "");c.adjustLeading&&b(this).css("line-height","")});c.useCookie&&b.fn.fontscale.savecookie("delete",c)};b.fn.fontscale.scale=function(e,c,a,d){var f=0,g=parseInt(a.bounds,10);if(c==="reset")a.bounds=0,b.fn.fontscale.reset(e,a);else{if(c==="+"||c==="up")f=a.increment,g+=1;else if(c==="-"||c==="down")f=a.increment*-1,g-=1;else if(d)f=parseFloat(c),a.cookieLoaded=!0;g>a.threshold?a.bounds=a.threshold:g<-1*a.threshold?a.bounds=-1*a.threshold:(a.bounds=g,a.unit==="percent"&&!d&&(f=1+f/100),b(e).each(function(){var c= parseInt(b(this).css("font-size"),10),d=parseInt(b(this).css("line-height"),10);a.unit==="percent"?(b(this).css("font-size",Math.round(c*f)),a.adjustLeading&&b(this).css("line-height",Math.round(d*f))):(b(this).css("font-size",c+f),a.adjustLeading&&b(this).css("line-height",d+f))}),a.useCookie&&!d&&b.fn.fontscale.savecookie(f,a))}};b.fn.fontscale.savecookie=function(e,c){if(e=="delete")b.cookie(c.cookieName,null,c.cookieParams);else{var a;a=b.cookie(c.cookieName)?b.fn.fontscale.readcookie(c.cookieName): {delta:0,unit:c.unit,bounds:c.bounds};if(c.unit===a.unit)a.delta=c.unit=="percent"?e?a.delta*e:1:parseInt(a.delta,10)+e,a.bounds=c.bounds;b.cookie(c.cookieName,b.param(a),c.cookieParams)}};b.fn.fontscale.readcookie=function(e){var c={};b.each(b.cookie(e).split("&"),function(){var a=this.split("=");c[a[0]]=a[1]});return c};b.fn.fontscale.defaults={useCookie:!0,cookieName:"fontscale",cookieParams:{expires:30,path:"/"},increment:2,unit:"px",adjustLeading:!1,event:"click",cookieLoaded:!1,bounds:0,threshold:0}})(jQuery);



