﻿var animating = false;
var now = "";

var freeDemoTitle = 'Free Demo';
var freeDemoInstructions = 'Please enter your contact information and someone will contact you soon.';

var contactUsTitle = 'Contact Us';
var contactUsInstructions = 'Contact Us'
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;
	}
});


;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'y',
		duration:1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window).scrollable();
	};

	// Hack, hack, hack... stay away!
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn.scrollable = function(){
		return this.map(function(){
			// Just store it, we might need it
			var win = this.parentWindow || this.defaultView,
				// If it's a document, get its iframe or the window if it's THE document
				elem = this.nodeName == '#document' ? win.frameElement || win : this,
				// Get the corresponding document
				doc = elem.contentDocument || (elem.contentWindow || elem).document,
				isWin = elem.setInterval;

			return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
				: isWin ? doc.documentElement
				: this;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this.scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(px)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					Dim = axis == 'x' ? 'Width' : 'Height',
					dim = Dim.toLowerCase();

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[dim]() * settings.over[pos];
				}else
					attr[key] = targ[pos];

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});			
			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};
			function max( Dim ){
				var attr ='scroll'+Dim,
					doc = elem.ownerDocument;
				
				return win
						? Math.max( doc.documentElement[attr], doc.body[attr]  )
						: elem[attr];
			};
		}).end();
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );

/* plugins.jquery.com/project/Timer */
$.timer = function (interval, callback){
	var interval = interval || 100;
	if (!callback)
		return false;
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		this.internalCallback = function () {
			callback(self);
		};
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		var self = this;
	};
	return new _timer(interval, callback);
};

$.extend({
	changeSlide: function( oldSlide, newSlide ){
		$('#choose-'+oldSlide+' a').removeClass('current');
		//$('#slide-'+oldSlide+'').css('display','none');
		//$('#slide-'+newSlide+'').css('display','block');
		$('#slide-'+oldSlide+'').fadeOut('normal');
		$('#slide-'+newSlide+'').fadeIn('normal');
		$('#choose-'+newSlide+' a').addClass('current');
		return newSlide;
	}
});

$.extend({
	resizeBody: function(){
		if( $('#promos').length > 0 ){
			if( $(window).height() > 428 && ( $('#promos').height()+428 < $(window).height() || $('#contact-form').height()+428 < $(window).height())  ){
				if( $.browser.msie && $.browser.version < 7 ){
					$('#promos').css('height',($(window).height()-428));
				}else{
					$('#promos').css('min-height',($(window).height()-428));
				}
			}
			return true;
		}
		if( $('#page-inner').length > 0 ){
			if( $(window).height() > 183 && $('#page-inner').height()+183 < $(window).height()  ){
				if( $.browser.msie && $.browser.version < 7 ){
					$('#page-inner').css('height',($(window).height()-183));
				}else{
					$('#page-inner').css('min-height',($(window).height()-183));
				}
			}
			return true;
		}
	}
});

jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		$('body').append('<img src="'+arguments[i]+'" class="hideme" style="display:none;" />');
	}
}

