/**
* Gallery - Just Jenna Photography (for Gallery Exhibition Format)
* jQuery plugin
*
* @version 0.3
* @author Leslie Owusu-Appiah - http://leslieowusuappiah.com/
* @copyright Leslie Owusu-Appiah - http://leslieowusuappiah.com/ | @LeslieOA | l@leslieoa.com
*/

jQuery.event.add(document, 'ready', resizeFrame); jQuery.event.add(window, 'resize', resizeFrame);
function resizeFrame() { $('#slideshow ul').css('marginLeft', ($(window).width()/2-600/2)+'px'); }

jQuery.fn.extend({ disableSelection: function() { this.each(function() { this.onselectstart = function() { return false; }; 
this.unselectable = 'on'; jQuery(this).css('-moz-user-select', 'none'); }); }});

jQuery(function($) {

	// Startup
	$('#screen').disableSelection(); // Prevent random highlighting of elements
	$('#slideshow ul').css('width', $('#slideshow ul').children().size()*800); // Slideshow width
	$('#slideshow ul li:eq(0)').addClass('selected');
	$('.prev').addClass('disabled'); 
	$('.num').empty(); $('.num').append(1); $('.numSlide').empty(); // # of...
	$('.numSlide').append($('#slideshow ul').children().size()); 	// #
	$('#screen').append('<div class="click"></div>'); $('.click').click(function(){$('.next').click();});

	$('#slideshow').serialScroll({ 
		items: 'li', prev: '#screen span.prev',	next: '#screen span.next', offset: ($(window).width()/2-600/2)*-1, 
		start: 0, duration: 600, force: true, stop: true, lock: false, cycle: false, easing: 'easeOutQuint', step: 1, jump: true, 
		onBefore: 	function(e, elem, $pane, $items, pos) { 
						var posSlide = pos; $('.num').empty(); $('.num').append(pos+1);					
						$('#slideshow ul li').removeClass('selected'); $('#slideshow ul li:eq('+posSlide+')').addClass('selected');

						if(pos == 0) { $('.prev').addClass('disabled'); $('.next').removeClass('disabled'); } 
							else if (pos == $items.length-1) { $('.next').addClass('disabled'); $('.prev').removeClass('disabled'); } 
							else { $('.next, .prev').removeClass('disabled'); }
						},
		onAfter: 	function(elem) { }
		});

	});



$(document).keydown(function(event) { // MSIE doesn't much like $(window)
	switch (event.keyCode) {
		//case 13: /*enter*/ $('.right').click(); break;
		case 32: /*space*/ $('#screen span.next').click(); break;
		case 37: /*left arrow*/ $('#screen span.prev').click(); break; 
		case 39: /* right arrow */ $('#screen span.next').click(); break;
		}
	});



// Easing equations from jQuery easing plugin - http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; };
jQuery.easing.easeOutQuint = function (x, t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; };

// Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | MIT/GPL
// jQuery ScrollTo - (http://demos.flesler.com/jquery/scrollTo/)
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
// jQuery SerialScroll (http://demos.flesler.com/jquery/serialScroll/)
;(function($){var a='serialScroll',b='.'+a,c='bind',C=$[a]=function(b){$.scrollTo.window()[a](b)};C.defaults={duration:1e3,axis:'x',event:'click',start:0,step:1,lock:1,cycle:1,constant:1};$.fn[a]=function(y){y=$.extend({},C.defaults,y);var z=y.event,A=y.step,B=y.lazy;return this.each(function(){var j=y.target?this:document,k=$(y.target||this,j),l=k[0],m=y.items,o=y.start,p=y.interval,q=y.navigation,r;if(!B)m=w();if(y.force)t({},o);$(y.prev||[],j)[c](z,-A,s);$(y.next||[],j)[c](z,A,s);if(!l.ssbound)k[c]('prev'+b,-A,s)[c]('next'+b,A,s)[c]('goto'+b,t);if(p)k[c]('start'+b,function(e){if(!p){v();p=1;u()}})[c]('stop'+b,function(){v();p=0});k[c]('notify'+b,function(e,a){var i=x(a);if(i>-1)o=i});l.ssbound=1;if(y.jump)(B?k:w())[c](z,function(e){t(e,x(e.target))});if(q)q=$(q,j)[c](z,function(e){e.data=Math.round(w().length/q.length)*q.index(this);t(e,this)});function s(e){e.data+=o;t(e,this)};function t(e,a){if(!isNaN(a)){e.data=a;a=l}var c=e.data,n,d=e.type,f=y.exclude?w().slice(0,-y.exclude):w(),g=f.length,h=f[c],i=y.duration;if(d)e.preventDefault();if(p){v();r=setTimeout(u,y.interval)}if(!h){n=c<0?0:n=g-1;if(o!=n)c=n;else if(!y.cycle)return;else c=g-n-1;h=f[c]}if(!h||d&&o==c||y.lock&&k.is(':animated')||d&&y.onBefore&&y.onBefore.call(a,e,h,k,w(),c)===!1)return;if(y.stop)k.queue('fx',[]).stop();if(y.constant)i=Math.abs(i/A*(o-c));k.scrollTo(h,i,y).trigger('notify'+b,[c])};function u(){k.trigger('next'+b)};function v(){clearTimeout(r)};function w(){return $(m,l)};function x(a){if(!isNaN(a))return a;var b=w(),i;while((i=b.index(a))==-1&&a!=l)a=a.parentNode;return i}})}})(jQuery);
