/*
 * 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. 
 *
 */

/* Copyright (c) 2009 Dimas Begunoff, http://www.farinspace.com
Licensed under the MIT license
http://en.wikipedia.org/wiki/MIT_License */
function imgpreload(a,b){if(b instanceof Function){b={all:b}}if(typeof a=="string"){a=[a]}var c=[];var t=a.length;var i=0;for(i;i<t;i++){var d=new Image();d.onload=function(){c.push(this);if(b.each instanceof Function){b.each.call(this)}if(c.length>=t&&b.all instanceof Function){b.all.call(c)}};d.src=a[i]}}if(typeof jQuery!="undefined"){(function($){$.imgpreload=imgpreload;$.fn.imgpreload=function(b){b=$.extend({},$.fn.imgpreload.defaults,(b instanceof Function)?{all:b}:b);this.each(function(){var a=this;imgpreload($(this).attr('src'),function(){if(b.each instanceof Function){b.each.call(a)}})});var c=[];this.each(function(){c.push($(this).attr('src'))});var d=this;imgpreload(c,function(){if(b.all instanceof Function){b.all.call(d)}});return this};$.fn.imgpreload.defaults={each:null,all:null}})(jQuery)}

/*!
 * jQuery Tools v1.2.6 - The missing UI library for the Web
 * 
 * scrollable/scrollable.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * jquery.event.wheel.js - rev 1 
 * Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
 * Liscensed under the MIT License (MIT-LICENSE.txt)
 * http://www.opensource.org/licenses/mit-license.php
 * Created: 2008-07-01 | Updated: 2008-07-14
 * 
 * -----
 * 
 */
(function(a){a.tools=a.tools||{version:"v1.2.6"},a.tools.scrollable={conf:{activeClass:"active",circular:!1,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:"> *",items:".items",keyboard:!0,mousewheel:!1,next:".next",prev:".prev",size:1,speed:400,vertical:!1,touch:!0,wheelSpeed:0}};function b(a,b){var c=parseInt(a.css(b),10);if(c)return c;var d=a[0].currentStyle;return d&&d.width&&parseInt(d.width,10)}function c(b,c){var d=a(c);return d.length<2?d:b.parent().find(c)}var d;function e(b,e){var f=this,g=b.add(f),h=b.children(),i=0,j=e.vertical;d||(d=f),h.length>1&&(h=a(e.items,b)),e.size>1&&(e.circular=!1),a.extend(f,{getConf:function(){return e},getIndex:function(){return i},getSize:function(){return f.getItems().size()},getNaviButtons:function(){return n.add(o)},getRoot:function(){return b},getItemWrap:function(){return h},getItems:function(){return h.find(e.item).not("."+e.clonedClass)},move:function(a,b){return f.seekTo(i+a,b)},next:function(a){return f.move(e.size,a)},prev:function(a){return f.move(-e.size,a)},begin:function(a){return f.seekTo(0,a)},end:function(a){return f.seekTo(f.getSize()-1,a)},focus:function(){d=f;return f},addItem:function(b){b=a(b),e.circular?(h.children().last().before(b),h.children().first().replaceWith(b.clone().addClass(e.clonedClass))):(h.append(b),o.removeClass("disabled")),g.trigger("onAddItem",[b]);return f},seekTo:function(b,c,k){b.jquery||(b*=1);if(e.circular&&b===0&&i==-1&&c!==0)return f;if(!e.circular&&b<0||b>f.getSize()||b<-1)return f;var l=b;b.jquery?b=f.getItems().index(b):l=f.getItems().eq(b);var m=a.Event("onBeforeSeek");if(!k){g.trigger(m,[b,c]);if(m.isDefaultPrevented()||!l.length)return f}var n=j?{top:-l.position().top}:{left:-l.position().left};i=b,d=f,c===undefined&&(c=e.speed),h.animate(n,c,e.easing,k||function(){g.trigger("onSeek",[b])});return f}}),a.each(["onBeforeSeek","onSeek","onAddItem"],function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}});if(e.circular){var k=f.getItems().slice(-1).clone().prependTo(h),l=f.getItems().eq(1).clone().appendTo(h);k.add(l).addClass(e.clonedClass),f.onBeforeSeek(function(a,b,c){if(!a.isDefaultPrevented()){if(b==-1){f.seekTo(k,c,function(){f.end(0)});return a.preventDefault()}b==f.getSize()&&f.seekTo(l,c,function(){f.begin(0)})}});var m=b.parents().add(b).filter(function(){if(a(this).css("display")==="none")return!0});m.length?(m.show(),f.seekTo(0,0,function(){}),m.hide()):f.seekTo(0,0,function(){})}var n=c(b,e.prev).click(function(a){a.stopPropagation(),f.prev()}),o=c(b,e.next).click(function(a){a.stopPropagation(),f.next()});e.circular||(f.onBeforeSeek(function(a,b){setTimeout(function(){a.isDefaultPrevented()||(n.toggleClass(e.disabledClass,b<=0),o.toggleClass(e.disabledClass,b>=f.getSize()-1))},1)}),e.initialIndex||n.addClass(e.disabledClass)),f.getSize()<2&&n.add(o).addClass(e.disabledClass),e.mousewheel&&a.fn.mousewheel&&b.mousewheel(function(a,b){if(e.mousewheel){f.move(b<0?1:-1,e.wheelSpeed||50);return!1}});if(e.touch){var p={};h[0].ontouchstart=function(a){var b=a.touches[0];p.x=b.clientX,p.y=b.clientY},h[0].ontouchmove=function(a){if(a.touches.length==1&&!h.is(":animated")){var b=a.touches[0],c=p.x-b.clientX,d=p.y-b.clientY;f[j&&d>0||!j&&c>0?"next":"prev"](),a.preventDefault()}}}e.keyboard&&a(document).bind("keydown.scrollable",function(b){if(!(!e.keyboard||b.altKey||b.ctrlKey||b.metaKey||a(b.target).is(":input"))){if(e.keyboard!="static"&&d!=f)return;var c=b.keyCode;if(j&&(c==38||c==40)){f.move(c==38?-1:1);return b.preventDefault()}if(!j&&(c==37||c==39)){f.move(c==37?-1:1);return b.preventDefault()}}}),e.initialIndex&&f.seekTo(e.initialIndex,0,function(){})}a.fn.scrollable=function(b){var c=this.data("scrollable");if(c)return c;b=a.extend({},a.tools.scrollable.conf,b),this.each(function(){c=new e(a(this),b),a(this).data("scrollable",c)});return b.api?c:this}})(jQuery);


