// BUILT ON TOP OF JQUERY /////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/*************************************************************************************************/

$(document).ready(function() {
						   
	$("ul li:first-child").addClass("first-child");
	$("gallery img:last-child").addClass("last-child");
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// init the site's horizontal scrolling mechanism
	
	$.localScroll({
		//target: '#projects', // could be a selector or a jQuery object too. (doesn't like this)
		duration:1000,
		//hash:true,
		axis:'x',
		onBefore:function( e, anchor, $target ){
		},
		onAfter:function( anchor, settings ){
		}
	});

	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// init the 'homepage' scrolling image carousel
	
	//// JQUERY PLUGIN - EASING
	jQuery.easing={easein:function(x,t,b,c,d){return c*(t/=d)*t+b},easeinout:function(x,t,b,c,d){if(t<d/2)return 2*c*t*t/(d*d)+b;var a=t-d/2;return-2*c*a*a/(d*d)+2*c*a/d+c/2+b},easeout:function(x,t,b,c,d){return-c*t*t/(d*d)+2*c*t/d+b},expoin:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(Math.exp(Math.log(c)/d*t))+b},expoout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b},expoinout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}if(t<d/2)return a*(Math.exp(Math.log(c/2)/(d/2)*t))+b;return a*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b},bouncein:function(x,t,b,c,d){return c-jQuery.easing['bounceout'](x,d-t,0,c,d)+b},bounceout: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}},bounceinout:function(x,t,b,c,d){if(t<d/2)return jQuery.easing['bouncein'](x,t*2,0,c,d)*.5+b;return jQuery.easing['bounceout'](x,t*2-d,0,c,d)*.5+c*.5+b},elasin: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},elasout: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},elasinout: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},backin:function(x,t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},backout:function(x,t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},backinout:function(x,t,b,c,d){var 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},linear:function(x,t,b,c,d){return c*t/d+b}};

	
	// dynamically move some assets...
	
	// move the images from carouselContent div into carousel
	// this is so that any extra markup/content stays within carouselContent & doesn't affect the carousel
	$("#carouselContent img").appendTo("#carousel");
	$("#carouselInner img").wrap("<li></li>");
	
	$("#carouselInner").jCarouselLite({
		auto: 20,
		speed: 4000,
		circular: true,
		visible: 6
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// nav event handlers
	
	$('#projectNav a').click(function () {
	  $('#projectNav a').removeClass('selected');
	  $(this).addClass('selected');
	});
	
	$('.right a').click(function () {
		$('#projectNav a.link1').addClass('selected');
	});
	
	$('#logo a').click(function () {
	  $('#projectNav a').removeClass('selected');
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// newsletter form stuff
	$('#newsletter input.emailaddress').click(function () {
	  $(this).select();
	});
	
	//if ($('#newsletter input.emailaddress').val() == "") $('#newsletter input.emailaddress').val("Enter your email address")
	
	///////////////////////////////////////////////////////////////////////////////////////////////

	// init fancybox, see for more http://fancybox.net/api
	$(".gallery .item .itemInner a").fancybox({
		'titlePosition' : 'inside'
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////

	// gallery drop shadows
	/*$('#sliderContent1 img').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});
	$('#sliderContent2 img').dropShadow({left: 1, top: 1, opacity: 0.6, blur: 2});
	$('#sliderContent3 img').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});
	$('#sliderContent4 img').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});
	//$('#sliderContent5 img').dropShadow({left: 1, top: 1, opacity: 0.6, blur: 2}); // the logos
	$('#sliderContent6 img').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});
	$('#sliderContent7 img').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});*/
	
	// changed this so that dropshadows need to be specified, with a CSS class of shadow
	$('.gallery img.shadow').dropShadow({left: 2, top: 2, opacity: 0.6, blur: 2});
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// vertically align each gallery image
	$('.gallery img').each(function() {
			var ah = $(this).height();
			if (ah < 300) {
				var ph = 300; //$(this).parent().height();
				var mh = (ph - ah) / 2;
				//alert ('mh = '+mh);
				$(this).css('margin-top', mh);
			}
    	}
    );
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	// reset all sliders on primary nav click
	$('#projectNav a').click(function() {
		$('#slider1').slider("value", 0 );
		$('#slider2').slider("value", 0 );
		$('#slider3').slider("value", 0 );
		$('#slider4').slider("value", 0 );
		$('#slider5').slider("value", 0 );
		$('#slider6').slider("value", 0 );
		$(".content-conveyor").css("left", "0px");
	});

	
});
