
(function($){

	"use strict";

	$(document).ready(function(){
		
		/*  */
		$('.results .entry:has(.image)').each(
			function(){
				$(this).find('dl').css('float','right').css('width',105 );
			}
		);

		/* Set 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;
		});

		setupFontResizer();

		/* Load Aside nav. */
		$.each({
			'#section_nav': '/section/sidebar.html',
			'#ir_nav': '/ir/sidebar.html'
			//'#results_nav': '/results/sidebar.html'
		}, function(navId, navUrl){
			$(navId).load(navUrl, function(){
				var currentUrl = location.href;
				$(this).find('a').each(function(){
					/* Add Current status. */
					if (this.href === currentUrl) {
						$(this).addClass('on');
					}
	
					/* Open link as '_blank'. */
					if ((this.rel === 'external')||(this.href.search(/\.pdf$/) !== -1)) {
						$(this).click(function(){
							window.open(this.href, '_blank');
							return false;
						});
					}
				});
			});
		});

		fixIE();
		
		$('#content .section_results .entry:even').addClass('even');
		//$('#content .section_results .entry:first').addClass('first');
		
	});

	/**
	 * Setup font resize.
	 */
	function setupFontResizer() {
		if ($.isFunction($.fn.fontscale)) {
			$('#font_size')
				.find('a[rel=smaller]')
					.fontscale('#article, #aside', '-')
				.end()
				.find('a[rel=larger]')
					.fontscale('#article, #aside', '+')
				.end()
				.find('p')
					.fontscale('#article, #aside', 'reset', {
						event: 'dblclick'
					})
				.end()
			;
		}
	}

	/**
	 * Fix ie problem.
	 */
	function fixIE() {
		if (!$.browser.msie) {
			return;
		}

		/* Background flicker. */
		try {
			document.execCommand('BackgroundImageCache', false, true);
		}
		catch(e) {}

		/* CSS3 selector alternative. */
		$('#aside div.section').find('li:first').addClass('first-child');
	}

})(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 
 * For documentation, visit http://byrnecreative.com/blog/fontscale
 * 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
 * @version 0.2
 */
(function(a){a.fn.fontscale=function(c,b,e){var d=a.extend(a.fn.fontscale.defaults,e);if(!a.isFunction(a.cookie)){d.useCookie=false}if(!d.cookieLoaded&&a.cookie(d.cookieName)&&d.useCookie){cookieSettings=a.fn.fontscale.readcookie(d.cookieName);if(cookieSettings.unit==d.unit&&!d.cookieLoaded){a.fn.fontscale.scale(c,cookieSettings.delta,d,true)}}this.each(function(){a(this).bind(d.event,function(){a.fn.fontscale.scale(c,b,d,false);if(a.isFunction(d.onAfter)){d.onAfter(c,b,d)}})});return this};a.fn.fontscale.reset=function(b,c){a(b).each(function(d){a(this).css("font-size","");if(c.adjustLeading){a(this).css("line-height","")}});if(c.useCookie){a.fn.fontscale.savecookie("delete",c)}};a.fn.fontscale.scale=function(d,c,e,b){var f=0;if(c=="+"||c=="up"){f=e.increment}else{if(c=="-"||c=="down"){f=e.increment*-1}else{if(c=="reset"){return a.fn.fontscale.reset(d,e)}else{if(b){f=parseFloat(c);e.cookieLoaded=true}}}}if(e.unit=="percent"&&!b){f=1+(f/100)}a(d).each(function(h){var g=parseInt(a(this).css("font-size"));var j=parseInt(a(this).css("line-height"));if(e.unit=="percent"){a(this).css("font-size",Math.round(g*f));if(e.adjustLeading){a(this).css("line-height",Math.round(j*f))}}else{a(this).css("font-size",g+f);if(e.adjustLeading){a(this).css("line-height",j+f)}}});if(e.useCookie&&!b){a.fn.fontscale.savecookie(f,e)}return};a.fn.fontscale.savecookie=function(c,b){if(c=="delete"){a.cookie(b.cookieName,null,b.cookieParams);return true}if(a.cookie(b.cookieName)){properties=a.fn.fontscale.readcookie(b.cookieName)}else{properties={delta:0}}if(b.unit==properties.unit){if(b.unit=="percent"){properties.delta=(c)?properties.delta*c:1}else{properties.delta=parseInt(properties.delta)+c}return a.cookie(b.cookieName,"delta="+properties.delta+"&unit="+properties.unit,b.cookieParams)}else{a.cookie(b.cookieName,"delta="+c+"&unit="+b.unit,b.cookieParams);return true}};a.fn.fontscale.readcookie=function(b){val_string=a.cookie(b);var c={};a.each(val_string.split("&"),function(){var d=this.split("=");c[d[0]]=d[1]});return c}})(jQuery);$.fn.fontscale.defaults={useCookie:true,cookieName:"fontscale",cookieParams:{expires:30,path:"/"},increment:2,unit:"px",adjustLeading:false,event:"click",cookieLoaded:false};



/**
 * thx PHP.js. (http://phpjs.org/functions/array_chunk:306)
 */
function array_chunk (input, size) {
	// Split array into chunks  
	// 
	// version: 1006.1915
	// discuss at: http://phpjs.org/functions/array_chunk    // +   original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
	// *     example 1: array_chunk(['Kevin', 'van', 'Zonneveld'], 2);
	// *     returns 1: {0 : {0: 'Kevin', 1: 'van'} , 1 : {0: 'Zonneveld'}}
 
	for (var x, i = 0, c = -1, l = input.length, n = []; i < l; i++){        (x = i % size) ? n[c][x] = input[i] : n[++c] = [input[i]];
	}
 
	return n;
}