/**
 * jQuery.browser.mobile (http://detectmobilebrowser.com/)
 *
 * jQuery.browser.mobile will be true if the browser is a mobile device
 *
 **/
(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);

/* Author: Nicole Sciacca, nicole@nahdesign.com */
/*global window, clearTimeout, setTimeout, $ */
/*jslint unparam: true*/
var serverPath = 'http://www.nahdesign.com/';
var videoPath = 'http://s152447388.onlinehome.us/'

var offsetheight = 175+100; // NS: added for adjusting body margin

// Time Control
var Time = {
	scroll: 775,
	projectHover: 200,
	openFades: 300,
	closeFades: 180,
	scale: 200,
	slide: 400,
	imgFadeDown: 250,
	imgFadeUp: 200,
	arrowFadeUp: 400,
	arrowFadeDown: 400,
	arrowPause: 2000,
	arrowThres: 100,
	fullscreenOff: 100,
	galleryScroll: 500,
	easeScroll: 'easeInOutQuart',
	easeScale: 'easeOutQuad',
	easeSlide: 'easeInOutQuart'
};

// Settings
var ProjectSettings = {
	height: 555,
	width: 987,
	closedHeight: 62,
	thumbSpace: 331,
	bgOffset: -246,
	bgFade: 0,
	header: 175,
	opened: [],
	copyHeight: 250,
	version: 0,
	topAdjust: 125
};

// Project "Class" prototype
function Project(container) {
	this.container = container;
	this.active = '';
	this.prev = '';
	this.next = '';
	this.scroller = '';
	this.hover = false;
	this.count = 3;
	this.thread = null;
	this.player = null;
	this.status = 0;
	this.top = container.offset().top;
	this.fullscreenEvents = null;
	this.body = null;
}

// set up reel
function resetReel () {
	var media = videoPath + 'mp4/' + $.trim($('#reel .jp-config').text()),
	  poster = $.trim($('#reel .jp-config-poster').text()),
	  $reel = $('#reel').data('reel');
	clearTimeout($reel.thread); 
	$('#jquery_jplayer_reel').jPlayer('setMedia', {
		m4v: media,
		poster: poster
	});
  if (ProjectSettings.version !== 3) {
		$('#jp_container_reel .jp-gui').addClass('locked');
	}
}

// close open projects
function resetProjects () {
	if (ProjectSettings.opened.length) {
		var x;
		for (x in ProjectSettings.opened) {
			if (ProjectSettings.opened[x] !== false) {
				ProjectSettings.opened[x].close(ProjectSettings.opened[x]);
			}
		}
	}
}

// versions
function setDisplay(version) {
	var scroller = $('body').data('scroller');
	if (version == 1) {
		ProjectSettings.version = 1;
		offsetheight = 150;
		ProjectSettings.header = 50;
		$('body').addClass('smaller');
	} else {
		ProjectSettings.version = 0;
		offsetheight = 275;
		ProjectSettings.header = 175;	
		$('body').removeClass('smaller');
	}
	if (scroller) {
		$('#' + scroller.id).css('margin-top', ProjectSettings.header + 'px');
		scroller.onResize();
	}
}

