var ielt9 = $.browser.msie && $.browser.version.substr(0,1)<9;
jQuery.fn.onImagesLoaded = function(_cb) { 
  return this.each(function() {
 
    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
        _cont = this,
            i = 0,
    _done=function() {
      if( typeof _cb === 'function' ) _cb(_cont);
    };
 
    if( $imgs.length ) {
      $imgs.each(function() {
        var _img = this,
        _checki=function(e) {
          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
          {
            if( ++i===$imgs.length ) _done();
          }
          else if( _img.readyState === undefined ) // dont for IE
          {
            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
          }
        }; // _checki \\
 
        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'}); // bind to 'load' event...
      });
    } else _done();
  });
};
/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
var ielt9 = $.browser.msie && $.browser.version.substr(0,1)<9;

var ajaxEngine = (function() {
	var settings = {
		enabled : false,
		redirectToRoot : true,
		defaultPage : '',
		root : 'http://electratherm.com/',
		cache : true,
		debug : false && (typeof console == 'object'),
		scrollAnimate : {
			enabled : true,
			duration : 500,
			easing : 'easeInOutQuad'
		},
		fade : {
			enterDuration : 500,
			exitDuration : 1000
		}
	};

	if(!settings.enabled) {
		$(document).ready(function() {$('#main').css('visibility','visible');});
		return;
	}

	var ajax = { abort : function() {}},
		interval = setInterval(checkHash, 50),
		checking = true,
		cache = [],
		hash = '',
		first = true;


	// Redirect to root for cleaner URLS
	if(settings.redirectToRoot && window.location.href.length - window.location.hash.length > settings.root.length)
		window.location.href = settings.root + '#' + window.location.href.replace(settings.root, '');
	init();
	
	// Init to be call more than once
	function init() {
		if(settings.debug) {
			console.log('ajaxEngine.init - hash: '+hash);
			console.log(settings);
		}
		firstCheck();
		$(document).ready(function() {updateLinks();});
	}
	function firstCheck() {
		if(window.location.hash != window.location.hash.replace(/\#/g, ''))
			window.location.hash = window.location.hash.replace(/\#/g, '');
		checkHash();
	}
	
	// Tracks hash changes and updates accordingly
	function checkHash() {
		if(!checking) return;
		var currentHash = window.location.hash.replace(/\#/g, '');
		if(currentHash == 'index.php' || currentHash == '') {
			if(window.location.hash != '' && window.location.hash != '#')
				window.location.hash = '';
			currentHash = '';
			first = false;
			$('#main').css('visibility', 'visible')
		}
		if(currentHash != hash) {
			if(settings.debug)
				console.log('ajaxEngine.checkHash - currentHash != hash { hash: '+hash+', currentHash: '+currentHash + ' }');
			checking = false;
			loadAJAX(settings.root+currentHash);
		}
	}
	
	// Updates all links with AJAX events
	function updateLinks() {
		$('a').each(function(i) {
			$this = $(this);
			$this.unbind('click.ajax click.blur');
			$this.bind('click.ajax', function(e) {$(this).blur();});
			if($this.attr('href').replace(settings.root, '') == hash) { $this.addClass('active'); return; }
			if($this.attr('target') == '_blank' || $this.attr('rel') == 'external') return;
			if(/^(mailto\:|text\:|javascript\:).*$/.test($this.attr('href'))) return;
						
			$this.removeClass('active').bind('click.ajax', _clickLink);
		});
	}
	
	// Loads AJAX page and runs corresponding page events
	function loadAJAX(url) {
		var shortURL = url.replace(settings.root, '');
		
		if(settings.debug)
			console.log('ajaxEngine.loadAJAX - url: '+url);
		ajax.abort();
		if(settings.cache && cache[shortURL] != null) {
			_transition(hash, shortURL, cache[shortURL]);
			hash = shortURL;
			if(window.location.hash != hash)
				window.location.hash = hash;
			checking = true;
			updateLinks();
			initJS(hash);
		} else {
			ajax = $.ajax({
				'url' : url,
				cache : false,
				data : 'ajax=1',
				error : function(XMLHttpRequest, textStatus) {
					if(settings.debug)
						console.log(XMLHttpRequest);
					hash = url.replace(settings.root, '');
					checking = true;
				},
				success : function(data, textStatus, XMLHttpRequest) {
					// Run default if no transition present
					_transition(hash, shortURL, XMLHttpRequest.responseText)
					hash = shortURL;
					if(window.location.hash != hash)
						window.location.hash = hash;
					checking = true;
					updateLinks();
				}
			});
		}
	}
	function initJS(hash) {
		if(settings.debug)
			console.log('ajaxEngine.initJS - hash: '+hash);
		switch(hash) {
			case '':
				Header.ajaxInit();
				Secondary.ajaxInit();
				break;
			default:
				Header.pauseAutoplay();
		}
	}
	function isCached(hash) {
		return settings.cache && cache[hash] != null;
	}
	function _cachePage(hash, $obj) {
		cache[hash] = $obj.remove();
		if(settings.debug) {
			console.log('ajaxEngine._cachePage - contents: ');
			console.log(cache[hash]);
			console.log('////');
		}
		$obj.remove();
	}
	function _transition(start, end, data) {
		// Put transitions in order of specificity
		if(settings.scrollAnimate.enabled)
			$.scrollTo(0, { duration: settings.scrollAnimate.duration, queue : false, easing : settings.scrollAnimate.easing });
		switch(true) {
			case first:
				first = false;
			case /^$/.test(start) && /^index\.php$/.test(end):
			case /^index\.php$/.test(start) && /^$/.test(end):
				$(document).ready(function() {
					if(settings.cache)
						_cachePage(start, $('#main').contents());
					$('#main').empty().css('visibility', 'visible').append(data);
				});
				break;
			default:
				$(document).ready(function() {
					$('#main').stop().animate({ opacity : 0 }, { queue : false, duration : settings.fade.enterDuration, complete : function() {
						if(settings.cache)
							_cachePage(start, $('#main').contents());
						$(this).empty().append(data);
						initJS(end);
						$(this).animate({ opacity : 1 }, { queue : false, duration : settings.fade.exitDuration });
					}});
				});
		}
	}	
	
	// AJAX link override
	function _clickLink(e) {
		var $this = $(this);
		if(settings.debug) {
			console.log('////');
			console.log('ajaxEngine._clickLink - href: '+$this.attr('href'));
		}
		loadAJAX($this.attr('href'));
		return false;
	}
	
	// Public functions
	return {
		'init' : init,
		'getHash' : function() { return hash; },
		'isCaching' : settings.cache,
		'isCached' : isCached,
		'loadAJAX' : loadAJAX,
		'updateLinks' : updateLinks,
		// Adds page event to list
		'checkHash' : checkHash,
		'initJS' : initJS
	};
})();
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var Header = (function() {
	var index = 0,
		basedir = '',
		images = [],
		settings = {
			speedclick : true,
			easing : 'easeOutQuad',
			duration : 900,
			autoplay : {
				enabled : true,
				idleStart : 8000,
				duration : 8000,
				idleReset : 30000
			},
			buttons : {
				easing : 'easeInOutExpo',
				duration : 100
			},
			caption : {
				easing : 'easeOutQuad',
				fadeInDuration : 2000,
				delay : 600,
				fadeOutDuration : 600
			},
			credits : {
				easing : 'easeOutQuad',
				fadeInDuration : 2000,
				delay : 600,
				fadeOutDuration : 600
			}
		},
		thisTime = 50000, lastTime = 0,
		autoplayInterval, idleTimeout;
	var $home_slider, $home_callout, $home_credits, $home_pagination_a;
	
	ajaxInit();
	init();
	
	function ajaxInit() {
		$(document).ready(function() {
			
				if (user_language == 'it') images.push({ image : 'http://electratherm.com/images/uploads/GBslideshow.jpg', caption : "La Green Machine produce energia dal calore disperso presso un impianto a biogas nella Repubblica Ceca ", credits : "Biogas", link : "http://electratherm.com/case_studies/biogas_in_czech_republic/"});	
				else if (user_language == 'de') images.push({ image : 'http://electratherm.com/images/uploads/GBslideshow.jpg', caption : "Eine Green Machine erzeugt Strom aus der Abwärme einer Biogasanlage in Tschechien", credits : "Biogas", link : "http://electratherm.com/case_studies/biogas_in_czech_republic/"});	
				else images.push({ image : 'http://electratherm.com/images/uploads/GBslideshow.jpg', caption : "Power from Waste Heat at Biogas Facility in the Czech Republic", credits : "Customer Success", link : "http://electratherm.com/case_studies/biogas_in_czech_republic/"});		
			
				if (user_language == 'it') images.push({ image : 'http://electratherm.com/images/uploads/Etatherm_homepage.jpg', caption : "Una Green Machine installata presso un impianto a biogas", credits : "Green Machine ElectraTherm", link : "http://electratherm.com/case_studies/biogas_in_germany/"});	
				else if (user_language == 'de') images.push({ image : 'http://electratherm.com/images/uploads/Etatherm_homepage.jpg', caption : "Green Machine in Biogasanlage in Österreich installiert", credits : "ElectraTherm Green Machine", link : "http://electratherm.com/case_studies/biogas_in_germany/"});	
				else images.push({ image : 'http://electratherm.com/images/uploads/Etatherm_homepage.jpg', caption : "Heat-to-Power Application in Germany", credits : "Power Generation at a Biogas Facility", link : "http://electratherm.com/case_studies/biogas_in_germany/"});		
			
				if (user_language == 'it') images.push({ image : 'http://electratherm.com/images/uploads/Denbury_Installation.jpg', caption : "Energia Senza Emissioni alla Testa del Pozzo", credits : "Studio Analitico per un Pozzo Petrolifero", link : "http://72.10.36.203/case_studies/smu_mississippi/"});	
				else if (user_language == 'de') images.push({ image : 'http://electratherm.com/images/uploads/Denbury_Installation.jpg', caption : "Emissionsfreier Strom am Bohrlochkopf", credits : "Fallstudien", link : "http://72.10.36.203/case_studies/smu_mississippi/"});	
				else images.push({ image : 'http://electratherm.com/images/uploads/Denbury_Installation.jpg', caption : "Emission Free Power at the Wellhead", credits : "Case Study at an Oil Well", link : "http://72.10.36.203/case_studies/smu_mississippi/"});		
			
				if (user_language == 'it') images.push({ image : 'http://electratherm.com/images/uploads/GCGE_ICE_Site.jpg', caption : "La Green Machine puo’ utilizzare l’acqua della camicia per generare potenza supplementare  ", credits : "Studio Analitico per un Motore Stazionario", link : "http://72.10.36.203/case_studies/south_texas/"});	
				else if (user_language == 'de') images.push({ image : 'http://electratherm.com/images/uploads/GCGE_ICE_Site.jpg', caption : "Die Green Machine kann Zwischenkühlwasser benutzen, um zusätzlichen Strom zu erzeugen", credits : "Fallstudien", link : "http://72.10.36.203/case_studies/south_texas/"});	
				else images.push({ image : 'http://electratherm.com/images/uploads/GCGE_ICE_Site.jpg', caption : "ElectraTherm's Green Machine can use jacket water to generate additional power", credits : "Case Study at a Stationary Engine", link : "http://72.10.36.203/case_studies/south_texas/"});		
			
			
			jQuery.preLoadImages("http://electratherm.com/images/uploads/headerimgs/slide1.jpg","http://electratherm.com/images/uploads/headerimgs/slide1.jpg","http://electratherm.com/images/uploads/headerimgs/slide1.jpg","http://electratherm.com/images/uploads/headerimgs/slide1.jpg","http://electratherm.com/images/uploads/headerimgs/slide1.jpg");
			$('#home_previous')
				.click(previous);
			$('#home_next')
				.click(next);
			$home_pagination_a = $('#home_pagination').children('a');
			$home_pagination_a.click(function(e) { resetAutoplay(); goto($home_pagination_a.index($(this))); });
			$home_slider = $('#home_slider');
			$home_callout = $('#home_callout');
			$home_credits = $('#header_credits');
			$home_slider.append('<img src='+basedir+images[index].image+' width="945" height="314" />');
			updateCaption();
			updateCredits();
			startAutoplay();
		});
	}
	function init() {
		for(var i=0; i<images.length; i++)
			(new Image()).src = images[i].image;
	}
	
	
	
	function autoplay() {
		if(!settings.autoplay.enabled) return;
		if(autoplayInterval == null)
			autoplayInterval = setInterval(autoplay, settings.autoplay.duration);
		clearTimeout(idleTimeout);
		next();
	}
	function startAutoplay() {
		if(settings.autoplay.enabled) {
			clearInterval(autoplayInterval);
			clearTimeout(idleTimeout);
			idleTimeout = setTimeout(autoplay, settings.autoplay.idleStart);
		}
	}
	function pauseAutoplay() {
		clearInterval(autoplayInterval);
		clearTimeout(idleTimeout);
	}
	function resetAutoplay() {
		if(settings.autoplay.enabled) {
			clearInterval(autoplayInterval);
			clearTimeout(idleTimeout);
			idleTimeout = setTimeout(autoplay, settings.autoplay.idleReset);
		}
	}
	function previous(e) {
		if(e != null) resetAutoplay();
		goto((index == 0 ? images.length - 1 : index - 1), 'left');
	}
	function next(e) {
		if(e != null) resetAutoplay();
		goto((index == images.length - 1 ? 0 : index + 1), 'right');
	}
	function goto(i, direction) {
		if(index == i) return;
		
		if(settings.speedclick) {
			lastTime = thisTime;
			thisTime = new Date().getTime();
		}
		
		if(direction == null)
			direction = (i > index) ? 'right' : 'left';
		
		index = i;
		updatePagination();
		
		$home_slider.add($home_callout).stop(1, 1);
		
		switch(direction) {
			case 'left':
				$home_slider.prepend('<img src='+basedir+images[i].image+' width="945" height="314" />');
				$home_slider.children('img:first').onImagesLoaded(function() {
					$home_slider.css('left', -945).animate({ left : 0 }, { queue : false, easing : settings.easing, duration : Math.min(settings.duration, thisTime - lastTime), complete : function() {$(this).children('img:gt(0)').remove();}});
				});
				break;
			case 'right':
				$home_slider.append('<img src='+basedir+images[i].image+' width="945" height="314" />');
				$home_slider.children('img:last').onImagesLoaded(function() {
					$home_slider.animate({ left : -945 }, { queue : false, easing : settings.easing, duration : Math.min(settings.duration, thisTime - lastTime), complete : function() {
						$(this).css('left', 0).children('img:eq(0)').remove();
					}});
				});
				break;
		}
		updateCaption();
		updateCredits();
	}
	function updatePagination() {
		$home_pagination_a.each(function(i) {
			if(i == index) $(this).addClass('active');
			else $(this).removeClass('active')
		});
	}
	function updateCaption() {
		if(ielt9) {
			$home_callout.css('display', 'none').empty().html(images[index].caption);
			$home_callout.attr('href', images[index].link);
			$home_callout.delay(Math.min(settings.caption.fadeOutDuration + settings.caption.delay, thisTime - lastTime)).queue(function(next) {
				$home_callout.css('display', 'block');
				next();
			});
		} else {
			$home_callout.animate({ opacity : 0 }, { queue : false, easing : settings.caption.easing, duration : Math.min(settings.caption.fadeOutDuration, (thisTime - lastTime) / 2), complete : function() {
				$home_callout.empty().html(images[index].caption);
				$home_callout.attr('href', images[index].link);
				$home_callout.delay(Math.min(settings.caption.delay, thisTime - lastTime)).animate({ opacity : 1 }, { easing : settings.caption.easing, duration : Math.min(settings.caption.fadeInDuration, (thisTime - lastTime) / 2) });
			}});
		}
	}
	function updateCredits() {
		if(ielt9) {
			$home_credits.css('display', 'none').empty().html(images[index].credits);
			$home_credits.delay(Math.min(settings.credits.fadeOutDuration + settings.credits.delay, thisTime - lastTime)).queue(function(next) {
				$home_credits.css('display', 'block');
				next();
			});
		} else {
			$home_credits.animate({ opacity : 0 }, { queue : false, easing : settings.credits.easing, duration : Math.min(settings.credits.fadeOutDuration, (thisTime - lastTime) / 2), complete : function() {
				$home_credits.empty().html(images[index].credits);
				$home_credits.delay(Math.min(settings.credits.delay, thisTime - lastTime)).animate({ opacity : 1 }, { easing : settings.credits.easing, duration : Math.min(settings.credits.fadeInDuration, (thisTime - lastTime) / 2) });
			}});
		}
	}
	
	return {
		'ajaxInit' : ajaxInit,
		'pauseAutoplay' : pauseAutoplay,
		'previous' : previous,
		'next' : next,
		'goto' : goto
	};
})();


