$(function($){
	
	$('#slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 5000,
		pause: 3500,
		hoverPause: true,
		animationStart: function(){
			$('.caption').animate({
				bottom:-35
			},400);
		},
		animationComplete: function(current){
			$('.caption').animate({
				bottom:0
			},300);
			if (window.console && console.log) {
				// example return of current slide number
				console.log(current);
			};
		}
	});
	
	$('#gallerygrid').jphotogrid({
		baseCSS: {
			width: '200px',
			height: '100px',
			padding: '0px'
		},
		selectedCSS: {
			left: '105px',
			width: '500px',
			height: '500px',
			padding: '10px'
		}
		});
		
	$('#contentWrapper').height($(document).height() - 400)

	// Scroll
	$.localScroll();

	// Link Nudge
	$('#sidebar #navigation li a').nudge();
});

jQuery.fn.nudge = function(params) {
	//set default parameters
	params = jQuery.extend({
		amount: 15,				//amount of pixels to pad / marginize
		duration: 300,			//amount of milliseconds to take
		property: 'padding', 	//the property to animate (could also use margin)
		direction: 'left',		//direction to animate (could also use right)
		toCallback: function() {},	//function to execute when MO animation completes
		fromCallback: function() {}	//function to execute when MOut animation completes
	}, params);
	//For every element meant to nudge...
	this.each(function() {
		//variables
		var jQueryt = jQuery(this);
		var jQueryp = params;
		var dir = jQueryp.direction;
		var prop = jQueryp.property + dir.substring(0,1).toUpperCase() + dir.substring(1,dir.length);
		var initialValue = jQueryt.css(prop);
		/* fx */
		var go = {};
		go[prop] = parseInt(jQueryp.amount) + parseInt(initialValue);
		var bk = {};
		bk[prop] = initialValue;
		
		//Proceed to nudge on hover
		jQueryt.hover(function() {
			jQueryt.stop().animate(go, jQueryp.duration, '', jQueryp.toCallback);
		}, function() {
			jQueryt.stop().animate(bk, jQueryp.duration, '', jQueryp.fromCallback);
		});
	});
	return this;
};