// jQuery on document ready...
$(function () {
	if ($('body').hasClass('front')) {
	
		var scroller = null;
	
		// mobile check
		if ($.browser.mobile) {
			ProjectSettings.version = 3;
			$('head').append('<link rel="stylesheet" href="'+serverPath+'sites/all/themes/nah/css/mobile.css" />');
		} 
		else { // only use nicescroll on desktops
			scroller = $('body').niceScroll({
				cursorborderradius: '0',
				cursorborder: '0',
				cursorcolor: '#CCC',
				cursorwidth: '6px'
			});
			var difference = (($(window).width() - $('#wrapper').width()) / 2);
			$('#' + scroller.id).css('right', difference + 'px');
			$('#' + scroller.id).css('margin-top', ProjectSettings.header + 'px');
		}
		$('body').data('scroller', scroller);
	
		// small window check
		if ($(window).height() <= 800 && ProjectSettings.version !== 3) {
			setDisplay(1);
		}	
		
		// reel setup
		var reel = new Project($('#jp_container_reel'));		
		$('#reel').data('reel', reel);
		$('#reel .jp-config-poster img').imgpreload({
			all: function()	{
				var img = $('#reel .jp-config-poster img'),
				  container = img.parent(),
					poster = img.attr('src');
				img.remove();
				container.text(poster);
				reel.video(reel);
			}
		});
		
		// initialize each project - preload and intialize
		$('article').each(function () {
			// preload bg and remove titles
			var $article = $(this);		
			$('img.bg', $article).imgpreload({
				all: function()	{
						var project = new Project($article);		
						Project.prototype.init(project);
						$article.data('project', project);
				}
			});	
		});

		// set up nav	
		$('section').each(function () {
			var offset = $(this).position().top - ProjectSettings.header;
			$(this).data('offset',offset);
		});
		$('nav a').each(function () {
			var $link = $(this),
			 href = $link.attr('href');			
			$link.data('href', href);
			// track page link clicks
			_gaq.push(['_trackPageview', '/nav/'+href]);			
			$link.removeAttr('href');
			$link.click(function (e) {
				e.preventDefault();
				// close all open + pause any players
				$.jPlayer.pause();
				resetProjects();
				$('nav a').removeClass('active');
				$(this).addClass('active');
				var loc = $(this).data('href'),
					scroller = $('body').data('scroller'),
					offset = $(loc).data('offset');
					resetReel();
				if (ProjectSettings.version === 3) { // mobile 
					offset += (ProjectSettings.header - 6);
				} else if (ProjectSettings.version === 1) { // small version
					offset -= 12;
				}
				if (scroller) {	
					scroller.stop();
				} 
				$('html,body').stop(true).animate({scrollTop: offset}, Time.scroll, 'easeInOutQuart', function() {
					if (loc == '#reel') {	$('#jp_container_reel .jp-video-play').click();	}
				});					
			});
		});	

		// resizing of window
		$(window).resize(function () {
			if (scroller) {
				var difference = (($(window).width() - $('#wrapper').width()) / 2);
				if (difference > 0) { $('#' + scroller.id).css('right', difference + 'px'); }
				else { $('#' + scroller.id).css('right', '-1px');}			
				if ($(window).height() <= 800 && ProjectSettings.version === 0) {
					setDisplay(1);
				} else if ($(window).height() > 800 && ProjectSettings.version === 1) {
					setDisplay(0);
				}				
			}					
		});
	}
	
	else if ($('.project').length){ // project page
		
		var body = $('.body'),
			scrollHeight = body.height();
		body.css({height: ProjectSettings.copyHeight + 'px'});	
		if (scrollHeight > ProjectSettings.copyHeight) {
			$('.body').niceScroll({
				cursorborderradius: '0',
				cursorborder: '0',
				cursorcolor: '#CCC',
				cursorwidth: '6px',
				zindex: 200,
				railoffset: { left: -1},
				autohidemode: false
			});
		}
		var project = new Project($('article'));		
		project.attachEvents(project);
		if ($('.jp-jplayer', project.container).length) {// jplayer	
			project.video(project);
			project.player = $('.jp-jplayer', project.container);
		}
		$('article').data('project', project);
		$('.loader', project.container).remove();
		project.container.removeClass('loading');
		if ($('img', project.container).length) {
			$('img', project.container).each(function () {
				var $image = $(this);
				if ($image.attr('src') !== $image.attr('data-small')) {
					$image.attr('src',$image.attr('data-small'));
				}
			});													
			$('.gallery img', project.container).imgpreload({
				each: function() {
						var $this = $(this);
				    $this.data('title', $this.attr('title'));
				    $this.removeAttr('title');
				}
			});			
		}
		// bgcolor
		$('#bgColor').change(function() {
			var val = $(this).val();
			project.container.add($(this)).add('.banner.on').css('backgroundColor','#'+val);
		});
	}	
	
	// contact form
	if ($('#contact-site-form').length) {
		$('#edit-submit').click(function() {
			$(this).val('Sending...');
			$(this).attr('disabled','disabled');
			$('#contact-site-form').submit();
		});
	}
});

