/*
 *  H10 App
 *
 *  www.hundred10.com
 *  info@hundred10.com
 *  @hundred10
 */

var H10 = {
	init : function () {
		// Cookie Handling
		H10.slideCookie();
		H10.getFeed(function () {
			// Main project components
			H10.drawItems();
			H10.orderItem();
			H10.proNav();
			// Main bio components
			H10.bioThumbs();
			H10.keysHandle();
		});
		H10.handleAddress();
		H10.proAddress();
	},
	
	jFeed: null,
	
	getFeed: function (callback) {
		"use strict";
		$.getJSON('http://h10.h10staging.com/api/v1/feed?callback=?', function (data) {
			H10.jFeed = data;
			callback.call();
		});
	},
	viewFeed : function () {
		return H10.jFeed
	},
	getItems: function () {
		"use strict";
		
		var i = 0,
			j = 0,
			output = '',
			sortItems = [],
			nItems = H10.jFeed.items.length;
		
		for (j; j < nItems; j += 1) {
			sortItems.push(j);
		}
		
		sortItems.sort(function(){
			return 0.5 - Math.random()
		});
		
		for (i; i < sortItems.length; i += 1) {
			// Filter project items only (exclude social items)
			if (H10.jFeed.items[sortItems[i]].type === "project") {
				output += '<div class="port-item" id="h10-' + H10.jFeed.items[sortItems[i]].type + '" alt="' 
				+ H10.jFeed.items[sortItems[i]].client +  '"><a class="anything" href="#" rel="address:/project/'+ sortItems[i] +'"><img src="files/projects/'
				+ H10.jFeed.items[sortItems[i]].thumb + '" alt="'
				+ H10.jFeed.items[sortItems[i]].client + '" width="235" height="150"><div class="item-info"><div class="client-name">'
				+ H10.jFeed.items[sortItems[i]].client + '</div><div class="client-service">'
				+ H10.jFeed.items[sortItems[i]].category + '</div></div></a></div>';
			} else if (H10.jFeed.items[sortItems[i]].type === "team") {
				output += '<div class="port-item" id="h10-' + H10.jFeed.items[sortItems[i]].type + '" alt="'
				+ H10.jFeed.items[sortItems[i]].name +  '"><a href="' + H10.jFeed.items[sortItems[i]].url + '"><img src="'
				+ H10.jFeed.items[sortItems[i]].img + '" alt="'
				+ H10.jFeed.items[sortItems[i]].name + '" width="235" height="150"><div class="item-info"><div class="client-name">'
				+ H10.jFeed.items[sortItems[i]].name + '</div><div class="client-service">'
				+ H10.jFeed.items[sortItems[i]].tag + '</div></div></a></div>';
			} else if (H10.jFeed.items[sortItems[i]].type === "social" && H10.jFeed.items[sortItems[i]].category === "twitter") {
				output += '<div class="port-item" style="cursor: default;" id="h10-' 
				+ H10.jFeed.items[sortItems[i]].type + '"><div class="social-info">' 
				+ H10.jFeed.items[sortItems[i]].text + '</div><div class="social-time"><abbr class="timeago" style="border: none;" title="' 
				+ H10.jFeed.items[sortItems[i]].created + '"></abbr> | <a href="' 
				+ H10.jFeed.items[sortItems[i]].url + '" target="blank">'  + H10.jFeed.items[sortItems[i]].category +  '</a></div></div>';
			} else if (H10.jFeed.items[sortItems[i]].type === "social" && H10.jFeed.items[sortItems[i]].category === "instagram") {
				output += '<div class="port-item" style="cursor: default;" id="h10-' 
					+ H10.jFeed.items[sortItems[i]].type + '"><a href="' + H10.jFeed.items[sortItems[i]].url + '" target="blank"><img src="' 
					+ H10.jFeed.items[sortItems[i]].image + '"></a></div>';
				} 
		}
		return output;
	},
	getItemsIE8: function () {
		"use strict";
		
		var i = 0,
			j = 0,
			output = '',
			sortItems = [],
			nItems = H10.jFeed.items.length;
		
		for (j; j < nItems; j += 1) {
			sortItems.push(j);
		}
		
		sortItems.sort(function(){
			return 0.5 - Math.random()
		});
		
		for (i; i < sortItems.length; i += 1) {
			// Filter project items only (exclude social items)
			if (H10.jFeed.items[sortItems[i]].type === "project") {
				output += '<div class="port-item" id="h10-' + H10.jFeed.items[sortItems[i]].type + '" alt="' 
				+ H10.jFeed.items[sortItems[i]].client +  '"><a class="anything" href="#" rel="address:/project/'+ sortItems[i] +'"><img src="files/projects/'
				+ H10.jFeed.items[sortItems[i]].thumb + '" alt="'
				+ H10.jFeed.items[sortItems[i]].client + '" width="235" height="150"><div class="item-info"><div class="client-name">'
				+ H10.jFeed.items[sortItems[i]].client + '</div><div class="client-service">'
				+ H10.jFeed.items[sortItems[i]].category + '</div></div></a></div>';
			}
		}
		return output;
	},
	drawItems : function () {
		"use strict";
			if ($('#port-wrap').length > 0) {
				var output = H10.getItems();
				$('#port-wrap').append(output);
				// Append clearfix after items loaded.
				$("#port-wrap").append('<div class="clearfix"></div>');
			}  else if ($('#port-wrap-ie').length > 0) {
				var output = H10.getItemsIE8();
				$('#port-wrap-ie').append(output);
				// Append clearfix after items loaded.
				$("#port-wrap-ie").append('<div class="clearfix"></div>');
			}
			// Show Items Info
			var $portItem = $(".port-item");
			
			$portItem.hover(function () {
				$(this).find(".item-info").stop(1,1).fadeIn("fast");
			}, function () {
				$(this).find(".item-info").stop(1,1).fadeOut("fast");
			});
			
			// Display and limit grid
			H10.showGrid();
			
			// Handle tweet times ** Plugin: timeago: a jQuery plugin, version: 0.9.3 (2011-01-21)
			$("abbr.timeago").timeago();
			
			// Needed for the address plugin to work
			$('a.anything').address();
			
	},
	showGrid : function () {
		"use strict";
		
		var scroll = 1,
			showItems = xItems(),
			nextItems = 8,
			effect = "slow",
			$items = $('.port-item'),
			allItems = $items.length,
			$viewMore = $('#view-work');
		
		if (typeof showItems === "undefined") {
			showItems = 12;
		}
	        
		// Show different amount of items depending on the windows height
		function xItems() {
			if (window.innerHeight < 800) {
				return 12;
			} else if (window.innerHeight < 1000) {
				return 16;
			} else if (window.innerHeight < 1200) {
				return 20;
			} else if (window.innerHeight < 1600) {
				return 24;
			}
		};
	        // Only show x items
	        $items.slice(showItems).hide();
	        
	        // Show next x items
	        var posScroll = 0;
	        
	        $viewMore.click(function(e){
	            $items.slice(showItems, showItems + nextItems).fadeIn(effect);
	            showItems += nextItems;
	            
	            // scroll after c0lick
	            if (scroll === 1) {
	            	$.scrollTo(posScroll + 400);
	            	posScroll += 400;
	            }
	            
	            // Remove assigned next div when there are no more items.
	            if (showItems >= allItems) {
	            	$(this).remove();
	            }
	            e.preventDefault();
	        });
	        
	},
	getAddress : function () {
		"use strict";
		
		var urlParts = $.address.pathNames(),
			viewURL = urlParts[1];
		
		return viewURL;
	},
	handleAddress : function () {
		"use strict";
		
		$.address.change(function(e) {
			if (e.pathNames[0] === 'project') {
					$('#slideshow').remove();
					$('header').find('#view-work').hide();
					H10.getFeed(function () {
						H10.viewProject();
						H10.relProject();
					});
				}
		});
	},
	proAddress : function () {
		$.address.change(function(e) {
			 if (e.pathNames[0] === 'all') {
				var itemCheck =setInterval(function(){
					 var $portItems = $('.port-item');
					 
					 if ($portItems.length > 0) {
						 
						 // Check everything loaded first
						 clearInterval(itemCheck);
						 
						// Add selected class to projects
				            $('nav').find('li:contains("Everything")').removeClass('selected');
				            $('nav').find('li:contains("Projects")').addClass('selected');
						 
						 $.each($portItems, function () {
				               if($(this).attr('id') === "h10-team" || $(this).attr('id') === "h10-social") {
				                 $(this).fadeOut(300, function () {
				                   $(this).remove();
				                 });
				               }
				         });
					 }
				 }, 50);
			 }  
		 });
	},
	viewProject: function () {
		"use strict";
		
		var i = 0,
			j = 0,
			htmlString = '',
			htmlString2 = '',
			$Detail = $('.port-detail'),
			viewItem = H10.getAddress(),
			$showPort = $('#port-detail-wrap'),
			proImages = H10.jFeed.items[viewItem].images.length,
			proServices = H10.jFeed.items[viewItem].services.length;
		
		// Scroll Window to top
		scroll(0,0);
		// Remove slideshow if present
		$('#port-wrap, #port-wrap-ie').fadeOut(300);
		// Remove Slideshow div
		$('#slideshow').remove();
		// Empty previous project data
		$Detail.find('h1').empty();
		$('.project-set > *').remove();
		$Detail.find('.left p').empty();
		$Detail.find('.right ul > li').remove();
		$Detail.find('.left .title-red').empty();
		$('.pro-related .rel-thumbs').remove();

		// Show the main Portfolio Wrap
		$showPort.fadeIn(800);
		
		// Get all available images.
		for (i; i < proImages; i += 1) {
			htmlString += '<img src="files/projects/' + H10.jFeed.items[viewItem].images[i] + '">';
		}
		// Hide project services for Phase I
		/*for (j; j < proServices; j += 1) {
			htmlString2 += '<li>' + H10.jFeed.items[viewItem].services[j] + '</li>';
		}*/
		// END
		// Project Title
		$Detail.find('h1').append(H10.jFeed.items[viewItem].client)
		
		// Project Category
		$Detail.find('.left .title-red').append(H10.jFeed.items[viewItem].category)
		
		// Project URL
		if (typeof H10.jFeed.items[viewItem].url === 'string') {
			$Detail.find('.left p').append('<a href="' + H10.jFeed.items[viewItem].url + '">' + H10.jFeed.items[viewItem].url + '</a>')
		}
		
		// Add all available project images
		$('.project-set').append(htmlString);
		
		// Add all services
		$Detail.find('.right ul').append(htmlString2);
		
		// Grid Icon: Close projecy div + clean up project details.
		$showPort.find("#proGrid").click(function () {
			$showPort.fadeOut(200);
			// Show the portfolio grid
			$('#port-wrap, #port-wrap-ie').fadeIn(200);
			
			// Show the view more button if there are still projects available
			$('#view-work').show();
			
			return false;
		});
	},
	
	relProject : function () {
		var i = 0,
			j = 0,
			relPro = [],
			output = '',
			ranItems = [],
			viewItem = H10.getAddress(),
			nItems = H10.jFeed.items.length,
			itemCat = H10.jFeed.items[viewItem].category;
		
		// Loop through the items and store related id's
		for (i; i < nItems; i += 1) {
			if (H10.jFeed.items[i].type === "project" && H10.jFeed.items[i].category == itemCat && viewItem != i) {
				relPro.push(i);
			}
		}
		
		relPro.sort(function() {
			return 0.5 - Math.random()
		});
		
		ranItems = relPro.splice(0,4);
		
		for (j; j < ranItems.length; j += 1) {
			output += '<div class="rel-thumbs" id="' + ranItems[j] + '" alt="' 
			+ H10.jFeed.items[ranItems[j]].client +  '"><a href="/index.php#/project/'+ ranItems[j] +'"><img src="files/projects/' 
			+ H10.jFeed.items[ranItems[j]].thumb + '" alt="'
			+ H10.jFeed.items[ranItems[j]].client + '" width="235" height="150"><div class="item-info"><div class="client-name">' 
			+ H10.jFeed.items[ranItems[j]].client + '</div><div class="client-service">' 
			+ H10.jFeed.items[ranItems[j]].category + '</div></div></a></div>';
		}
		
		$('.pro-related').prepend(output);
		
		// Show related items info
		var $relItem = $(".pro-related").find(".rel-thumbs");
		
		
		$relItem.hover(function(){
			$(this).find(".item-info").stop(1,1).fadeIn("fast");
		}, function(){
			$(this).find(".item-info").stop(1,1).fadeOut("fast");
		});
		
	},
	orderItem : function () {
		var i = 0,
			nPro = [],
			output = [],
			lastItem = 0,
			firstItem = 0;
		
			// Get the first and last id's only for projects;
			for (i; i < H10.jFeed.items.length; i+=1) {
				if (H10.jFeed.items[i].type === 'project') {
					nPro.push(i);
				}
			}
			
			firstItem = nPro[0];
			lastItem = nPro[nPro.length-1];
			
			output.push(firstItem, lastItem);
		
		return output;
	},
	proNav : function () {
		"use strict";
		
		var items = H10.orderItem();
		
		var i = 0,
			nPro = [],
			position = 0;
		
		// Get the first and last id's only for projects;
		for (i; i < H10.jFeed.items.length; i+=1) {
			if (H10.jFeed.items[i].type === 'project') {
				nPro.push(i);
			}
		}
		
		// Next Icon: OnClick next project
		$('#pNavigation').find('#next').click(function() {
			var pathNames = $.address.pathNames(),
				current = parseInt(pathNames[1]);

			for (var i in nPro) {
				if (nPro[i] === current) {
					position = i;
					
					break;
				}
			}
			
			var newPos = parseInt(position) + 1;
			
			var newPath = 'project/' + ( (H10.jFeed.items[nPro[newPos]]) ? (nPro[newPos]):items[0] );
			
			$.address.path(newPath);
			
			return false;
		});
		
		// Prev Icon: OnClick previous project
		$('#pNavigation').find('#prev').click(function() {
			var pathNames = $.address.pathNames(),
				current = parseInt(pathNames[1]);
			
			for (var i in nPro) {
				if (nPro[i] === current) {
					position = i;
					
					break;
				}
			}
			
			var newPos = parseInt(position) - 1;
			
			var newPath = 'project/' + (H10.jFeed.items[nPro[newPos]] ? (nPro[newPos]):items[1]);
			
			$.address.path(newPath);
			return false;
		});
		
		// Down Arrow Icon: Remove featured items after click.
		$('header').find('#view-work').click(function () {
			// Nav Everything Selected
			$('#slideshow').fadeOut(300);
			$('#port-wrap, #port-wrap-ie').delay(400).fadeIn(1000);
			return false;
		});
	},
	slideCookie : function () {
		if ($.cookie('H10 Cookie') === "true") {
			$('nav').find('li:contains("Everything")').addClass('selected');
			$("#slideshow").remove();
			$('#port-wrap, #port-wrap-ie').show();
		}
		$.cookie('H10 Cookie', "true");
		
		$('#logo').click(function () {
			$.cookie('H10 Cookie', null);
			$('nav').find('li:contains("Everything")').removeClass('selected');
		});
		
	},
	bioCounter : function () {
		"use strict";
		
	    var bioStats = $("body");
	    
	    if(bioStats.length > 0) {
	        var container = $(bioStats.find('.stat-number')[0]);
	        var count = container.text().replace(/[^\d]/g, '');
	        var total = parseInt(count, 10);
	        container.text('0');
	        if ($('#stat-john').length > 0) {
	        	animateStatsCount( container, total, '$' );
	        }
	        else if ($('#stat-Layne').length > 0) {
	        	animateStatsCount(container, total);
	        }
	        if ($('#stat-alo').length > 0) {
	        	animateStatsCount( container, total, null, 'GB' );
	        }
	        else if ($('#stat-steph').length > 0) {
	        	animateStatsCount(container, total);
	        }
	        else if ($('#stat-seb').length > 0) {
	        	animateStatsCount(container, total);
	        }
	        else if ($('#stat-jeff').length > 0) {
	        	animateStatsCount(container, total);
	        }
	        else if ($('#stat-becka').length > 0) {
	        	animateStatsCount(container, total);
	        }
	    }

		function animateStatsCount( container, total, dollar, gb) {
			
		    var i,
		        j,
		        arr,
		        str,
		        count,
		        dollar,
		        spd = 70,
		        rawCount = 0;
		    
		    var update = setInterval(function() {
		    	
		        
		        rawCount += (total - rawCount) * 0.30;
		        count = Math.round(rawCount);
		        
		        arr = count.toString().split('');
		        str = '';
		        i = arr.length;
		        j = 0;
		        
		        while(--i >= 0) {
		        	str = (i > 0 && (j++ % 3 == 2) ? ',': '') + arr[i] + str;
		        }
		        if (typeof dollar === 'string') {
		        	container.text(dollar + str);
		        }
		        else if (typeof gb === 'string') {
		        	container.text(str + gb);
		        }
		        else {
		        	container.text(str);
		        }
		        if(count >= total) {
		            clearInterval(update);
		        }
		        
		    }, 1000 / spd);
		}
	},
	bioThumbs : function () {
		// Show Items Info
		var $bioItem = $(".bio-thumbs");
			
			$bioItem.hover(function () {
				$(this).find(".item-info").stop(1,1).fadeIn("fast");
			}, function () {
				$(this).find(".item-info").stop(1,1).fadeOut("fast");
			});
	},
	keysHandle : function () {
		// --- Keyboard navigation 
		$(window).keydown(function(e) {
			
			switch (e.keyCode) {
				case 39:
					e.preventDefault();
					
					var items = H10.orderItem();
					
						var pathNames = $.address.pathNames(),
							current = parseInt(pathNames[1]);
						
						var newPath = 'project/' + ( (H10.jFeed.items[current+1].type === 'project') ? (current+1):items[0] );
						
						$.address.path(newPath);
						return false;
					break;
				case 37:
					e.preventDefault();
					
					var items = H10.orderItem();
					
						var pathNames = $.address.pathNames(),
						current = parseInt(pathNames[1]);
					
						var newPath = 'project/' + (H10.jFeed.items[current-1].type === 'project' ? (current-1):items[1]);
						
						$.address.path(newPath);
					break;
				case 27:
					e.preventDefault();
					break;
			}
		});
	}
};

