/*** NZ Herald Combined JS ***/

/**** Combined File : _010_jquery.sizes.min.js ****/
/*
 * JSizes - JQuery plugin v0.32
 *
 * Licensed under the revised BSD License.
 * Copyright 2008, Bram Stein
 * All rights reserved.
 */
(function(B){var A=function(C){return parseInt(C,10)||0};B.each(["min","max"],function(D,C){B.fn[C+"Size"]=function(G){var F,E;if(G){if(G.width){this.css(C+"-width",G.width)}if(G.height){this.css(C+"-height",G.height)}return this}else{F=this.css(C+"-width");E=this.css(C+"-height");return{width:(C==="max"&&(F===undefined||F==="none"||A(F)===-1)&&Number.MAX_VALUE)||A(F),height:(C==="max"&&(E===undefined||E==="none"||A(E)===-1)&&Number.MAX_VALUE)||A(E)}}}});B.fn.isVisible=function(){return this.css("visibility")!=="hidden"&&this.css("display")!=="none"};B.each(["border","margin","padding"],function(D,C){B.fn[C]=function(E){if(E){if(E.top){this.css(C+"-top"+(C==="border"?"-width":""),E.top)}if(E.bottom){this.css(C+"-bottom"+(C==="border"?"-width":""),E.bottom)}if(E.left){this.css(C+"-left"+(C==="border"?"-width":""),E.left)}if(E.right){this.css(C+"-right"+(C==="border"?"-width":""),E.right)}return this}else{return{top:A(this.css(C+"-top"+(C==="border"?"-width":""))),bottom:A(this.css(C+"-bottom"+(C==="border"?"-width":""))),left:A(this.css(C+"-left"+(C==="border"?"-width":""))),right:A(this.css(C+"-right"+(C==="border"?"-width":"")))}}}})})(jQuery);
/**** Combined File : _020_jquery.hoverIntent.js ****/
/**
* hoverIntent is similar to jQuery's built-in "hover" function except that
* instead of firing the onMouseOver event immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the onMouseOver event.
* 
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);
/**** Combined File : _030_jquery.history.js ****/
/*
 * jQuery history plugin
 * 
 * sample page: http://www.mikage.to/jquery/jquery_history.html
 *
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 */