// Project prototype functions
Project.prototype = {
	init: function (thisProject) {
		$('.loader', thisProject.container).remove();
		thisProject.container.removeClass('loading');
		thisProject.container.bind('mouseup', function () { thisProject.trigger(thisProject); });
		thisProject.bindHover(thisProject);
		thisProject.copy = $('.body', thisProject.container).html();
		$('.body', thisProject.container).remove();
		if ($('.jp-jplayer', thisProject.container).length) {// jplayer	
			thisProject.player = $('.jp-jplayer', thisProject.container);
		}
		if (ProjectSettings.version === 1) {
			thisProject.top += ProjectSettings.topAdjust;
		}
	},

	bindHover: function (thisProject) {
		$(thisProject.container).bind('mouseenter', function () {
			if (!thisProject.container.hasClass('open')) {
				$('.bg', this).stop().fadeTo(Time.projectHover, 0.65);
				var $parent = $('.title', this),
					parentWidth = null;
				if (!($parent.data('width'))) { $parent.data('width', $parent.width()); }
				parentWidth = $parent.data('width');
				if (parentWidth < 0) {	parentWidth = $parent.data('width', $parent.width());	}
				$('h1', $parent).stop(true).css({width: '0', visibility: 'visible'}).animate({width: parentWidth + 'px'},  Time.projectHover);
			}
		});
		$(thisProject.container).bind('mouseleave', function () {
			if (!thisProject.container.hasClass('open')) {
				$('.bg', this).stop().fadeTo(Time.projectHover, 1);
				var $parent = $('.title', this);
				$('h1', $parent).stop(true).animate({width: '0px'}, Time.projectHover, function () {
					$(this).css({width: $parent.data('width') + 'px', visibility: 'hidden'});
				});
			}
		});
	},
	
	openComplete: function (thisProject) {	
		$('.bg', thisProject.container).delay(200).fadeTo(300, ProjectSettings.bgFade);

		// initialize video
		if ($('.jp-config', thisProject.container).length) {
			$('.visual', thisProject.container).delay(466).fadeIn(Time.openFades);		
			thisProject.video(thisProject);
		} else {
			$('.visual', thisProject.container).delay(666).fadeIn(Time.openFades);		
		}
		
		// turn on copy
		$('.copy', thisProject.container).show();
		$('.copy header', thisProject.container).delay(666).fadeIn(Time.openFades);

		var body = $('<div class="body">' + thisProject.copy + '</div>');
		body.css('visibility','hidden');
		$('.copy', thisProject.container).append(body);
		var scrollHeight = body.height();
		body.css({visibility: 'visible'});		
		if (scrollHeight > ProjectSettings.copyHeight) {
			$(body).css('height', ProjectSettings.copyHeight + 'px');
		}
		$(body).delay(666).fadeIn(Time.openFades, function () {
			if (scrollHeight > ProjectSettings.copyHeight) {
				thisProject.scroller = $(this).niceScroll({
					cursorborderradius: '0',
					cursorborder: '0',
					cursorcolor: '#CCC',
					cursorwidth: '6px',
					zindex: 200,
					railoffset: { left: -1},
					autohidemode: false
				});
			}
		});

		// gallery -- 31 frame delay = 1033, 5 fr fade 166
		$('.gallery', thisProject.container).delay(1000).fadeIn(Time.openFades, function () {
			if (thisProject.status === 0) {
				thisProject.attachEvents(thisProject);
			} else {
				$('.copy .body', thisProject.container).resize();
				if (thisProject.scroller) {
					$('#' + thisProject.scroller.id).show();
				}
			}
		});
		
		// track opening of project as page click
		_gaq.push(['_trackPageview', '/'+thisProject.container.attr('id')]);
	},

	open: function (thisProject) {
		// set active project,remove events,pause videos
		if (!thisProject.container.hasClass('closing')) {
			$(thisProject.container).addClass('open');
			$(thisProject.container).unbind();
			ProjectSettings.opened.push(thisProject);

			var $parent = $('.title', thisProject.container),
				$bg = $('.bg', thisProject.container);

			// version adjustment
/*			if (ProjectSettings.version === 1) { // small header
				offset -= ProjectSettings.topAdjust;
			} else if (ProjectSettings.version === 3) { // mobile 
				offset = thisProject.top - 6;
			}
*/
			// stop animation of rollover, scroll to new location
			$('h1', $parent).stop(true).css({width: $parent.data('width') + 'px', visibility: 'hidden'});
//			if (scroller) {	scroller.stop();}
//			$('html,body').stop(true).animate({scrollTop: offset}, Time.scroll, Time.easeScroll);

			thisProject.focusOn(thisProject);

			// move image to correct location
			$bg.stop(true).animate({top: '0px', opacity: 1}, Time.scroll, Time.easeScroll);

			// open height of project		
			$(thisProject.container).animate({ height: ProjectSettings.height + 'px'
				}, Time.scroll, Time.easeScroll, function () {

					// need to recheck if this is closing...
					if (!thisProject.container.hasClass('closing')) {

						if ($('img', thisProject.container).length) {						
							// loading icon
							var $loader = $('<div class="loader">');
							thisProject.container.append($loader);
							
							// preload images
							// initialize each project - preload and intialize
							$('img', thisProject.container).each(function () {
								var $image = $(this);
								if ($image.attr('src') !== $image.attr('data-small')) {
									$image.attr('src',$image.attr('data-small'));
								}
							});										
							$('img', thisProject.container).imgpreload({
								each: function() {
										var $this = $(this);
								    $this.data('title', $this.attr('title'));
								    $this.removeAttr('title');
								},
								all: function()	{
									// video projects
									if (thisProject.player) {
										var poster = $.trim($('.jp-config-poster', thisProject.container).text());
										$.imgpreload([poster],function() {
											$loader.remove();
											thisProject.openComplete(thisProject);
										});									  
									} else {
										$loader.remove();
										thisProject.openComplete(thisProject);
									}
								}
							});		
						}
						else {
							thisProject.openComplete(thisProject);
						}
				 } 
			});
		}
	},
	
	focusOn: function (thisProject) {
		var offset = thisProject.top - ProjectSettings.header,
			scroller = $('body').data('scroller');
		// version adjustment
		if (ProjectSettings.version === 1) { // small header
			offset -= ProjectSettings.topAdjust;
		} else if (ProjectSettings.version === 3) { // mobile 
			offset = thisProject.top - 6;
		}
		if (scroller) {	scroller.stop();} 
		$('html,body').stop(true).animate({scrollTop: offset}, Time.scroll, Time.easeScroll);		
	},

	close: function (closed) {
		// remove scroller and body	
		if (!closed.container.hasClass('closing')) {
			closed.container.addClass('closing');
			$('#' + closed.scroller.id).remove();
			$('.body', closed.container).remove();

			if (closed.player) {
				$('.jp-restore-screen', closed.container).click();
				$('.jp-video-play', closed.container).unbind('click');
				closed.player.jPlayer('destroy');
			}
			$('.enlarge', closed.container).click();

			if ($('.copy, .copy .body, .visual, .copy header, .gallery').length) {
				$('.copy, .copy .body,.visual,.copy header, .gallery', closed.container).stop(true, true).hide();
			}

			$('.bg', closed.container).stop(true).animate({ top: ProjectSettings.bgOffset + 'px', opacity: 1}, Time.scroll, Time.easeScroll);

			$(closed.container).stop(true, true).animate({ height: ProjectSettings.closedHeight + 'px'}, Time.scroll, Time.easeScroll, function () {
				$(closed.container).removeClass('open');
				closed.container.bind('mouseup', function () { closed.trigger(closed); });
				closed.bindHover(closed);
				var x;
				for (x in ProjectSettings.opened) {
					if (ProjectSettings.opened[x] === closed) {
						ProjectSettings.opened.splice(x, 1);
						closed.container.removeClass('closing');
					}
				}
			});
		}
	},

	trigger: function (thisProject) {
		// don't allow anything to happen to the already open project
		if (!($(thisProject.container).hasClass('open'))) {
			// reset reel
			//$('#jquery_jplayer_reel').jPlayer('pause');
			resetReel();
			resetProjects();
			thisProject.open(thisProject);
		}
	},

	attachEvents: function (thisProject) {
		// initialize image scrollers,text scroller,player ref
		thisProject.scollersInit();

		$('.scrollable .items div', thisProject.container).bind('click', function () {
			thisProject.scale(thisProject, this);
		});

		if (!thisProject.player) { // image
			$('.visual.image', thisProject.container).bind('click', function () {
				thisProject.scale(thisProject, this);
			});
		}

		thisProject.status = 1;
	},

	scollersInit: function () {
		var thisProject = this;
		$('.scrollable', thisProject.container).scrollable({size: 1, touch: false, easing: Time.easeScroll, speed: Time.galleryScroll});
		$('.browse', this.container).hide();
		thisProject.api = $('.scrollable', thisProject.container).data('scrollable');

		if (thisProject.api) {
			// needed next?
			if (thisProject.api.getSize() <= thisProject.count)	{
				$('a.next', thisProject.container).addClass('disabled');
			}
			if (ProjectSettings.version === 3) { // show browse for mobile
				$('.browse', thisProject.container).not('.disabled').fadeIn(Time.arrowFadeUp);			
			}
			
			// on scroll,after scroll events		
			thisProject.api.onBeforeSeek(function (event, index) {
				if (this.getIndex() >= this.getSize() - thisProject.count) {
					if (index > this.getIndex()) {
						return false; // Cancel navigation
					}
				}
			});
			thisProject.api.onSeek(function (event, index) {
			  // Check to see if we're at the end
				if (this.getIndex() >= this.getSize() - thisProject.count) {
					// Disable the Next link
					$('a.next', thisProject.container).addClass('disabled');
				}
				if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
					$('.browse', thisProject.container).not('.disabled').show();
					$('.browse.disabled', thisProject.container).hide();
				} else {
					$('.browse', thisProject.container).not('.disabled').fadeIn(Time.arrowFadeUp);
					$('.browse.disabled', thisProject.container).fadeOut(Time.arrowFadeDown);
				}
			});

			if (ProjectSettings.version !== 3) { // do not bind hovers on mobile ver
				// small thumb gallery events
				$('.gallery .items div', thisProject.container).bind('mousemove', function () {
					if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
						$('.browse', thisProject.container).not('.disabled').show();
					} else {
						$('.browse', thisProject.container).not('.disabled').fadeTo(0, 1).fadeIn(Time.arrowFadeUp);
					}
					thisProject.thread = thisProject.arrowOff(thisProject, '.browse');
				});
			
				$('.browse', thisProject.container).hover(
					function () {	clearTimeout(thisProject.thread); },
					function () {	thisProject.thread = thisProject.arrowOff(thisProject, '.browse'); }
				);
				$('.gallery .items', thisProject.container).bind('mouseout', function () {
					thisProject.thread = thisProject.arrowOff(thisProject, '.browse', Time.arrowThres);
				});
			}
		}
	},

	scale: function (thisProject, media) {
//		$(media).stop(true).fadeTo(0, 1);
		thisProject.focusOn(thisProject);
		if ($(media).hasClass('active')) {
			thisProject.scaleDown(thisProject, media);
		} else {
			thisProject.scaleUp(thisProject, media);
		}
	},

	scaleUp: function (thisProject, media) {
		var $ref_media = $('img',media),
			$media = $('<img class="enlarge sliding" src="' + $ref_media.attr('data-large') + '" alt="' + $ref_media.attr('alt') + '">'),
			pos = $ref_media.parent().position(),
			adjustLeft = 0,
			bottom = 0,
			num = 0,
			main = false;
			
		$media.data('title',$ref_media.data('title'));
		$('.gallery .items div', thisProject.container).unbind('mousemove');
		$('.browse', thisProject.container).hide();
		
		// take our cloned image, place it on top of our reference
		if ($ref_media.hasClass('main')) {
			main = true;
		}
		else {
			num = thisProject.api.getIndex();
			adjustLeft = pos.left - (num * ProjectSettings.thumbSpace);
		}	

		$ref_media.addClass('active');	
		$media.css({
			bottom: bottom + 'px',
			left: adjustLeft + 'px',
			height: $ref_media.height() + 'px',
			width: $ref_media.width() + 'px'
		});
		
		if (main) {	$media.css({ top: '0px'	}); bottom = 206;	}
		
		// pause video
		if (thisProject.player) {
			thisProject.player.jPlayer('pause');
		}
		
		// loading icon
		var $loader = $('<div class="imgloader">');
		$loader.css({
			bottom: bottom + 'px',
			left: adjustLeft + 'px',
			height: $ref_media.height() + 'px',
			width: $ref_media.width() + 'px'
		});
	  thisProject.container.append($loader);
		
		// preload it, then position/animate
		$media.imgpreload({
			all: function()	{
				$loader.remove();	
				thisProject.container.append($media);	
				
				// save the image position for later,stop the player,set zindex
				thisProject.active = $media.position();
				thisProject.active.height = $media.height();
				thisProject.active.width = $media.width();
				
				// IE7 fix, not sure this is needed anymore
				$('.browse', thisProject.container).add('#'+thisProject.scroller.id).addClass('pushBack');
				
				// set class,determine offset and begin animation		
				$media.animate({
					height: ProjectSettings.height + 'px',
					width: ProjectSettings.width + 'px',
					bottom: '0px',
					left: '0px'
				}, Time.scale, Time.easeScale, function () {

					// oncomplete of scale up,turn on gallery nav
					$media.bind('click', function () { thisProject.scale(thisProject, $ref_media); });
					if (bottom !== 206) {	
						thisProject.fullscreen(thisProject, $ref_media);
					}
				});
			}
		});
	},

	scaleDown: function (thisProject, media) {
		// turn off gallery nav	
		var $ref_media = $(media),
			$ref_parent = $ref_media.parent(),
		 	$media = $('.enlarge',thisProject.container);
		$('.lgBrowse', thisProject.container).stop(true).hide();

		// animate down the image
		$media.unbind('mousemove');
		$media.unbind('click');
		
		$media.animate({
			top: thisProject.active.top + 'px',
			height: thisProject.active.height + 'px',
			width: thisProject.active.width + 'px',
			left: thisProject.active.left + 'px'
		}, Time.scale, Time.easeScale, function () {
			// oncomplete of scale down: remove active,zindex,start player...
			$ref_media.removeClass('active');
			$media.remove();

			// IE7 fix, not sure this is needed anymore
			$('.browse', thisProject.container).add('#'+thisProject.scroller.id).removeClass('pushBack');
			
			// settimeout + rebind
			if ($ref_parent.index() === $($ref_parent.siblings()).length) { $('a.next', thisProject.container).addClass('disabled'); }
			$('.browse.disabled', thisProject.container).hide();
			$('.gallery .items div', thisProject.container).bind('mousemove', function () {
				if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
					$('.browse', thisProject.container).not('.disabled').show();
				} else {
					$('.browse', thisProject.container).not('.disabled').fadeTo(0, 1).fadeIn(Time.arrowFadeUp);
				}
				thisProject.thread = thisProject.arrowOff(thisProject, '.browse');
			});			
		});
	},

	fullscreen: function (thisProject, media) {
		var $ref_media = $(media),
		  $ref_parent = $ref_media.parent(),
			index = $ref_parent.index(),  
			$media = $('.enlarge',thisProject.container),
			$prev = $('.lgPrev', thisProject.container),
			$next = $('.lgNext', thisProject.container),
			$nextItem = null,
			$prevItem = null;
		$prev.unbind('click');
		$next.unbind('click');

		// prev button
		if (index > 0) {
			$prev.removeClass('disabled');
			if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
				$prev.show(0, function () {
					$prevItem = $($('.scrollable .items div', thisProject.container)[index - 1]);
					$(this).bind('click', function () {
						thisProject.slide(thisProject, $media, $prevItem, 'right');
					});
				});
			} else {
				$prev.fadeTo(0, 1).fadeIn(Time.arrowFadeUp, function () {
					$prevItem = $($('.scrollable .items div', thisProject.container)[index - 1]);
					$(this).bind('click', function () {
						thisProject.slide(thisProject, $media, $prevItem, 'right');
					});
				});
			}
		} else {
			$prev.addClass('disabled');
		}

		// next button
		if (index < ($('.scrollable .items div', thisProject.container).length - 1)) {
			$next.removeClass('disabled');
			if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
				$next.show(0, function () {
					$nextItem = $($('.scrollable .items div', thisProject.container)[index + 1]);
					$(this).bind('click', function () {
						thisProject.slide(thisProject, $media, $nextItem, 'left');
					});
				});
			} else {
				$next.fadeTo(0, 1).fadeIn(Time.arrowFadeUp, function () {
					$nextItem = $($('.scrollable .items div', thisProject.container)[index + 1]);
					$(this).bind('click', function () {
						thisProject.slide(thisProject, $media, $nextItem, 'left');
					});
				});
			}
		} else {
			$next.addClass('disabled');
		}

		// mousemove event for media
		$media.bind('mousemove', function () {
			if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
				$('.lgBrowse', thisProject.container).not('.disabled').show();			
			} else {
				$('.lgBrowse', thisProject.container).not('.disabled').fadeTo(0, 1).fadeIn(Time.arrowFadeUp);
			}
			thisProject.thread = thisProject.arrowOff(thisProject, '.lgBrowse');
		});

		// set events + first timeout
		thisProject.thread = thisProject.arrowOff(thisProject, '.lgBrowse');
		if (!thisProject.fullscreenEvents && ProjectSettings.version !== 3) { // do not bind hovers on mobile ver
			$('.lgBrowse', thisProject.container).hover(
				function () {	clearTimeout(thisProject.thread); },
				function () {	thisProject.thread = thisProject.arrowOff(thisProject, '.lgBrowse'); }
			);
			thisProject.fullscreenEvents = true;
		}
		
	},

	arrowOff: function (thisProject, selector, time) {
		clearTimeout(thisProject.thread);
		if (!time) { time = Time.arrowPause; }
		var thread = setTimeout(function () {
			if ( ProjectSettings.version !== 3) {			
				if ($.browser.msie) { // ie needs to show/hide, not fade due to transparent png issue
					$(selector, thisProject.container).not('.disabled').stop(true).hide();
				}	else {
					$(selector, thisProject.container).not('.disabled').stop(true).fadeOut(Time.arrowFadeDown);
				}
			}
		}, time);
		return thread;
	},

	caption: function (img) {
		var text = $(img).data('title'),
		  container = $(img).parent(),
			caption = $('.caption span', container),
			captionwrp = null,
			disabled = false;
		if (!text) {
			text = '';
			disabled = true;
		}
		if (caption.length === 0) {
			captionwrp = $('<div class="caption"><span>' + text + '</span></div>');
			container.append(captionwrp);
			caption = $('span', captionwrp);
		} else {	$(caption).text(text);}
		if (disabled) {	caption.addClass('empty'); } 
		else { caption.removeClass('empty');	}
	},

	slide: function (thisProject, item1, item2, direction) {
		thisProject.focusOn(thisProject);

		// positions and movement vars
		$('.lgBrowse', thisProject.container).unbind('click');
		
		var move = ProjectSettings.width,
		  item2_img = $('img',item2),
			$sliding = $('<img class="enlarge sliding" src="' + item2_img.attr('data-large') + '" alt="' + item2_img.attr('alt') + '">'),
			item2_left = item1.position().left + item1.width(),
			item1_moveTo = item1.position().left - move,
			item2_moveTo = item1.position().left,
			seek = null;
			
		$sliding.data('title',item2_img.data('title'));	
			
		if (direction === 'right') {
			item2_left = item1.position().left - item1.width();
			item1_moveTo = item1.position().left + move;
		}	
			
		$sliding.css({bottom: '0px',left: item2_left + 'px'	});
		$sliding.bind('click', function () { thisProject.scale(thisProject, item2_img); });
		thisProject.container.append($sliding);						

		// do we need to hide the scrollers?
		if (item2.index() === $(item2.siblings()).length) {
			$('.lgNext', thisProject.container).hide();
		} else if (item2.index() === 0) {
			$('.lgPrev', thisProject.container).hide();
		}

		// setup for move
		item2_img.addClass('active');
		thisProject.next = item2.position();
		thisProject.next.top = 372; // override
		thisProject.next.left = 660; // override		
		thisProject.next.height = item2.height();
		thisProject.next.width = item2.width();
		thisProject.prev = thisProject.active;
		
		// loading icon
		var $loader = $('<div class="loader">');
		thisProject.container.append($loader);

	
		// preload it, then position/animate
		$sliding.imgpreload({
			all: function()	{
				$loader.remove();
				
				// animate
				item1.animate({	left: item1_moveTo }, Time.slide, Time.easeSlide, function () {
					item1.remove();
				});

				$sliding.animate({	left: item2_moveTo }, Time.slide, Time.easeSlide, function () {
					$(this).removeClass('sliding');
					thisProject.active = thisProject.next;
					thisProject.fullscreen(thisProject, item2_img);
					seek = item2.index() - 2;
					if (seek < 0) { 
						seek = 0; 
						thisProject.next.left = item2.index() * 330;
					}
					thisProject.api.seekTo(seek, 0);
				});				
			}
		});		
	},
	
	video: function (thisProject) {
		var media = videoPath + 'mp4/' + $.trim($('.jp-config', thisProject.container).text()),
			nohdmedia = videoPath + 'mp4/' + $.trim($('.jp-config-no-hd', thisProject.container).text()),
		  poster = $.trim($('.jp-config-poster', thisProject.container).text()),
			jpID = $('.jp-config', thisProject.container).attr('id').replace('jplayer_config_', ''),
			autohide = true,
			fullscreen = false,
			$jplayer = $('#jquery_jplayer_' + jpID),
			$loader = $('<div class="videoLoader"><div class="loader"></div></div>');
		if (ProjectSettings.version === 3) {	autohide = false;}			
		if (jpID == 'reel') {	fullscreen = true;}
		$jplayer.jPlayer({
			ready: function () {
				$(this).jPlayer('setMedia', {
					m4v: media,
					poster: poster
				});
				$('video',this).css({height: '1px', width: '1px'});
				if (jpID === 'reel') {
					$('#reel .loader').remove();
					$('#jp_container_' + jpID).css({visibility: 'visible', backgroundColor: '#3d3b3b'});
					$('#jp_container_' + jpID + ' .jp-type-single').css({opacity: 1});
					$('.intro').css('visibility','visible');
				} else {
					$('#jp_container_' + jpID).css({visibility: 'visible', opacity: 0, backgroundColor: '#3d3b3b'});
					$('#jp_container_' + jpID + ' .jp-type-single').css({opacity: 1});
					$('#jp_container_' + jpID).animate({opacity: 1}, 300);			
				}					
				$('img',this).bind('click',function () {
					if (jpID === 'reel') {resetProjects();}
					thisProject.focusOn(thisProject);
					thisProject.container.append($loader);
					$(this).parent().jPlayer('play');				
				});								
				$(this).data('paused',false);
				if (ProjectSettings.version !== 3) {
					$('#jp_container_' + jpID+' .jp-gui').addClass('locked');
				}
				
				// hd switcher
				if (nohdmedia != videoPath + 'mp4/') {
					$('#jp_container_' + jpID + ' a.jp-hd-on').hide();
					$('#jp_container_' + jpID + ' a.jp-hd-off').click(function() {
						$(this).hide();
						$('#jp_container_' + jpID + ' a.jp-hd-on').show();					
						$jplayer.jPlayer('setMedia', {
							m4v: nohdmedia,
							poster: poster
						});
						$jplayer.jPlayer('play');
					});
					$('#jp_container_' + jpID + ' a.jp-hd-on').click(function() {
						$(this).hide();
						$('#jp_container_' + jpID + ' a.jp-hd-off').show();
						$jplayer.jPlayer('setMedia', {
							m4v: media,
							poster: poster
						});
						$jplayer.jPlayer('play');
					});
				} else { // no hd option - remove quality
					$('#jp_container_' + jpID + ' .jp-quality').remove();
				}							
			},
			play: function () { // To avoid both jPlayers playing together.
				$loader.remove();
				$(this).jPlayer('pauseOthers');
				if ($(this).data('paused') !==  true) {
					// track video play
					_gaq.push(['_trackPageview', '/video/'+jpID]);
					if (jpID !== 'reel') {
						$('a.jp-full-screen',thisProject.container).click();				
					}
				}			
				if (ProjectSettings.version !== 3) {
					clearTimeout(thisProject.thread);
					thisProject.thread = setTimeout(function(){$('#jp_container_' + jpID+' .jp-gui').removeClass('locked');},100);
				}			
			},
			pause: function() {
				$(this).data('paused',true);
			},
			ended: function () {
				$(this).jPlayer('setMedia', {
					m4v: media,
					poster: poster
				});
				$(this).data('paused',false);
				if (ProjectSettings.version !== 3) {
					clearTimeout(thisProject.thread);
					$('#jp_container_' + jpID+' .jp-gui').addClass('locked');	
				}
				if (jpID !== 'reel') {$('a.jp-restore-screen',thisProject.container).click(); }
			},
			autohide: {
				restored: autohide,
				full: autohide,
				hold: 1200
			},
			fullScreen: fullscreen,
			swfPath: serverPath + 'sites/all/themes/nah/jplayer',
			supplied: 'm4v',
			sizeFull: {
				width: '988px', // 987, 555
				height: '556px'
			},
			size: {
				width: '624px', // 620, 349
				height: '351px',
				cssClass: 'jp-video-620p'
			},
			solution: 'flash,html',
			volume: 0.75,
			cssSelectorAncestor: '#jp_container_' + jpID
		});
		$('#jp_container_' + jpID).css({visibility: 'visible', backgroundColor: 'transparent'});
		$('#jp_container_' + jpID + ' .jp-type-single').css({opacity: 0});
		$('#jp_container_' + jpID + ' .jp-video-play').bind('click',function () {
			if (jpID === 'reel') {resetProjects();}
			thisProject.focusOn(thisProject);
			thisProject.container.append($loader);
		});
		
		// fullscreen fix for layering in IE7
		if ($.browser.msie) {
			$('.jp-full-screen', thisProject.container).click( function () {
				$(thisProject.container).addClass('pushTop');
			});
			$('.jp-restore-screen', thisProject.container).click( function () {
				$(thisProject.container).removeClass('pushTop');
			});
		}		
		
		// restore screen
		$('.jp-restore-screen', thisProject.container).click( function () {
			$loader.remove();
		});		
		
		// gui
		$('.jp-gui a, object, video', thisProject.container).click( function() {
			if (jpID === 'reel') {resetProjects();}
			if (!thisProject.container.hasClass('closing')) {
				thisProject.focusOn(thisProject);
			}
		});
	}
}; // end Project prototype