$(document).ready(function() {

	$.resizeBody();
	$(window).resize(function(){ $.resizeBody(); });

	$.preloadImages("/initechs/images/slides/semi.jpg","/initechs/images/slides/forklift.jpg", "/initechs/images/slides/box.jpg","/initechs/images/slides/cog.jpg");

	if( $('#content').length > 0){
		$('#content').before('<ul id="submenu"></ul>');
		$('#content div.module').each(function(){
			$('#submenu').append('<li><a href="#'+$(this).attr('id')+'">'+$(this).children('h3').html()+'</a></li>');
		});
	}

	$('#contact-form h3').before('<p class="close" rel="generated"><a href="">X</a></p>');
	$('#contact-form').css({
		position: 'absolute',
		top: '49px',
		right: 0,
		height: '1px'
	});

	// Billboard cycler
	var interrupt = false;
	var current = 'intro';
	$('#choose-intro a').bind("click", function(event){ 
		event.preventDefault();
		interrupt = true;
		current = $.changeSlide(current, 'intro');
	});
	$('#choose-wms a').bind("click", function(event){ 
		event.preventDefault();
		interrupt = true;
		current = $.changeSlide(current, 'wms');
	});
	$('#choose-tms a').bind("click", function(event){ 
		event.preventDefault();
		interrupt = true;
		current = $.changeSlide(current, 'tms');
	});
	$('#choose-inventory a').bind("click", function(event){ 
		event.preventDefault();
		interrupt = true;
		current = $.changeSlide(current, 'inventory');
	});
	$.timer(5000, function (timer) {
		if (!interrupt) {
			if( current == 'intro'){
				current = $.changeSlide(current, 'wms');
			} else if ( current == 'wms' ){
				current = $.changeSlide(current, 'tms');
			} else if ( current == 'tms' ){
				current = $.changeSlide(current, 'inventory');
			} else if ( current == 'inventory' ){
				current = $.changeSlide(current, 'intro');
			}
			timer.reset(5000);
		}else { 
			timer.stop();
		}
	});
	
	// Raquo trick
	$('a.more').append('<span> &raquo;</span>');

	if(!$.browser.msie){
		$('#submenu a[href*=#]:not(.formlink)').click(function() {
			$.scrollTo($(this).attr('href'), 400, 'easeInOutQuint');
			return false;
		});
	}
	if( !$.browser.msie || ($.browser.msie && $.browser.version > 6) ){
		$('body').append('<div id="listener" rel="generated">&nbsp;</div>');
		$(window).scroll(function () { 
			if($('#listener').offset().top > 150){
				$('body:not(.fixmenu)').addClass('fixmenu');
			}else{
				$('body.fixmenu').removeClass('fixmenu');
			}
		});
	}
	$('p.close a').click(function(event){
		event.preventDefault();
		if(animating == false){
			animating = true;
			$('#contact-form').animate({'height':'1px'}, 1000, 'easeInOutQuint',function(){
				animating = false;
				if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','block'); }
				if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','block'); }
				if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','block'); }
			});
			now = '';
		}
	});
	$('#free-demo-button').click(function(event){
		event.preventDefault();
		if(animating == false){
			if(now == 'free-demo'){
				animating = true;
				$('#contact-form').animate({'height':'1px'}, 1000, 'easeInOutQuint',function(){
					animating = false;
					$(this).css('overflow','hidden');
					if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','block'); }
					if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','block'); }
					if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','block'); }
				});
				now = '';
			}else if(now == 'contact-us'){
				animating = true;
				$('#contact-form').animate({'height':'1px'}, 1000, 'easeInOutQuint',function(){
					$('#contact-form h3').html(freeDemoTitle);
					$('#contact-form p.instructions').html(freeDemoInstructions);				
					$('#contact-form').animate({'height':($(window).height()-148)+'px'}, 1000, 'easeInOutQuint',function(){
						animating = false;
						$(this).css('overflow','auto');
						if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','none'); }
						if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','none'); }
						if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','none'); }
						$(this).focus();
					});
					now = 'free-demo';
				});
			}else{
				$('#contact-form h3').html(freeDemoTitle);
				$('#contact-form p.instructions').html(freeDemoInstructions);				
				animating = true;
				$('#contact-form').animate({'height':($(window).height()-148)+'px'}, 1000, 'easeInOutQuint',function(){
					animating = false;
					$(this).css('overflow','auto');
					if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','none'); }
					if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','none'); }
					if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','none'); }
					$(this).focus();
				});
				now = 'free-demo';
			}
		}
	});
	$('#contact-us-button').click(function(event){
		event.preventDefault();
		if(animating == false){
			if(now == 'contact-us'){
				animating = true;
				$('#contact-form').animate({'height':'1px'}, 1000, 'easeInOutQuint',function(){
					animating = false;
					$(this).css('overflow','hidden');
					if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','block'); }
					if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','block'); }
					if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','block'); }
				});
				now = '';
			}else if(now == 'free-demo'){
				animating = true;
				$('#contact-form').animate({'height':'1px'}, 1000, 'easeInOutQuint',function(){
					$('#contact-form h3').html(contactUsTitle);
					$('#contact-form p.instructions').html(contactUsInstructions);				
					$('#contact-form').animate({'height':($(window).height()-148)+'px'}, 1000, 'easeInOutQuint',function(){
						animating = false;
						$(this).css('overflow','auto');
						if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','none'); }
						if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','none'); }
						if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','none'); }
						$(this).focus();
					});
					now = 'contact-us';
					interrupt = true;
				});
			}else{
				$('#contact-form h3').html((contactUsTitle));
				$('#contact-form p.instructions').html(contactUsInstructions);				
				animating = true;
				$('#contact-form').animate({'height':($(window).height()-148)+'px'}, 1000, 'easeInOutQuint',function(){
					animating = false;
					$(this).css('overflow','auto');
					if($('#chooser').length>0 && $.browser.msie){ $('#chooser').css('display','none'); }
					if($('#submenu').length>0 && $.browser.msie){ $('#submenu').css('display','none'); }
					if($('#page h2').length>0 && $.browser.msie){ $('#page h2').css('display','none'); }
					$(this).focus();
				});
				now = 'contact-us';
				interrupt = true;
			}
		}
	});

	$('#content table tbody tr td:first-child').addClass('firstCell');
	$('#content table tbody tr:odd').addClass('odd');

	if( $('.changeSidebar').length > 0 ){
		$('#submenu').prepend('<li><a href="/?wave-model"><b>The WAVE Model</b></a></li>');
		$('#submenu').append('<li><a href="/?wave-wms">Warehouse Management</a></li>');
		$('#submenu').append('<li><a href="/?wave-tms">Transportation Management</a></li>');
		$('#submenu').append('<li><a href="/?full-feature-list">Full Feature List</a></li>');
	}

});