/*** NZ Herald Combined JS ***/
/**** Combined File : _010_jquery.autAds.js ****/
(function($) {

	/**
	 * @desc Create our autSlider.
	 * @author Craig Bassett
	 * @version 1.0
	 *
	**/
	
	$.fn.autSlider = function(options) {
		
		// Our options.
		options = jQuery.extend({
			data			: {},
			size			: 440,
			slideContainer 	: "#autSlides",
			scrollTime		: 10000,
			onLoad			: function() {}
		}, options);
		
		// Defined Variables.
		var pluginElement = $(this); // The element the plugin was invoked on.
		var slideWindow = $(options.slideContainer);
		var navEnabled = true;
		
		// Public Functions.
		$.extend({
			showNext		: function() {
				slideNext();
			},
			
			showPrevious	: function() {
				slidePrevious();
			}
		});
		
		//*** Check for CSS support ***
		var 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;
		}
		
		var timer				= (function() {
			var pub = {};
			var timerActual = "";
			var tickCount = 0;
			var maxCount = 0;
		
			var intFunc = function() {
				slideNext();
				pub.startTimer(maxCount);
			}

			pub.setMaxCount 	= function(count) {
				maxCount = count;
			}
			
			pub.startTimer		= function(){
				if (tickCount < maxCount) {
					tickCount ++;
					timerActual = setTimeout(intFunc, options.scrollTime);
				}		
			};
			
			pub.stopTimer		= function(){ 
				clearTimeout(timerActual);
				tickCount = 0;
			};
			
			return pub;
		}());
		
		//*** Slide next ***
		var slideNext = function() {
			// We use this setInterval to make sure the user can't stack additional animations without the first being finished.
			var wait = setInterval(function() {
				
				if(!slideWindow.children("a.slide").is(":animated")) {
					clearInterval(wait);
				
					// If our currently active item is the last in the row, move the first item to the end.
					if ((parseFloat(nextSelector(slideWindow.children("a.active")).css('left')) - 0) < 0) {
						nextSelector(slideWindow.children("a.active")).css('left', options.size);
					}
					slideWindow.children("a.slide").each(function(){
						$.fn.autSlider.slideLeft($(this));
					});
					incrementNav();
					setActive(nextSelector(slideWindow.children("a.active")));
				}
				
			}, 150);
		}
		
		//*** Slide previous ***
		var slidePrevious = function() {
			// We use this setInterval to make sure the user can't stack additional animations without the first being finished.
			var wait = setInterval(function() {
				
				if(!slideWindow.children("a.slide").is(":animated")) {
					clearInterval(wait);
				
					// If our currently active item is the first in the row, move the last item to the front.
					if ((parseFloat(previousSelector(slideWindow.children("a.active")).css('left')) - 0) > 0) {
						previousSelector(slideWindow.children("a.active")).css('left', -options.size);
					}
					slideWindow.children("a.slide").each(function(){
						$.fn.autSlider.slideRight($(this));
					});
					decrementNav();
					setActive(previousSelector(slideWindow.children("a.active")));
				}
			}, 150);
		}
		
		//*** Set our current active element ***
		var setActive = function(element) {
			unsetActive();
			element.addClass("active");
		}
		
		//*** Make sure nothing is set active ***
		var unsetActive = function() {
			slideWindow.children("a.slide").each(function(){
				$(this).removeClass("active");
			});
		}
		
		//** Return the currently active element ***
		var activeElement = function() {
			return slideWindow.children("a.active");
		}
		
		//** Return the currently active nav element ***
		var activeSubNav = function() {
			return pluginElement.find("li.active");
		}
		
		//** Determine the next sibling in line, or the first. ***
		var nextSelector = function(selector) {
			return $(selector).is(':last-child') ?
				   $(selector).siblings(':first-child') :
				   $(selector).next();		
		}
		
		//** Determine the previous sibling in line, or the last. ***
		var previousSelector = function(selector) {
			return $(selector).is(':first-child') ?
				   $(selector).siblings(':last-child') :
				   $(selector).prev();
		}
		
		//** Increment the nav to the next item. ***
		var incrementNav = function() {
			var element = nextSelector(activeSubNav());
			activeSubNav().removeClass('active').siblings().removeClass('active');
			element.addClass("active");
		}
		
		//** Increment the nav to the previous item. ***
		var decrementNav = function() {
			var element = previousSelector(activeSubNav());
			activeSubNav().removeClass('active').siblings().removeClass('active');
			element.addClass("active");
		}
		
		//*** Used to determine if we've got an empty object or not. ***
		var isEmptyObject = function(obj) {
			for(var i in obj) { return false; } return true;
		}
		
		//** Reshuffle an array **
		var shuffle = function(arr) {
			for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
			return arr;
		}
		
		//*** Grab our article data. ***
		var getData = function(feed, callback) {
			
			var slideData = [];
			
			// Get our JSON data.
			$.ajax({ type: "GET", url: feed, success: function(data){
				
				// Make sure we have data.
				if (data.SLIDER.length > 0) {
					
					// Loop through our data.
					$.each(data.SLIDER, function(i){
						if (options.size == 440) {
							slideData.push({ "title": data.SLIDER[i].TITLE, "url": data.SLIDER[i].URL, "type": data.SLIDER[i].TYPE, "target": data.SLIDER[i].TARGET, "clicktag": data.SLIDER[i].CLICKTAG, "image": data.SLIDER[i].IMAGE_440X400 });
							
						} else if (options.size == 300) {
							slideData.push({ "title": data.SLIDER[i].TITLE, "url": data.SLIDER[i].URL, "type": data.SLIDER[i].TYPE, "target": data.SLIDER[i].TARGET, "clicktag": data.SLIDER[i].CLICKTAG, "image": data.SLIDER[i].IMAGE_300X250 });
						}
					});
				}
				
				// Shuffle the Array.
				slideData = shuffle(slideData);
				
				// Append our ad if it was passed.
				if (!isEmptyObject(options.data)) {
					slideData.push(options.data);
				}
				
				// Run our callback.
				callback(slideData);
			
			}, dataType: "json", cache: true })
		}
		
		//** Return a random number - given the limits. **
		var returnRand = function(numLow, numHigh) {
			var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
			return Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
		}

		// check for basic CSS support
		if (!hasCSS()) { return false; }
		
		// Add our nav elements.
		var _aLeft =	$("<a href='#' class='navLeft'><!-- --></a>")
						.click(function(){
							timer.stopTimer();
							slidePrevious();
							return false;
					 	})
						
		var _aRight =	$("<a href='#' class='navRight'><!-- --></a>")
						.click(function(){
							timer.stopTimer();
							slideNext();
							return false;
					 	})

		// Append the a tags to our nav.
		pluginElement.prepend(_aLeft);
		pluginElement.prepend(_aRight);
		
		// Add our nav to the container.
		//pluginElement.prepend(_nav);
		
		// Add our sub nav item.
		var _subNav = $("<div class='subNav'></div>");
		var _list = $("<ol></ol>");
		
		// Grab our pre-formatted data.
		getData("/apps/aut/getfeaturejson.cfm", function(slideData){
			
			// Loop through our data structure and build markup from it.
			var position = 0;
			var count = 0;
			
			$.each(slideData, function(i) {
				// Create the root slide div element.
				var _slide = $("<a></a>")
							 .addClass('slide')
							 .css("left", position)
							 .attr("href", slideData[i].url);
							 
				// Set the target for our link. (Default _blank).
				(isEmptyObject(slideData[i].target) && slideData[i].target == undefined) ? _slide.attr("target", "_blank") : _slide.attr("target", slideData[i].target);
						 
				// Add a click tag if it was defined.
				if (slideData[i].clicktag.length > 0) {
					_slide.attr("onclick", slideData[i].clicktag);
				}
							 
				// Make sure the first slide is marked as active.
				if (i == 0) _slide.addClass('active');
				
				// Add the image.
				_slide.append($("<img class='img' />").attr('src',slideData[i].image));
				
				// Add caption.
				var _caption = $("<div class='caption'></div>")
							   .append("<div class='transparency'><!-- --></div>");
				
				// Add the overlay.
				if (slideData[i].type != undefined && slideData[i].type.toLowerCase() == "video") {
					_slide.append($("<span class='videoOverlay'><!-- --></span>"));
				}
				
				// Determine our title prefix (if any).
				var titlePrefix = "";
				
				if (slideData[i].type != undefined) {
					switch (slideData[i].type.toLowerCase()) {
						case "photo":
							titlePrefix = "Photo:&nbsp;";
							break;
						case "video":
							titlePrefix = "Video:&nbsp;";
							break;
						case "quiz":
							titlePrefix = "Quiz:&nbsp;";
							break;
					}
				}
				
				// Create our link.
				var _content = $("<div class='content'></div>")
						 .append("<span>" + titlePrefix + slideData[i].title + "</span>")
						 .append("<div class='logo'><!-- --></span>");
				
				// Add our a tag to the caption.
				_caption.append(_content);
				
				// Add the caption to our slide.
				_slide.append(_caption);
				
				// Add the slide to our container.
				slideWindow.append(_slide);
				
				// Generate the list item for our subnav.
				(i == 0) ? _list.append($("<li class='navItem active'><!-- --></li>")) : _list.append($("<li class='navItem'><!-- --></li>"));
				
				// Increase our position by the size.
				position = position + options.size;
				count ++;
			});
			
			// Add our subnav to the container.
			_list.css('width', ((count)*12)+(count*4));
			_subNav.append(_list);
			pluginElement.append(_subNav);
			
			// Fire our onLoad event.
			options.onLoad();
			
			// Setup a timer to scroll our slider automagically.
			timer.setMaxCount(count);
			timer.startTimer();
		});
		
		return this;
		
	};

	// Exposed extensions to our plugin.
	// We could use other easing settings here if we used jquery.ui.core.
	// The user could also extend these without having to touch the plugin if required.
	$.fn.autSlider.slideLeft = function(element) {
		element.stop().animate(
			{ 
				left: parseInt(element.css('left'), 10) - element.outerWidth(),
				duration: 300,
				easing:   'swing'
			});
	}
	
	$.fn.autSlider.slideRight = function(element) {
		element.stop().animate(
			{ 
				left: parseInt(element.css('left'), 10) + element.outerWidth(),
				duration: 300,
				easing:   'swing'
			});
	}
	

})(jQuery);
/**** Combined File : _020_jquery.autArt.js ****/
(function($) {

	/**
	 * @desc Create our autArticle.
	 * @author Craig Bassett
	 * @version 1.0
	 *
	**/
	
	$.fn.autArticle = function(options) {
		
		// Our options.
		options = jQuery.extend({
			slideContainer 	: "#autArticle",
			onLoad			: function() {}
		}, options);
		
		// Defined Variables.
		var pluginElement = $(this); // The element the plugin was invoked on.
		
		//*** Check for CSS support ***
		var 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;
		}
		
		//*** Used to determine if we've got an empty object or not. ***
		var isEmptyObject = function(obj) {
			for(var i in obj) { return false; } return true;
		}
		
		//*** Used to determine a query string parameter.
		var urlParam = function(name){
			var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
			if (!results) { return 0; }
			return results[1] || 0;
		}
		
		//** Reshuffle an array **
		var shuffle = function(arr) {
			for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
			return arr;
		}
		
		//*** Grab our article data. ***
		var getData = function(feed, callback) {
			
			var slideData = [];
			var currentPageObjectId = urlParam("objectid");
			
			// Get our JSON data.
			$.ajax({ type: "GET", url: feed, success: function(data){
				
				// Make sure we have data.
				if (data.ARTICLE.length > 0) {
				
					// Loop through our data.
					$.each(data.ARTICLE, function(i){
												  
						// Don't add an article if it's the same as our current article page (if we're on an article page).
						if (currentPageObjectId != data.ARTICLE[i].ID) {
							slideData.push({ "title": data.ARTICLE[i].TITLE, "bodytext": data.ARTICLE[i].BODY, "url": data.ARTICLE[i].URL, "clicktag": data.ARTICLE[i].CLICKTAG, "image": data.ARTICLE[i].IMAGE_140X70 });
						}
						
					});
				}
				
				// Shuffle the Array.
				slideData = shuffle(slideData);
				
				// Run our callback.
				callback(slideData);
			
			}, dataType: "json", cache: true })
		}

		// check for basic CSS support
		if (!hasCSS()) { return false; }
		
		// Grab our pre-formatted data.
		getData("/apps/aut/getfeaturejson.cfm", function(slideData){
														 
			// Determine which article (if we have more than one) to use.
			var articleIndex = 0;
			if (slideData.length > 1) {
				//alert(slideData.length);
			}
			
			// Find the elements we need to inject data into.
			_body = pluginElement.find(".body");
			
			// Add the headline BEFORE the body div.
			var _headline = 	$("<a class='headline'></a>")
								.attr("href", slideData[articleIndex].url);
			_headline.append(slideData[articleIndex].title);
			if (slideData[articleIndex].clicktag.length > articleIndex) {
				_headline.attr("onclick", slideData[articleIndex].clicktag);
			}
			
			_body.before(_headline);
			
			// Image appended in _body.
			if (slideData[articleIndex].image.length > 0) {
				var _a = 	$("<a class='thumb'></a>")
							.attr("href", slideData[articleIndex].url);
				if (slideData[articleIndex].clicktag.length > 0) {
					_a.attr("onclick", slideData[articleIndex].clicktag);
				}

				var _img = $("<img />").attr('src',slideData[articleIndex].image);
				
				// Append the image to our a tag.
				_a.append(_img);
				
				// Append the a tag to our body.
				_body.append(_a);
			}
			
			// Add the body text.
			var _synopsis = $("<p></p>");
			_synopsis.append(slideData[articleIndex].bodytext + "...&nbsp;");
			
			// Add a more link.
			var _more = 	$("<a class='more'>More</a>")
							.attr("href", slideData[articleIndex].url);

			// Add a click tag if it was defined.
			if (slideData[articleIndex].clicktag.length > 0) {
				_more.attr("onclick", slideData[articleIndex].clicktag);
			}
			
			// Add our more link to the synopsis.
			_synopsis.append(_more);
			
			// Append the synopsis to our body.
			_body.append(_synopsis);
			
			// Fire our onLoad event.
			options.onLoad();
		});
		
		return this;
		
	};
})(jQuery);

