	var addState = true;
	var _is_touch = false;

	var _num_pushing   = $('#thumbs-pushing li').length;
	var _num_editorial = $('#thumbs-editorial li').length;
	var _num_personal  = $('#thumbs-personal li').length;
	var _num_videos    = $('#video-thumbs li').length;

	var _videoWidth = 640;
	var _videoHeight = 360;

	if ('ontouchstart' in document) {
		$('body').addClass('touch');
		_is_touch = true;
		/*
		_videoWidth = 473;
		_videoHeight = 266;
		*/
	}

	/**
	if ('onorientationchange' in window) {
		window.onorientationchange = updateOrientation;
	}
	**/

	$(function() {
		var height = parseInt($(window).height());
		var width  = parseInt($(window).width());

		$('body').height(height);

		width -= 130;
		$('#video-nav').width(width);
		if (width >= _num_videos * 129) { // -- 12 x 129
			$('#video-thumb-arrow-right').addClass('disabled');
		}

		width -= 129;
			
		$('.photos-thumbs').width(width);

		if (width >= _num_pushing * 129) {
			$('#photos-pushing .thumb-arrow-right').addClass('disabled');
		}

		if (width >= _num_editorial * 129) {
			$('#photos-editorial .thumb-arrow-right').addClass('disabled');
		}

		if (width >= _num_personal * 129) {
			$('#photos-personal .thumb-arrow-right').addClass('disabled');
		}

		$('#draggable,#contact').fadeIn(800, function() {
			setTimeout("$('#draggable').css('background-image', 'none');", 10000);
		});

		$('#draggable').draggable({ 
							handle: '#draggable-handle',
							axis: 'x',
							containment: 'parent',
							cursor: 'move',
							drag: function(event, ui) {
								var pos = ui.position;
								$('#draggable-left').css('width', pos.left + 'px');
								$('#draggable').css('background-image', 'none');
							},
							stop: function(event, ui) {
								var width = $(window).width() / 2;
								var pos = ui.position;

								if (Math.abs(width - pos.left) < 150) {
									$('#draggable-left').animate({ 'width' : width + 'px'}, 300);
									$('#draggable').animate({'left' : width + 'px'}, 300);
								} else if (pos.left > width) {
									$('#director').click();
								} else {
									$('#photographer').click();
								}
							}
				});

		var path = window.location.pathname.replace(/\//g, "");

		if (path == "contact") {
			addState = false;
			$('#contact').click();

			if (supports_history_api()) {
				history.replaceState({ 'page' : 'contact' }, 'contact page', '/contact/');
			} else {
				window.location = "/#contact";
			}
		} else if (path == "director") {
			addState = false;
			$('#director').click();

			if (supports_history_api()) {
				history.replaceState({ 'page' : 'director' }, 'director page', '/director/');
			} else {
				window.location = "/#director";
			}

		} else if (path == "photographer") {
			addState = false;
			$('#photographer').click();

			if (supports_history_api()) {
				history.replaceState({ 'page' : 'photographer' }, 'photographer page', '/photographer/');
			} else {
				window.location = "/#photographer";
			}
		} else {
			var path = window.location.hash.substring(1);
			if (path == "contact") {
				addState = false;
				$('#contact').click();

				if (supports_history_api()) {
					history.replaceState({ 'page' : 'contact' }, 'contact page', '/contact/');
				}
			} else if (path == "director") {
				addState = false;
				$('#director').click();

				if (supports_history_api()) {
					history.replaceState({ 'page' : 'director' }, 'director page', '/director/');
				}
			} else if (path == "photographer") {
				addState = false;
				$('#photographer').click();

				if (supports_history_api()) {
					history.replaceState({ 'page' : 'photographer' }, 'photographer page', '/photographer/');
				}
			}
		}

		$(window).keyup(function(event) {
			if ($('body').hasClass('busy')) {
				return false;
			}
			if (event.keyCode == 39) { // -- right
				$('#arrows-right').click();
			} else if (event.keyCode == 37) { // -- left
				$('#arrows-left').click();
			}
			return false;
		});
	});

	$(window).resize(function() {
		var height = parseInt($(window).height());
		var width  = parseInt($(window).width());

		if (!_is_touch) {
			if (width < 1000) {
				width = 1000;
			}
			if (height < 600) {
				height = 600;
			}
			$('body').width(width);
		}
		$('body').height(height);

		width -= 130;
		$('#video-nav').width(width);
		if (width >= _num_videos * 129) {
			$('#video-thumb-arrow-right').addClass('disabled');
		} else {
			$('#video-thumb-arrow-right').removeClass('disabled');
			$('#video-thumbs').css('margin-left', 0);
		}

		width -= 129;

		$('.photos-thumbs').width(width);

		if (width >= _num_pushing * 129) {
			$('#photos-pushing .thumb-arrow-right').addClass('disabled');
		} else {
			$('#photos-pushing .thumb-arrow-right').removeClass('disabled');
			$('#photos-pushing .thumbs').css('margin-left', 0);
		}

		if (width >= _num_editorial * 129) {
			$('#photos-editorial .thumb-arrow-right').addClass('disabled');
		} else {
			$('#photos-editorial .thumb-arrow-right').removeClass('disabled');
			$('#photos-editorial .thumbs').css('margin-left', 0);
		}

		if (width >= _num_personal * 129) {
			$('#photos-personal .thumb-arrow-right').addClass('disabled');
		} else {
			$('#photos-personal .thumb-arrow-right').removeClass('disabled');
			$('#photos-personal .thumbs').css('margin-left', 0);
		}
	});

	function supports_history_api() {
		if (navigator.userAgent.indexOf('iPad') != -1) {
			return false;
		}
		return !!(window.history && history.pushState);
	}

	if (supports_history_api())  {
		window.onpopstate = function(event) {
			if (event.state) {
				var page = event.state.page;

				addState = false;

				if ($('#page-contact:visible').length) {
					$('#contact-close').click();
				} else if (page == 'contact') {
					$('#contact').click();
				} else {
					$('#switch').mouseup();
				}
			}
		};
	}


	$('#contact').click(function() {
		if ($('video').length) {
			$('#film-close').click();
		}
		$('#page-contact').slideDown();

		if (supports_history_api() && addState) {
			history.pushState({ 'page' : 'contact' }, 'contact page', '/contact/');
		} else if (addState) {
			window.location.hash = "contact";
		}

		addState = true;

		return false;
	});

	$('#contact-close,#page-contact').click(function(e) {
		if ($(e.target).attr('id') != 'page-contact' && $(e.target).attr('id') != 'contact-close') {
			return true;
		}

		if (addState) {
			window.history.back();
		}

		$('#page-contact').slideUp();

		addState = true;

		return false;
	});

	// -- director link
	$('#director').click(function() {
		var pos = $('#draggable').position();
		var width = $(window).width() + 233;

		$('#draggable').css('left' , pos.left).animate({ 'left' :  width }, 300);
		$('#draggable-left').css('left', 0).animate({ 'width': width }, 300, function() {
			$('#page-home').fadeOut(300, function() {
				$('#page-works').show(function (){
					$('#arrows').show().animate({ 'right' : 0 }, 300);
					$('#works-nav').show().animate({ 'bottom' : 0 }, 300, function() {
						$('.video-thumbs ul li:first a').click();
					});
				});			
			});
		});

		$('#switch').removeClass('photos').addClass('film');
		$('#works-nav').removeClass('photos').addClass('film');

		if (supports_history_api() && addState) {
			history.pushState({ 'page' : 'director' }, 'director page', '/director/');
		} else if (addState) {
			window.location.hash = "director";
		}

		addState = true;

		return false;
	});

	// -- photographer link
	$('#photographer').click(function() {
		var pos = $('#draggable').position();
		var width = $(window).width() + 233;

		$('#draggable').css('left' , pos.left).animate({ 'left' :  -233 }, 300);
		$('#draggable-left').css('left', 0).animate({ 'width': 0 }, 300, function() {
			$('#page-home').fadeOut(300, function() {
				$('#page-works').show(function() {
					$('#arrows').show().animate({ 'right' : 0 }, 300);
					$('#works-nav').show().animate({ 'bottom' : 0 }, 300, function() {
						$('.thumbs ul li:first a').click();
					});
				});
			});
		});

		$('#switch').removeClass('film').addClass('photos');
		$('#works-nav').removeClass('film').addClass('photos');

		if (supports_history_api() && addState) {
			history.pushState({ 'page' : 'photographer' }, 'photographer page', '/photographer/');
		} else if (addState) {
			window.location.hash = "photographer";
		}

		addState = true;

		return false;
	});

	$('#arrows-left').click(function() {
		if ($('body').hasClass('busy')) {
			return false;
		}
		$(this).addClass('active');
		setTimeout("$('#arrows-left').removeClass('active');", 200);
		$('body').addClass('busy');

		if ($('#switch').hasClass('photos')) { // -- if viewing photos
			if (currentIndex == 0) {
				$('#nav-personal').click();
			} else if (currentIndex == _num_pushing) {
				$('#nav-pushing').click();
			} else if (currentIndex == _num_pushing + _num_editorial) {
				$('#nav-editorial').click();
			}

			if (currentIndex > 0) {
				$('.thumbs ul li:eq('+(currentIndex-1)+') a').click();
			} else if (currentIndex == 0) {
				var length = $('.thumbs li').length;
				$('.thumbs ul li:eq('+(length-1)+') a').click();
			}
		} else { // -- else: viewing film
			if (currentIndex > 0) {
				$('.video-thumbs ul li:eq('+(currentIndex-1)+') a').click();
			} else if (currentIndex == 0) {
				var length = $('.video-thumbs li').length;
				$('.video-thumbs ul li:eq('+(length-1)+') a').click();
			}
		}

		return false;
	});

	$('#arrows-right').click(function() {
		if ($('body').hasClass('busy')) {
			return false;
		}
		$(this).addClass('active');
		setTimeout("$('#arrows-right').removeClass('active');", 200);
		$('body').addClass('busy');

		if ($('#switch').hasClass('photos')) { // -- if viewing photos
			if (currentIndex == _num_pushing + _num_editorial + _num_personal - 1) { // -- wrapping back to 
				$('#nav-pushing').click();
			} else if (currentIndex == _num_pushing - 1) {
				$('#nav-editorial').click();
			} else if (currentIndex == _num_pushing + _num_editorial - 1) {
				$('#nav-personal').click();
			}

			if (currentIndex < $('.thumbs li').length -1) {
				$('.thumbs ul li:eq('+(currentIndex+1)+') a').click();
			} else {
				$('.thumbs ul li:eq(0) a').click();
			}
		
		} else { // -- else: viewing film
			if (currentIndex < $('.video-thumbs li').length -1) {
				$('.video-thumbs ul li:eq('+(currentIndex+1)+') a').click();
			} else {
				$('.video-thumbs ul li:eq(0) a').click();
			}
		}

		return false;
	});

	$('#film-close').click(function() {
		$('#frames').click();
		$('#film-close').hide();

		var index = $('.video-thumbs ul').find('a').index($('.video-thumbs a.active'));
		var id    = parseInt($('.video-thumbs a.active').data('id'));

		var poster = getSetImagePath(id) + id + '_'+_videoWidth+'.jpg';

		var video = '<div class="video-holder" id="v'+id+'"><a href="javascript:showVideoNow('+id+')"><span class="play"></span><img src="'+poster+'" width="'+_videoWidth+'" height="'+_videoHeight+'" alt=""></a></div>';

		$('#frames .video-frame-container').html('<div class="video-frame">'+video+'</div>');

	});

	$('#frames').click(function(e) {
		if ($(e.target).parents('.video-js-box').length || $(e.target).parents('.video-holder').length) {
			return true;
		}

		$('#arrows').show();

		if (parseInt($('#works-nav').css('bottom')) == 0) {
			$('#contact').addClass('dim');
			$('#arrows').addClass('dim');

			if ($('#switch').hasClass('film')) {
				$('#arrows').hide();
				$('#film-close').show();
			}

			if (_is_touch) {
				$('#works-nav').css('bottom', -130);
				if ($('#switch').hasClass('photos')) { // -- if viewing photos
					var wWidth  = parseInt( $(window).width() );
					var cur = Math.abs(parseInt($('#frames').css('left')));
					if (cur != wWidth) {
						$('#frames').css('left', -wWidth).find('.frame-container:eq(0)').css('left', wWidth);
					}
					setResizeEvent();
				} else {
					windowVideoResizeEvent();
				}
			} else {
				$('#works-nav').animate({ 'bottom' : -130 }, { 'duration' : 300, 'step' : function(now, fx) {
					if ($('#switch').hasClass('photos')) { // -- if viewing photos
						setResizeEvent();
					} else {
						windowVideoResizeEvent();
					}
				}});
			}

			$('#arrows').addClass('full');
		} else {
			$('#contact').removeClass('dim');
			$('#arrows').removeClass('dim');

			if ($('#switch').hasClass('film')) {
				$('#film-close').hide();

				var index = $('.video-thumbs ul').find('a').index($('.video-thumbs a.active'));
				var id    = parseInt($('.video-thumbs a.active').data('id'));

				var poster = getSetImagePath(id) + id + '_'+_videoWidth+'.jpg';

				var video = '<div class="video-holder" id="v'+id+'"><a href="javascript:showVideoNow('+id+')"><span class="play"></span><img src="'+poster+'" width="'+_videoWidth+'" height="'+_videoHeight+'" alt=""></a></div>';

				
				$('#frames .video-frame-container').html('<div class="video-frame">'+video+'</div>');
			}

			if (_is_touch) {
				$('#works-nav').css('bottom', 0);
				if ($('#switch').hasClass('photos')) { // -- if viewing photos
					var wWidth  = parseInt( $(window).width() );
					var cur = Math.abs(parseInt($('#frames').css('left')));
					if (cur != wWidth) {
						$('#frames').css('left', -wWidth).find('.frame-container:eq(0)').css('left', wWidth);
					}
					setResizeEvent();
				} else {
					windowVideoResizeEvent();
				}
			} else {
				$('#works-nav').animate({ 'bottom' : 0 }, { 'duration' : 300, 'step' : function(now, fx) {
					if ($('#switch').hasClass('photos')) { // -- if viewing photos
						setResizeEvent();
					} else {
						windowVideoResizeEvent();
					}
				}});
			}
			$('#arrows').removeClass('full');
		}

		return false;
	});


	$('#switch').click(function() {
		return false;
	});

	$('#switch').mouseup(function() {
		if (switchstartbtn) {
			return false;
		}

		currentIndex = null;

		if ($(this).hasClass('photos')) {
			$(this).removeClass('photos').addClass('film');
			$('#works-nav').removeClass('photos').addClass('film');

			$('.video-thumbs ul li:eq(0) a').click();

			if (supports_history_api() && addState) {
				history.pushState({ 'page' : 'director' }, 'director page', '/director/');
			} else if (addState) {
				window.location.hash = "director";
			}
		} else {
			$(this).removeClass('film').addClass('photos');
			$('#works-nav').removeClass('film').addClass('photos');

			$('.thumbs ul li:eq(0) a').click();

			if (supports_history_api() && addState) {
				history.pushState({ 'page' : 'photographer' }, 'photographer page', '/photographer/');
			} else if (addState) {
				window.location.hash = "photographer";
			}
		}

		addState = true;

		return false;
	});

	$('#nav-editorial').click(function() {
		$('#photo-nav').removeClass('pushing').removeClass('personal').addClass('editorial');
		$('#photos-thumbs-container').removeClass('pushing').removeClass('personal').addClass('editorial');

		return false;
	});
	
	$('#nav-pushing').click(function() {
		$('#photo-nav').addClass('pushing').removeClass('personal').removeClass('editorial');
		$('#photos-thumbs-container').addClass('pushing').removeClass('personal').removeClass('editorial');

		return false;
	});

	$('#nav-personal').click(function() {
		$('#photo-nav').removeClass('pushing').addClass('personal').removeClass('editorial');
		$('#photos-thumbs-container').removeClass('pushing').addClass('personal').removeClass('editorial');

		return false;
	});

	$('.thumb-arrow-left').click(function() {
		if ($(this).hasClass('disabled')) {
			return false;
		}

		var f = $(this).siblings('.thumbs');
		var left = parseInt(f.css('margin-left'));
		left = Math.min(0, left + 129 * 3);
		f.animate({ 'margin-left' : left }, 300);

		if (left == 0) {
			$(this).addClass('disabled');
		}

		$(this).siblings('.thumb-arrow-right').removeClass('disabled');

		return false;
	});

	$('.thumb-arrow-right').click(function() {
		if ($(this).hasClass('disabled')) {
			return false;
		}

		var num;
		if ($('#photos-thumbs-container').hasClass('pushing')) {
			num = _num_pushing;
		} else if ($('#photos-thumbs-container').hasClass('editorial')) {
			num = _num_editorial;
		} else {
			num = _num_personal;
		}

		var f = $(this).siblings('.thumbs');
		var width = $(window).width();
		var left = parseInt(f.css('margin-left'));
		var diff = -(num * 129) + width - 258; // thumbs-width - window-width + left-offset
		left = Math.max(diff, left - 129 * 3);

		/*
		window width = 942
		area = 942 - 258 = 684
		over = 1548 - 942 + 258 = 864 (over right side, which means that -864 is the max)
		*/

		f.animate({ 'margin-left' : left }, 300);

		$(this).siblings('.thumb-arrow-left').removeClass('disabled');

		if (left == diff) {
			$(this).addClass('disabled');
		}

		return false;
	});

	$('#video-thumb-arrow-left').click(function() {
		if ($(this).hasClass('disabled')) {
			return false;
		}

		var f = $(this).siblings('.video-thumbs');
		var left = parseInt(f.css('margin-left'));
		left = Math.min(0, left + 129 * 3);
		f.animate({ 'margin-left' : left }, 300);

		if (left == 0) {
			$(this).addClass('disabled');
		}

		$(this).siblings('#video-thumb-arrow-right').removeClass('disabled');

		return false;
	});

	$('#video-thumb-arrow-right').click(function() {
		if ($(this).hasClass('disabled')) {
			return false;
		}

		var f = $(this).siblings('.video-thumbs');
		var width = $(window).width();
		var left = parseInt(f.css('margin-left'));
		var diff = -(_num_videos * 129) + width - 130; // thumbs-width - window-width + left-offset
		left = Math.max(diff, left - 129 * 3);

		f.animate({ 'margin-left' : left }, 300);

		$(this).siblings('#video-thumb-arrow-left').removeClass('disabled');

		if (left == diff) {
			$(this).addClass('disabled');
		}

		return false;
	});

	/*
	function updateOrientation() {
		if ($('#switch').hasClass('photos')) { // -- if viewing photos
			setTimeout('setResizeEvent();', 200);
		} else {
			windowVideoResizeEvent();
		}
	}
	*/

	var currentIndex = null;

	function showEntry(obj) {
		$(obj).blur();
		var index = $('.thumbs ul').find('li').index($(obj).parent()); // -- global thumb index
		var id    = parseInt($(obj).data('id'));

		if (currentIndex == index) {
			return false;
		}

		$('.thumbs a.active').removeClass('active');
		$(obj).addClass('active');

		// -- disable resizing
		$(window).unbind('resize', setResizeEvent);

		var img = new Image();
		img.onload = function() {
			$(window).bind('resize', setResizeEvent);
			var wWidth  = parseInt( $(window).width() );

			if (currentIndex == null) {
				$('#frames').css('left', -wWidth).empty().append('<div class="frame-container" style="left: '+wWidth+'px" data-id="'+id+'" data-width="'+this.width+'" data-height="'+this.height+'"><div class="frame"></div></div>');

			} else if (currentIndex > index) { // -- left
				$('#frames').append('<div class="frame-container" style="left: 0px" data-id="'+id+'" data-width="'+this.width+'" data-height="'+this.height+'"><div class="frame"></div></div>');

				$('#frames').animate({ 'left' : 0 }, 400, function() {
					$(this).find('.frame-container:eq(0)').remove();
					$(this).find('.frame-container').css('left', wWidth);
					$(this).css('left', -wWidth);

					$('body').removeClass('busy');
				});

			} else { // -- right
				$('#frames').append('<div class="frame-container" style="left: '+ (wWidth * 2)+'px" data-id="'+id+'" data-width="'+this.width+'" data-height="'+this.height+'"><div class="frame"></div></div>');

				$('#frames').animate({ 'left' : -wWidth * 2}, 400, function() {
					$(this).find('.frame-container:eq(0)').remove();
					$(this).find('.frame-container').css('left', wWidth);
					$(this).css('left', -wWidth);

					$('body').removeClass('busy');
				});
			}

			currentIndex = index;

			setResizeEvent();

			preloadsiblings();
		};

		// -- this image is only loaded for the aspect ratio. the actual displaying happens when the resize event is called
		if (_is_touch) {
			img.src = getSetImagePath(id)+id+'_864.jpg';
		} else {
			img.src = getSetImagePath(id)+id+'_800.jpg';
		}

		return false;
	}

	function getSetImagePath(id) {
		return '/data/albums/' + lastChar(id) + '/';
	}

	function lastChar(string) {
		string = new String(string);
		return string.charAt(string.length - 1);
	}

	function setResizeEvent() {
		windowResizeEvent(getSetImagePath);
	}

	function windowResizeEvent(getImagePathFn) {
		// -- threshold in px
		var threshold = 150;

		// -- window dims
		var owWidth  = parseInt( $('body').width() );
		var owHeight = parseInt( $('body').height() );

		var wWidth  = owWidth;
		var wHeight = owHeight;

		// -- container dims
		var cWidth;
		var cHeight;

		var navHeight = 130;
		navHeight = 130 + parseInt($('#works-nav').css('bottom'));

		wHeight = wHeight - 88 - navHeight; // -- 44px top and bottom + 130 nav height

		if (_is_touch) {
			wWidth  -= 160;  // -- 80px either side
		} else {
			wWidth  -= 200;  // -- 100px either side
		}

		// -- original image dims are used for aspect/scaling
		var counter = 0;
		$('.frame-container').each(function() {
			var iWidth  = $(this).data('width');
			var iHeight = $(this).data('height');
			var id      = $(this).data('id');
			var frame   = $(this).find('.frame');

			// -- which orientation gives the best fit
			if (wHeight / wWidth < iHeight / iWidth) {
				cHeight = wHeight;
				cWidth  = Math.round(wHeight * iWidth / iHeight);
			} else {
				cWidth  = wWidth;
				cHeight = Math.round(wWidth * iHeight / iWidth);
			}

			// -- max width of 1200 for desktop version
			if (cWidth > 1000 && cWidth >= cHeight) {
				cWidth = 1000;
				cHeight = Math.round(cWidth * iHeight / iWidth);
			} else if (cHeight > 683 && cHeight >= cWidth) {
				cHeight = 683;
				cWidth  = Math.round(cHeight * iWidth / iHeight);
			}


			// -- ipad horizontal
			if (_is_touch && owWidth == 1024) {
				if ($(this).find('.image_L').length == 0) {
					var img = $('<img src="'+getImagePathFn(id)+id+'_864.jpg" class="image_L" class="loading" style="opacity: 0; z-index: 0"/>');

					frame.append(img);

					img.load(function() {
						$(this).removeClass('loading').addClass('loaded');
						$(this).css( { 'opacity' : 1, 'z-index' : 2 } );
						frame.find('.image_M').css( { 'opacity' : 0, 'z-index' : 1 } );
					});
				}
				
				if (frame.find('.image_L').hasClass('loaded')) {
					frame.find('.image_L').css( { 'opacity' : 1, 'z-index' : 2 } );
					frame.find('.image_M').css( { 'opacity' : 0, 'z-index' : 1 } );
				}

			// -- ipad vertical
			} else if (_is_touch) {
				if ($(this).find('.image_M').length == 0) {
					var img = $('<img src="'+getImagePathFn(id)+id+'_606.jpg" class="image_M" class="loading" style="opacity: 0; z-index: 0"/>');

					frame.append(img);

					img.load(function() {
						$(this).removeClass('loading').addClass('loaded');
						$(this).css( { 'opacity' : 1, 'z-index' : 2 } );
						frame.find('.image_L').css( { 'opacity' : 0, 'z-index' : 1 } );
					});
				}
				
				if (frame.find('.image_M').hasClass('loaded')) {
					frame.find('.image_M').css( { 'opacity' : 1, 'z-index' : 2 } );
					frame.find('.image_L').css( { 'opacity' : 0, 'z-index' : 1 } );
				}

				// -- recalculate iWidth and iHeight:
				if (cHeight == wHeight) { // -- portrait
					iWidth = Math.round(729 * iWidth / iHeight);
					iHeight = 729;
				} else { // -- landscape
					iHeight = Math.round(606 * iHeight / iWidth);
					iWidth = 606;
				}

			// -- 1000px
			} else if (cWidth >= 1000-threshold || cHeight >= 683-threshold) {
				if ($(this).find('.image_L').length == 0) {
					var img = $('<img src="'+getImagePathFn(id)+id+'_1000.jpg" class="image_L" class="loading" style="opacity: 0; z-index: 0"/>');

					frame.append(img);

					img.load(function() {
						$(this).removeClass('loading').addClass('loaded');
						$(this).css( { 'opacity' : 1, 'z-index' : 2 } );
						frame.find('.image_M').css( { 'opacity' : 0, 'z-index' : 1 } );
					});
				}
				
				if (frame.find('.image_L').hasClass('loaded')) {
					frame.find('.image_L').css( { 'opacity' : 1, 'z-index' : 2 } );
					frame.find('.image_M').css( { 'opacity' : 0, 'z-index' : 1 } );
				}

			// -- 800px
			} else {
				if (frame.find('.image_M').length == 0) {
					var img = $('<img src="'+getImagePathFn(id)+id+'_800.jpg" class="image_M" class="loading" style="opacity: 0; z-index: 0"/>');
					
					frame.append(img);

					img.load(function() {
						$(this).removeClass('loading').addClass('loaded');
						$(this).css( { 'opacity' : 1, 'z-index' : 2 } );
						frame.find('.image_L').css( { 'opacity' : 0, 'z-index' : 1 } );
					});
				}

				if (frame.find('.image_M').hasClass('loaded')) {
					frame.find('.image_M').css( { 'opacity' : 1, 'z-index' : 2 } );
					frame.find('.image_L').css( { 'opacity' : 0, 'z-index' : 1 } );
				}
			}

			if (_is_touch) {
				// -- ipad doesn't like resizing images, so using a fixed size of either 606 x 729 (portrait), or 864 x 473 (landscape)
				frame.css({ 'width' : iWidth + 'px', 'height' : iHeight + 'px', 'margin-left' : + (-iWidth / 2) + 'px', 'margin-top' : '-' + (((iHeight - navHeight) / 2) + navHeight)  + 'px' });
			} else {
				frame.css({ 'width' : cWidth + 'px', 'height' : cHeight + 'px', 'margin-left' : + (-cWidth / 2) + 'px', 'margin-top' : '-' + (((cHeight - navHeight) / 2) + navHeight)  + 'px' });
			}

			$(this).css('width', owWidth);

			counter++;
		});
	}


	function failedVideo(event) {
		// video playback failed - show a message saying why
		// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-video-element
		switch (e.target.error.code) {
			case e.target.error.MEDIA_ERR_ABORTED:
				alert('You aborted the video playback.');
				break;
			case e.target.error.MEDIA_ERR_NETWORK:
				alert('A network error caused the video download to fail part-way.');
				break;
			case e.target.error.MEDIA_ERR_DECODE:
				alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
				break;
			case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
				alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
				break;
			default:
				alert('An unknown error occurred.');
				break;
		}
	}

	function windowVideoResizeEvent() {
		var wWidth  = parseInt( $(window).width() );
		var wHeight = parseInt( $(window).height() );

		var navHeight = 130;
		navHeight = 130 + parseInt($('#works-nav').css('bottom'));
		var height = wHeight - navHeight;

		$('.video-frame-container').css({ 'height' : height, 'width' : wWidth });
	}

	function showVideo(obj) {
		var index = $('.video-thumbs ul').find('li').index($(obj).parent());
		var id    = parseInt($(obj).data('id'));

		if (currentIndex == index) {
			return false;
		}

		$('.video-thumbs a.active').removeClass('active');
		$(obj).addClass('active');

		// -- disable resizing
		$(window).unbind('resize', setResizeEvent);

		var wWidth  = parseInt( $(window).width() );
		var wHeight = parseInt( $(window).height() );

		var navHeight = 130;
		navHeight = 130 + parseInt($('#works-nav').css('bottom'));

		var height = wHeight - navHeight;

		var poster = getSetImagePath(id) + id + '_'+_videoWidth+'.jpg';

		var video = '<div class="video-holder" id="v'+id+'"><a href="javascript:showVideoNow('+id+')"><span class="play"></span><img src="'+poster+'" width="'+_videoWidth+'" height="'+_videoHeight+'" alt=""></a></div>';

		if (currentIndex == null) {
			$('#frames').css('left', -wWidth).empty().append('<div class="video-frame-container" data-id="'+id+'" style="height: '+height+'px; width: '+wWidth+'px; left: '+wWidth+'px"><div class="video-frame">'+video+'</div></div>');
		} else if (currentIndex > index) { // left
			$('#frames').append('<div class="video-frame-container" data-id="'+id+'" style="height: '+height+'px; width: '+wWidth+'px; left: 0px"><div class="video-frame">'+video+'</div></div>');

			$('#frames').animate({ 'left' : 0 }, 400, function() {
				$(this).find('.video-frame-container:eq(0)').remove();
				$(this).find('.video-frame-container').css('left', wWidth);
				$(this).css('left', -wWidth);

				$('body').removeClass('busy');
			});
		} else { // right
			$('#frames').append('<div class="video-frame-container" data-id="'+id+'" style="height: '+height+'px; width: '+wWidth+'px; left: '+(wWidth * 2)+'px"><div class="video-frame">'+video+'</div></div>');

			$('#frames').animate({ 'left' : -wWidth * 2 }, 400, function() {
				$(this).find('.video-frame-container:eq(0)').remove();
				$(this).find('.video-frame-container').css('left', wWidth);
				$(this).css('left', -wWidth);

				$('body').removeClass('busy');
			});
		}

		currentIndex = index;

		$(window).bind('resize', windowVideoResizeEvent);

		windowVideoResizeEvent();
	}

	function showVideoNow(id) {
		var container = $('#v' + id);

		container.removeClass('video-holder');

		var poster = getSetImagePath(id) + id + '_'+_videoWidth+'.jpg';
		var webm   = getSetImagePath(id) + id + '_'+_videoWidth+'.webm';
		var mp4    = getSetImagePath(id) + id + '_'+_videoWidth+'.mp4';

		var video = '<div class="video-js-box vim-css"><video class="video-js" id="video'+id+'" width="'+_videoWidth+'" height="'+_videoHeight+'" controls preload autoplay  poster="'+poster+ '">\
						<source id="webm" src="'+webm+'" type="video/webm" codecs="vp8, vorbis"/>\
						<source id="mp4" src="'+mp4+'" type="video/mp4" codecs="avc1.42E01E, mp4a.40.2"/>\
						<object class="vjs-flash-fallback" id="flowplayer" width="'+_videoWidth+'" height="'+_videoHeight+'" type="application/x-shockwave-flash" data="/static/swf/flowplayer-3.2.7.swf">\
						<param name="movie" value="/static/swf/flowplayer-3.2.7.swf"/>\
						<param name="allowfullscreen" value="true"/>\
						<param name="flashvars" value="config={\'playlist\':[{\'url\':\''+poster+'\'},{\'url\':\''+mp4+'\',\'autoPlay\':true},{\'url\':\''+poster+'\'}]}"/>\
						<a href="http://get.adobe.com/flashplayer/">Adobe Flash Player Required to View this Video</a>\
						</object>\
						</video></div>';

		container.html(video);

		VideoJS.setupAllWhenReady({
		      controlsBelow: false, // Display control bar below video instead of in front of
		      controlsHiding: true, // Hide controls when mouse is not over the video
		      defaultVolume: 0.85, // Will be overridden by user's last volume if available
		      flashPlayerVersion: 9 // Required flash version for fallback
		});
		
		if ($('#film-close:hidden').length) {
			$('#frames').click();
		}

		// -- this plays the video a tiny bit faster
		var v = document.getElementById('video'+ id);
		if (typeof(v) != 'null') {
			v.play();
		} else {
			setTimeout('v.play()', 200);
		}
	}


/** -- touch events **/
var homex = null;
function touchStartHome(e) {
	event.preventDefault();
}

function touchMoveHome(e){
	event.preventDefault();
		
	var touch = e.touches[0];
	var x = touch.screenX;

	homex = x;

	$('#draggable-left').css('width', x + 'px');
	$('#draggable').css('left', x + 'px');
	$('#draggable').css('background-image', 'none');
}

function touchEndHome(e) {
	var width = $(window).width() / 2;

	if (Math.abs(width - homex) < 200) {
		$('#draggable-left').animate({ 'width' : width + 'px'}, 300, function() {
			$(this).css('width', '50%');			
		});
		$('#draggable').animate({'left' : width + 'px'}, 300, function() {
			$(this).css('left', '50%');
		});
	} else if (homex > width) {
		$('#director').click();
	} else {
		$('#photographer').click();
	}
}

var switchstart = null;
var switchx = null;
var switchstartbtn = null;
var switchTimer = null;
var switchTimeCounter = 0;
function touchStartSwitch(e) {
	e.preventDefault();

	var touch = e.touches[0];
	var x = touch.screenX;

	switchstart = x;

	switchstartbtn = $('#switch').attr('class');

	switchTimeCounter = 0;

	clearTimeout(switchTimer);
	switchTimer = setTimeout(timeCountSwitch, 300);
}

function touchMoveSwitch(e){
	e.preventDefault();
		
	var touch = e.touches[0];
	var x = touch.screenX;

	diff = switchstart - x;

	if (switchstartbtn == 'photos' && diff < 1 && diff > -46) { // need to swipe right
		diff = Math.abs(diff);
		$('#switch-btn').css('left', diff + 'px');
	} else if (switchstartbtn == 'film' && diff > 0 && diff < 46) {
		diff = 45 - diff;
		$('#switch-btn').css('left', diff + 'px');
	}
}

function touchEndSwitch(e) {
	e.preventDefault();

	var x = parseInt($('#switch-btn').css('left'));

	if (switchTimeCounter == 0) {
		clearTimeout(switchTimer);
		switchTimeCounter = 0;

		switchstart = null;
		switchx = null;
		switchstartbtn = null;

		$('#switch-btn').attr('style', '');

		$('#switch').mouseup();

		return false;
	}

	if (x > 22) { // -- show film
		$('#switch-btn').css('left', '45px');
		$('#switch').removeClass('photos').addClass('film');

		if (switchstartbtn == 'photos') { // -- was on photos
			currentIndex = null;

			$('#works-nav').removeClass('photos').addClass('film');

			$('.video-thumbs ul li:eq(0) a').click();

			if (supports_history_api()) {
				history.pushState({ 'page' : 'director' }, 'director page', '/director/');
			} else if (addState) {
				window.location.hash = "director";
			}
		}
	} else { // -- show photos
		$('#switch-btn').css('left', '0px');
		$('#switch').removeClass('film').addClass('photos');

		if (switchstartbtn == 'film') { // -- was on film
			currentIndex = null;

			$('#works-nav').removeClass('film').addClass('photos');

			$('.thumbs ul li:eq(0) a').click();

			if (supports_history_api()) {
				history.pushState({ 'page' : 'photographer' }, 'photographer page', '/photographer/');
			} else if (addState) {
				window.location.hash = "photographer";
			}
		}
	}

	$('#switch-btn').attr('style', '');

	clearTimeout(switchTimer);
	switchTimeCounter = 0;

	return false;
}

function touchCancelSwitch(e) {
	e.preventDefault();

	switchstart = null;
	switchx = null;
	switchstartbtn = null;
}
function timeCountSwitch(){
	switchTimeCounter++;
}

// -- photo thumbs
var startx = null;
var startleftx = null;
var photosTimer = null;
var photosTimeCounter = 0;
var photosdiff = null;
var lastx = null;
var lastdiff = null;
function touchStartPhotos(e) {
	e.preventDefault();

	var touch = e.touches[0];
	var x = touch.screenX;

	var p = $(e.target).parents('.thumbs,.video-thumbs');

	startx = x;
	startleftx = parseInt(p.css('margin-left'));
	lastx = x;

	photosTimeCounter = 0;

	clearTimeout(photosTimer);
	photosTimer = setTimeout(timeCountPhotos, 200);

	photosdiff = 0;
}

function touchMovePhotos(e){
	e.preventDefault();
		
	var touch = e.touches[0];
	var x = touch.screenX;

	lastdiff = lastx - x;

	lastx = x;

	diff = startx - x;

	var width = $(window).width();
	var p = $(e.target).parents('.thumbs');
	var left = startleftx;

	var num;
	if ($('#photos-thumbs-container').hasClass('pushing')) {
		num = _num_pushing;
	} else if ($('#photos-thumbs-container').hasClass('editorial')) {
		num = _num_editorial;
	} else {
		num = _num_personal;
	}

	if (diff > 0) { // -- left
		left = Math.max(-(num * 129) + width - 258 - 55, startleftx - diff);
	} else { // -- right
		left -= diff;
		if (left > 55) {
			left = 55;
		}
	}
	p.css('margin-left', left);

	if (left >= 0) {
		p.siblings('.thumb-arrow-left').addClass('disabled');
		p.siblings('.thumb-arrow-right').removeClass('disabled');
	} else {
		p.siblings('.thumb-arrow-left').removeClass('disabled');
	}

	if (left <= -(num * 129) + width - 258) {
		p.siblings('.thumb-arrow-left').removeClass('disabled');
		p.siblings('.thumb-arrow-right').addClass('disabled');
	} else {
		p.siblings('.thumb-arrow-right').removeClass('disabled');
	}

	photosdiff = diff;
}

function touchEndPhotos(e) {
	if (Math.abs(photosdiff) < 10) {
		$(e.target).click();
		return true;
	}
	e.preventDefault();

	var p = $(e.target).parents('.thumbs');
	var width = $(window).width();
	var left = parseInt(p.css('margin-left'));

	var num;
	if ($('#photos-thumbs-container').hasClass('pushing')) {
		num = _num_pushing;
	} else if ($('#photos-thumbs-container').hasClass('editorial')) {
		num = _num_editorial;
	} else {
		num = _num_personal;
	}

	if (lastdiff > 0) { // strip moves left to < 0
		left = left - (lastdiff/35 * 387);
		left = Math.max(-(num * 129) + width - 258 - 55, left);
		p.animate({ 'margin-left' : left }, 350, 'easeOutQuint', function() {
			if (left >= 0) {
				p.siblings('.thumb-arrow-left').addClass('disabled');
				p.siblings('.thumb-arrow-right').removeClass('disabled');
				$(this).animate({'margin-left' : 0}, 100, 'easeOutQuint');
			} else {
				p.siblings('.thumb-arrow-left').removeClass('disabled');
			}

			if (left <= -(num * 129) + width - 258) {
				p.siblings('.thumb-arrow-left').removeClass('disabled');
				p.siblings('.thumb-arrow-right').addClass('disabled');
				$(this).animate({'margin-left' : -(num * 129) + width - 258}, 100, 'easeOutQuint');
			} else {
				p.siblings('.thumb-arrow-right').removeClass('disabled');
			}	
		});
	} else { // left
		left = left - (lastdiff/35 * 387);
		left = Math.min(55, left);
		p.animate({ 'margin-left' : left }, 350, 'easeOutQuint', function() {
			if (left >= 0) {
				p.siblings('.thumb-arrow-left').addClass('disabled');
				p.siblings('.thumb-arrow-right').removeClass('disabled');
				$(this).animate({'margin-left' : 0}, 100, 'easeOutQuint');
			} else {
				p.siblings('.thumb-arrow-left').removeClass('disabled');
			}

			if (left <= -(num * 129) + width - 258) {
				p.siblings('.thumb-arrow-left').removeClass('disabled');
				p.siblings('.thumb-arrow-right').addClass('disabled');
			} else {
				p.siblings('.thumb-arrow-right').removeClass('disabled');
			}
		});
	}

	clearTimeout(photosTimer);
	photosTimeCounter = 0;

	return false;
}

function timeCountPhotos(){
	photosTimeCounter++;
}

// -- film thumbs
function touchMoveFilm(e){
	e.preventDefault();
		
	var touch = e.touches[0];
	var x = touch.screenX;

	lastdiff = lastx - x;

	lastx = x;

	diff = startx - x;

	var width = $(window).width();
	var p = $(e.target).parents('.video-thumbs');
	var left = startleftx;

	if (diff > 0) { // -- left
		left = Math.max(-(_num_videos * 129) + width - 130 - 55, startleftx - diff);
	} else { // -- right
		left -= diff;
		if (left > 55) {
			left = 55;
		}
	}

	p.css('margin-left', left);

	if (left >= 0) {
		p.siblings('#video-thumb-arrow-left').addClass('disabled');
		p.siblings('#video-thumb-arrow-right').removeClass('disabled');
	} else {
		p.siblings('#video-thumb-arrow-left').removeClass('disabled');
	}

	if (left <= -(_num_videos * 129) + width - 130) {
		p.siblings('#video-thumb-arrow-left').removeClass('disabled');
		p.siblings('#video-thumb-arrow-right').addClass('disabled');
	} else {
		p.siblings('#video-thumb-arrow-right').removeClass('disabled');
	}

	photosdiff = diff;
}

function touchEndFilms(e) {
	if (Math.abs(photosdiff) < 10) {
		$(e.target).click();
		return true;
	}
	e.preventDefault();

	var p = $(e.target).parents('.video-thumbs');
	var width = $(window).width();
	var left = parseInt(p.css('margin-left'));

	if (lastdiff > 0) { // strip moves left to < 0
		left = left - (lastdiff/35 * 387);
		left = Math.max(-(_num_videos * 129) + width - 130 - 55, left);
		p.animate({ 'margin-left' : left }, 350, 'easeOutQuint', function() {
			if (left >= 0) {
				p.siblings('#video-thumb-arrow-left').addClass('disabled');
				p.siblings('#video-thumb-arrow-right').removeClass('disabled');
				$(this).animate({'margin-left' : 0}, 100, 'easeOutQuint');
			} else {
				p.siblings('#video-thumb-arrow-left').removeClass('disabled');
			}

			if (left <= -(_num_videos * 129) + width - 130) {
				p.siblings('#video-thumb-arrow-left').removeClass('disabled');
				p.siblings('#video-thumb-arrow-right').addClass('disabled');
				$(this).animate({'margin-left' : -(_num_videos * 129) + width - 130 }, 100, 'easeOutQuint');
			} else {
				p.siblings('#video-thumb-arrow-right').removeClass('disabled');
			}
		});
	} else { // left
		left = left - (lastdiff/35 * 387);
		left = Math.min(55, left);
		p.animate({ 'margin-left' : left }, 350, 'easeOutQuint', function() {
			if (left >= 0) {
				p.siblings('#video-thumb-arrow-left').addClass('disabled');
				p.siblings('#video-thumb-arrow-right').removeClass('disabled');
				$(this).animate({'margin-left' : 0}, 100, 'easeOutQuint');
			} else {
				p.siblings('#video-thumb-arrow-left').removeClass('disabled');
			}

			if (left <= -(_num_videos * 129) + width - 130) {
				p.siblings('#video-thumb-arrow-left').removeClass('disabled');
				p.siblings('#video-thumb-arrow-right').addClass('disabled');
			} else {
				p.siblings('#video-thumb-arrow-right').removeClass('disabled');
			}
		});
	}

	clearTimeout(photosTimer);
	photosTimeCounter = 0;

	return false;
}

/** swipe main area */
var startx = null;
var currentx = null;
var timer = null;
var timeCounter = 0;
var mainProgress = 0;
function touchStartFrames(e) {
	if (e.target.className == 'play') {
		return true;
	}

	e.preventDefault();

	if (mainProgress != 0) {
		return false;
	}

	mainProgress = 1;

	var length;
	var touch = e.touches[0];
	currentx = startx = touch.screenX;

	var wWidth  = parseInt( $(window).width() );
	if ($('#switch').hasClass('photos')) { // -- if viewing photos
		length = $('.thumbs li').length;
	} else {
		length = $('.video-thumbs li').length;
	}

	var indexL, indexR, idL, idR;

	indexL = currentIndex - 1;
	if (indexL < 0) {
		indexL = length - 1;
	}

	indexR = currentIndex + 1;
	if (indexR >= length) {
		indexR = 0;
	}

	if ($('#switch').hasClass('photos')) { // -- if viewing photos
		$('#frames').find('.frame-container').addClass('centre');

		idL = $('.thumbs ul li:eq('+indexL+') a').data('id');
		idR = $('.thumbs ul li:eq('+indexR+') a').data('id');

		// -- left
		var imgL = new Image();
		imgL.onload = function() {
			$('#frames').append('<div class="frame-container left" style="left: 0px" data-id="'+idL+'" data-width="'+this.width+'" data-height="'+this.height+'"><div class="frame"></div></div>');

			setResizeEvent();
		};
		imgL.src = getSetImagePath(idL)+idL+'_864.jpg';

		// -- right
		var imgR = new Image();
		imgR.onload = function() {
			$('#frames').append('<div class="frame-container right" style="left: '+ (wWidth * 2) +'px" data-id="'+idR+'" data-width="'+this.width+'" data-height="'+this.height+'"><div class="frame"></div></div>');

			setResizeEvent();
		};
		imgR.src = getSetImagePath(idR)+idR+'_864.jpg';

	} else {
		$('#frames').find('.video-frame-container').addClass('centre');

		idL = $('.video-thumbs ul li:eq('+indexL+') a').data('id');
		idR = $('.video-thumbs ul li:eq('+indexR+') a').data('id');

		var wHeight = parseInt( $(window).height() );
		var navHeight = 130;
		navHeight = 130 + parseInt($('#works-nav').css('bottom'));
		var height = wHeight - navHeight;

		var posterL = getSetImagePath(idL) + idL + '_'+_videoWidth+'.jpg';
		var posterR = getSetImagePath(idR) + idR + '_'+_videoWidth+'.jpg';

		var videoL = '<div class="video-holder" id="v'+idL+'"><a href="javascript:showVideoNow('+idL+')"><span class="play"></span><img src="'+posterL+'" alt=""></a></div>';
		var videoR = '<div class="video-holder" id="v'+idR+'"><a href="javascript:showVideoNow('+idR+')"><span class="play"></span><img src="'+posterR+'" alt=""></a></div>';

		$('#frames').append('<div class="video-frame-container left" data-id="'+idL+'" style="height: '+height+'px; width: '+wWidth+'px; left: 0px"><div class="video-frame">'+videoL+'</div></div>');
		$('#frames').append('<div class="video-frame-container right" data-id="'+idR+'" style="height: '+height+'px; width: '+wWidth+'px; left: '+(wWidth * 2)+'px"><div class="video-frame">'+videoR+'</div></div>');
	}

	timeCounter = 0;
	clearTimeout(timer);
	timer = setTimeout(timeCount, 200);
}

function touchMoveFrames(e) {
	if (e.target.className == 'play') {
		return true;
	}

	e.preventDefault();
	
	if (mainProgress != 1) {
		return false;
	}

	var touch = e.touches[0];
	var x = touch.screenX;

	var diff = startx - x;

	var wWidth  = parseInt( $(window).width() );

	$('#frames').css('left',  -wWidth - diff);

	currentx = x;
}


function touchEndFrames(e) {
	if (e.target.className == 'play') {
		return true;
	}
	e.preventDefault();

	if (mainProgress != 1) {
		return false;
	}

	mainProgress = 2;

	var diff = startx - currentx;
	var wWidth = parseInt( $(window).width() );
	var parentClass;
	var containerClass;
	
	if ($('#switch').hasClass('photos')) { // -- if viewing photos
		parentClass = '.thumbs';
		containerClass = '.frame-container';
	} else {
		parentClass = '.video-thumbs';
		containerClass = '.video-frame-container';
	}

	var length = $(parentClass + ' li').length;

	if (Math.abs(diff) > 30 && diff < 0) { // -- left
		currentIndex--;

		if (currentIndex < 0) {
			currentIndex = length - 1;
		}

		var currentID = $(parentClass + ' ul li:eq('+currentIndex+') a').data('id');

		$('#frames').animate({ 'left' : 0 }, 300, function() {
			$(containerClass).each(function() {
				if ($(this).data('id') != currentID) {
					$(this).remove();
				}
			});

			$(this).find(containerClass).css('left', wWidth);
			$(this).css('left', -wWidth);

			$(parentClass + ' a.active').removeClass('active');
			$(parentClass + ' ul li:eq('+currentIndex+') a').addClass('active');
			if (parentClass == '.thumbs') {
				preloadsiblings();
			}

			if (currentIndex == _num_pushing - 1) { // -- wrapping back to 
				$('#nav-pushing').click();
			} else if (currentIndex == _num_pushing + _num_editorial - 1) {
				$('#nav-editorial').click();
			} else if (currentIndex == _num_pushing + _num_editorial + _num_personal - 1) {
				$('#nav-personal').click();
			}

			mainProgress = 0;
		});

	} else if (Math.abs(diff) > 30) { // -- right
		currentIndex++;
		if (currentIndex >= length) {
			currentIndex = 0;
		}

		var currentID = $(parentClass + ' ul li:eq('+currentIndex+') a').data('id');

		$('#frames').animate({ 'left' : -wWidth * 2 }, 300, function() {
			$(containerClass).each(function() {
				if ($(this).data('id') != currentID) {
					$(this).remove();
				}
			});

			$(this).find(containerClass).css('left', wWidth);
			$(this).css('left', -wWidth);

			$(parentClass + ' a.active').removeClass('active');
			$(parentClass + ' ul li:eq('+currentIndex+') a').addClass('active');
			if (parentClass == '.thumbs') {
				preloadsiblings();
			}

			if (currentIndex == 0) { // -- wrapping back to 
				$('#nav-pushing').click();
			} else if (currentIndex == _num_pushing) {
				$('#nav-editorial').click();
			} else if (currentIndex == _num_pushing + _num_editorial) {
				$('#nav-personal').click();
			}

			mainProgress = 0;
		});
	} else {
		if (timeCounter == 0) {
			$('#frames').click();
		}

		var currentID = $(parentClass + ' ul li:eq('+currentIndex+') a').data('id');

		$('#frames').animate({ 'left' : -wWidth }, 300, function() {
			$(containerClass).each(function() {
				if ($(this).data('id') != currentID) {
					$(this).remove();
				}
			});

			$(parentClass + ' a.active').removeClass('active');
			$(parentClass + ' ul li:eq('+currentIndex+') a').addClass('active');
			if (parentClass == '.thumbs') {
				preloadsiblings();
			}
			mainProgress = 0;
		});
	}
}

function timeCount(){
	timeCounter++;
}

function preloadsiblings() {
	// -- preload next and previous
	var indexL, indexR, idL, idR;

	var length = $('.thumbs li').length;

	indexL = currentIndex - 1;
	if (indexL < 0) {
		indexL = length - 1;
	}

	indexR = currentIndex + 1;
	if (indexR >= length) {
		indexR = 0;
	}

	idL = $('.thumbs ul li:eq('+indexL+') a').data('id');
	idR = $('.thumbs ul li:eq('+indexR+') a').data('id');

	if (_is_touch) {
		var imgL = new Image();
		imgL.src = getSetImagePath(idL)+idL+'_864.jpg';

		var imgR = new Image();
		imgR.src = getSetImagePath(idR)+idR+'_864.jpg';
	} else {
		var imgL = new Image();
		imgL.src = getSetImagePath(idL)+idL+'_800.jpg';

		var imgR = new Image();
		imgR.src = getSetImagePath(idR)+idR+'_800.jpg';

		var imgLL = new Image();
		imgL.src = getSetImagePath(idL)+idL+'_1000.jpg';

		var imgRL = new Image();
		imgR.src = getSetImagePath(idR)+idR+'_1000.jpg';
	}
}