window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var newarr=[].slice.call(arguments);(typeof console.log==='object'?log.apply.call(console.log,console,newarr):console.log.apply(console,newarr))}};(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try{console.log();return window.console}catch(err){return window.console={}}})());jQuery.cookie=function(key,value,options){if(arguments.length>1&&String(value)!=="[object Object]"){options=jQuery.extend({},options);if(value===null||value===undefined){options.expires=-1}if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days)}value=String(value);return(document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''))}options=value||{};var result,decode=options.raw?function(s){return s}:decodeURIComponent;return(result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null};(function($){$.timeago=function(timestamp){if(timestamp instanceof Date){return inWords(timestamp)}else if(typeof timestamp==="string"){return inWords($.timeago.parse(timestamp))}else{return inWords($.timeago.datetime(timestamp))}};var $t=$.timeago;$.extend($.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years",numbers:[]}},inWords:function(distanceMillis){var $l=this.settings.strings;var prefix=$l.prefixAgo;var suffix=$l.suffixAgo;if(this.settings.allowFuture){if(distanceMillis<0){prefix=$l.prefixFromNow;suffix=$l.suffixFromNow}distanceMillis=Math.abs(distanceMillis)}var seconds=distanceMillis/1000;var minutes=seconds/60;var hours=minutes/60;var days=hours/24;var years=days/365;function substitute(stringOrFunction,number){var string=$.isFunction(stringOrFunction)?stringOrFunction(number,distanceMillis):stringOrFunction;var value=($l.numbers&&$l.numbers[number])||number;return string.replace(/%d/i,value)}var words=seconds<45&&substitute($l.seconds,Math.round(seconds))||seconds<90&&substitute($l.minute,1)||minutes<45&&substitute($l.minutes,Math.round(minutes))||minutes<90&&substitute($l.hour,1)||hours<24&&substitute($l.hours,Math.round(hours))||hours<48&&substitute($l.day,1)||days<30&&substitute($l.days,Math.floor(days))||days<60&&substitute($l.month,1)||days<365&&substitute($l.months,Math.floor(days/30))||years<2&&substitute($l.year,1)||substitute($l.years,Math.floor(years));return $.trim([prefix,words,suffix].join(" "))},parse:function(iso8601){var s=$.trim(iso8601);s=s.replace(/\.\d\d\d+/,"");s=s.replace(/-/,"/").replace(/-/,"/");s=s.replace(/T/," ").replace(/Z/," UTC");s=s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2");return new Date(s)},datetime:function(elem){var isTime=$(elem).get(0).tagName.toLowerCase()==="time";var iso8601=isTime?$(elem).attr("datetime"):$(elem).attr("title");return $t.parse(iso8601)}});$.fn.timeago=function(){var self=this;self.each(refresh);var $s=$t.settings;if($s.refreshMillis>0){setInterval(function(){self.each(refresh)},$s.refreshMillis)}return self};function refresh(){var data=prepareData(this);if(!isNaN(data.datetime)){$(this).text(inWords(data.datetime))}return this}function prepareData(element){element=$(element);if(!element.data("timeago")){element.data("timeago",{datetime:$t.datetime(element)});var text=$.trim(element.text());if(text.length>0){element.attr("title",text)}}return element.data("timeago")}function inWords(date){return $t.inWords(distance(date))}function distance(date){return(new Date().getTime()-date.getTime())}document.createElement("abbr");document.createElement("time")}(jQuery));(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