jQuery.extend({
	historyCurrentHash: undefined,
	historyCallback: undefined,
	historyIframeSrc: undefined,
	historyNeedIframe: jQuery.browser.msie && (jQuery.browser.version < 8 || document.documentMode < 8),
	
	historyInit: function(callback, src){
		jQuery.historyCallback = callback;
		if (src) jQuery.historyIframeSrc = src;
		var current_hash = location.hash.replace(/\?.*$/, '');
		
		jQuery.historyCurrentHash = current_hash;
		if (jQuery.historyNeedIframe) {
			// To stop the callback firing twice during initilization if no hash present
			if (jQuery.historyCurrentHash == '') {
				jQuery.historyCurrentHash = '#';
			}
		
			// add hidden iframe for IE
			jQuery("body").prepend('<iframe id="jQuery_history" style="display: none;"'+
				' src="javascript:false;"></iframe>'
			);
			var ihistory = jQuery("#jQuery_history")[0];
			var iframe = ihistory.contentWindow.document;
			iframe.open();
			iframe.close();
			iframe.location.hash = current_hash;
		}
		else if (jQuery.browser.safari) {
			// etablish back/forward stacks
			jQuery.historyBackStack = [];
			jQuery.historyBackStack.length = history.length;
			jQuery.historyForwardStack = [];
			jQuery.lastHistoryLength = history.length;
			
			jQuery.isFirst = true;
		}
		if(current_hash)
			jQuery.historyCallback(current_hash.replace(/^#/, ''));
		setInterval(jQuery.historyCheck, 100);
	},
	
	historyAddHistory: function(hash) {
		// This makes the looping function do something
		jQuery.historyBackStack.push(hash);
		
		jQuery.historyForwardStack.length = 0; // clear forwardStack (true click occured)
		this.isFirst = true;
	},
	
	historyCheck: function(){
		if (jQuery.historyNeedIframe) {
			// On IE, check for location.hash of iframe
			var ihistory = jQuery("#jQuery_history")[0];
			var iframe = ihistory.contentDocument || ihistory.contentWindow.document;
			var current_hash = iframe.location.hash.replace(/\?.*$/, '');
			if(current_hash != jQuery.historyCurrentHash) {
			
				location.hash = current_hash;
				jQuery.historyCurrentHash = current_hash;
				jQuery.historyCallback(current_hash.replace(/^#/, ''));
				
			}
		} else if (jQuery.browser.safari) {
			if(jQuery.lastHistoryLength == history.length && jQuery.historyBackStack.length > jQuery.lastHistoryLength) {
				jQuery.historyBackStack.shift();
			}
			if (!jQuery.dontCheck) {
				var historyDelta = history.length - jQuery.historyBackStack.length;
				jQuery.lastHistoryLength = history.length;
				
				if (historyDelta) { // back or forward button has been pushed
					jQuery.isFirst = false;
					if (historyDelta < 0) { // back button has been pushed
						// move items to forward stack
						for (var i = 0; i < Math.abs(historyDelta); i++) jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop());
					} else { // forward button has been pushed
						// move items to back stack
						for (var i = 0; i < historyDelta; i++) jQuery.historyBackStack.push(jQuery.historyForwardStack.shift());
					}
					var cachedHash = jQuery.historyBackStack[jQuery.historyBackStack.length - 1];
					if (cachedHash != undefined) {
						jQuery.historyCurrentHash = location.hash.replace(/\?.*$/, '');
						jQuery.historyCallback(cachedHash);
					}
				} else if (jQuery.historyBackStack[jQuery.historyBackStack.length - 1] == undefined && !jQuery.isFirst) {
					// back button has been pushed to beginning and URL already pointed to hash (e.g. a bookmark)
					// document.URL doesn't change in Safari
					if (location.hash) {
						var current_hash = location.hash;
						jQuery.historyCallback(location.hash.replace(/^#/, ''));
					} else {
						var current_hash = '';
						jQuery.historyCallback('');
					}
					jQuery.isFirst = true;
				}
			}
		} else {
			// otherwise, check for location.hash
			var current_hash = location.hash.replace(/\?.*$/, '');
			if(current_hash != jQuery.historyCurrentHash) {
				jQuery.historyCurrentHash = current_hash;
				jQuery.historyCallback(current_hash.replace(/^#/, ''));
			}
		}
	},
	historyLoad: function(hash){
		var newhash;
		hash = decodeURIComponent(hash.replace(/\?.*$/, ''));
		
		if (jQuery.browser.safari) {
			newhash = hash;
		}
		else {
			newhash = '#' + hash;
			location.hash = newhash;
		}
		jQuery.historyCurrentHash = newhash;
		
		if (jQuery.historyNeedIframe) {
			var ihistory = jQuery("#jQuery_history")[0];
			var iframe = ihistory.contentWindow.document;
			iframe.open();
			iframe.close();
			iframe.location.hash = newhash;
			jQuery.lastHistoryLength = history.length;
			jQuery.historyCallback(hash);
		}
		else if (jQuery.browser.safari) {
			jQuery.dontCheck = true;
			// Manually keep track of the history values for Safari
			this.historyAddHistory(hash);
			
			// Wait a while before allowing checking so that Safari has time to update the "history" object
			// correctly (otherwise the check loop would detect a false change in hash).
			var fn = function() {jQuery.dontCheck = false;};
			window.setTimeout(fn, 200);
			jQuery.historyCallback(hash);
			// N.B. "location.hash=" must be the last line of code for Safari as execution stops afterwards.
			//      By explicitly using the "location.hash" command (instead of using a variable set to "location.hash") the
			//      URL in the browser and the "history" object are both updated correctly.
			location.hash = newhash;
		}
		else {
		  jQuery.historyCallback(hash);
		}
	}
});



/**** Combined File : _060_jquery.apngallery.js ****/
(function($){

var $$;


/**
 * Original credits to apngallery, and it's author David Hellsing.
 * 
 * @desc Take a UL list of anchor's and images - and convert into a usable image gallery.
 * @author Craig Bassett
 * @version 1.0
 *
 * @name APNGallery
 * @type jQuery
 *
 * @cat plugins/Media
 * 
 * @example $('ul.gallery').apngallery({options});
 * @desc Create a a gallery from an unordered list of images with thumbnails
 * @options
 *   insert:   (selector string) The gallery insert it's required elements into this div.
 *   onLoading:(function) This fires upon the initiation of a new image being loaded.
 *   onImage:  (function) This function get's fired upon creation of the main image.
 *   onThumb:  (function) This function get's fired upon initialisation of the thumb image.
 *
**/

$$ = $.fn.apngallery = function($options) {
	
	// check for basic CSS support
	if (!$$.hasCSS()) { return false; }
	
	// set default options
	var $defaults = {
		insert      : '.apngallery_container',
		preload		: false,
		history		: false,
		onLoading   : function(caption,thumb) {},
		onImage     : function(image,caption,thumb) {},
		onThumb     : function(thumb) {}
	};
	
	// extend the options
	var $opts = $.extend($defaults, $options);
	
	// bring the options to the apngallery object
	for (var i in $opts) {
		if (i) {
			$.apngallery[i]  = $opts[i];
		}
	}
	
	// if no insert selector, create a new division and insert it before the ul
	var _insert = ( $($opts.insert).is($opts.insert) ) ? 
		$($opts.insert) : 
		jQuery(document.createElement('div')).insertBefore(this);
		
	// create a loading div
	var _loaderImage = $(document.createElement('div')).addClass('apngallery_loader');
	
	// create a wrapping div for the image
	var _div = $(document.createElement('div')).addClass('apngallery_wrapper');

	// create a caption span
	var _span = $(document.createElement('span')).addClass('caption');
	
	// inject the loader, wrapper and caption in the insert selector
	_insert.addClass('apngallery_container').append(_loaderImage).append(_div).append(_span);
	
	// add the apngallery class
	$(this).addClass('apngallery');
	
	// loop through list of images
	var _dRel = ""; // Default Source.
	$(this).children('li').each(function(i) {
		
		// bring the scope
		var _container = $(this);
		
		// build element specific options
		var _o = $.meta ? $.extend({}, $opts, _container.data()) : $opts;
		
		// find our anchor anchor
		var _a = $(this).find('a');
		
		// reference the original image as a variable and hide it
		var _img = $(this).children('img').css('display','none');
		
		// extract the original source
		var _src = _a.attr('href');
		
		// find a title
		var _title = _a.attr('title');
		
		// find the rel
		var _rel = _a.attr('rel');
		
		// create our overlay
		var _overlay = $(document.createElement('div')).addClass('overlay');		
		
		// check url and activate container if match
		if ((window.location.hash && (window.location.hash.replace(/\#/,'') == _rel))) {
			_container.siblings('.active').removeClass('active');
			_container.addClass('active');
		}
	
		// let's create the thumbnail
		var _thumb = _a.find('img').addClass('thumb noscale').css('display','none');
		if (_a) { _a.replaceWith(_thumb); }

		// add the rel attribute
		_thumb.attr('rel',_src);
		
		// add the title attribute
		_thumb.attr('title',_title);
		
		// add the alt
		_thumb.attr('alt',_rel);
		
		// add the click functionality to the the thumbs container (li)
		_container.click(function() {
			$.apngallery.activate(_rel);
		});
		
		// hover classes for IE6
		_thumb.hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
		);
		_container.hover(
			function() { _container.addClass('hover'); },
			function() { _container.removeClass('hover'); }
		);

		// prepend the thumbnail in the container
		_container.prepend(_thumb);
		
		// add the title to our overlay
		_overlay.attr('title',_title);
		
		// append our overlay class in the container
		_container.append(_overlay);
		
		// show the thumbnail
		_thumb.css('display','block');
		
		// call the onThumb function
		_o.onThumb(jQuery(_thumb));
		
		if (_container.hasClass('active')){
			_dRel = _rel;	
		}
		
		//-----------------------------------------------------------------
		
		// finally delete the original image
		_img.remove();
		
	}).error(function () {
		
		// Error handling
		_container.html('<span class="error" style="color:red">Error loading image: '+_src+'</span>');
	
	});
	
	// activate our image
	if ($.apngallery.history) {
		$.historyInit($$.onPageLoad);
		if (!window.location.hash) $.apngallery.activate(_dRel);
	} else {
		$.apngallery.activate(_dRel)
	}
};

/**
 *
 * @name NextSelector
 *
 * @desc Returns the sibling sibling, or the first one
 *
**/

$$.nextSelector = function(selector) {
	return $(selector).is(':last-child') ?
		   $(selector).siblings(':first-child') :
    	   $(selector).next();
    	   
};

/**
 *
 * @name previousSelector
 *
 * @desc Returns the previous sibling, or the last one
 *
**/

$$.previousSelector = function(selector) {
	return $(selector).is(':first-child') ?
		   $(selector).siblings(':last-child') :
    	   $(selector).prev();
    	   
};

/**
 *
 * @name hasCSS
 *
 * @desc Checks for CSS support and returns a boolean value
 *
**/

$$.hasCSS = function()  {
	$('body').append(
		$(document.createElement('div')).attr('id','css_test').css({ width:'1px', height:'1px', display:'none' })
	);
	var _v = ($('#css_test').width() != 1) ? false : true;
	$('#css_test').remove();
	return _v;
};

/**
 *
 * @name onPageLoad
 *
 * @desc The function that displays the image and alters the active classes
 *
 * Note: This function gets called when:
 * 1. after calling $.historyInit(); [from the plugin's initialisation i.e., initial page load]
 * 2. after calling $.historyLoad(); [from activate]
 * 3. after pushing "Go Back" button of a browser
 *
**/

$$.onPageLoad = function(_alt) {
	// if the thumb doesnt exist - reset to the first in the gallery.
	if (!_alt)
	{
		_alt = $('.apngallery img:first').attr('alt');
	}
	
	// get the wrapper
	var _wrapper = $('.apngallery_wrapper');
	
	// get the thumb
	var _thumb = $('.apngallery img[alt="'+_alt+'"]');
	
	// get the thumbs src
	var _src = _thumb.attr('rel');
	
	// get the loader
	var _loaderImage = $('.apngallery_loader');
	
	// new hash location
	window.location = window.location.href.replace(/\#.*/,'') + '#' + _alt;

	// alter the active classes
	_thumb.parents('li').siblings('.active').removeClass('active');
	_thumb.parents('li').addClass('active');

	// empty the wrapper - and hide the caption.
	_wrapper.empty();
	
	// fire the onLoading function to customize what we need prior to the image loading.
	$.apngallery.onLoading(_wrapper.siblings('.caption'),_thumb);
	
	// Show the loader. Use a timer to avoid the loader image showing on fast connections.
	loaderTimer = setTimeout(function(){
		_loaderImage.show()
	}, 200);

	// define a new image
	var _img = $(new Image()).load(function(){
		// Hide the loader image.
		clearTimeout(loaderTimer);
		_loaderImage.hide();
	
		// resize the wrapper based on the new image.
		_wrapper.css('height',$(this).attr('height'));
		
		// insert the caption, and title
		if (_thumb.attr('title').length > 0) {
			$(this).attr('title',_thumb.attr('title'));
			_wrapper.siblings('.caption').text(_thumb.attr('title')).show()
		} else {
			_wrapper.siblings('.caption').hide();
		}
		
		// fire the onImage function to customize the loaded image's features
		$.apngallery.onImage($(this),_wrapper.siblings('.caption'),_thumb);
	
		// Insert the new image
		_wrapper.append($(this))
		
	}).attr('src',_src).addClass('replaced');

	// place the source in the apngallery.current variable
	$.apngallery.current = _alt;
	
};

/**
 *
 * @name jQuery.apngallery
 *
 * @desc The global apngallery object holds two constant variables and four public methods:
 *       $.apngallery.current = is the current source that's being viewed.
 *       $.apngallery.onImage(image,caption) = gets fired when the image is displayed.
 *       $.apngallery.activate(_src) = displays an image from _src in the apngallery container.
 *       $.apngallery.next() = displays the next image in line, returns to first image after the last.
 *       $.apngallery.prev() = displays the previous image in line, returns to last image after the first.
 *
**/

$.extend({apngallery : {
	current : '',
	onLoading : function(){},
	onImage : function(){},
	activate : function(_alt) { 
		if ($.apngallery.history) {
			$.historyLoad(_alt);
		} else {
			$$.onPageLoad(_alt);
		}
	},
	next : function() {
		var _next = $($$.nextSelector($('.apngallery img[alt="'+$.apngallery.current+'"]').parents('li')));
		$.apngallery.activate(_next.find('img').attr('alt'));
		if($.apngallery.preload) {
			var _preload = $$.nextSelector($(_next)).find('img').attr('rel');
			$.apngallery.preLoadImage(_preload);
		}
	},
	prev : function() {
		var _prev = $($$.previousSelector($('.apngallery img[alt="'+$.apngallery.current+'"]').parents('li')));
		$.apngallery.activate(_prev.find('img').attr('alt'));
		if($.apngallery.preload) {
			var _preload = $$.previousSelector($(_prev)).find('img').attr('rel');
			$.apngallery.preLoadImage(_preload);
		}
	},
	preLoadImage : function(_src) {
		var image = $(new Image()).attr('src',_src);
	}
}
});

})(jQuery);

