/* Gallery (slide-on-click) */

jQuery.fn.gallSlide = function(_options){

	// defaults options	

	var _options = jQuery.extend({

		duration: 700,

		autoSlide: 5000

	},_options);



	return this.each(function(){

		var _hold = $(this);

		var _speed = _options.duration;

		var _timer = _options.autoSlide;

		var _wrap = _hold.find('ul.slider');

		var _el = _hold.find('ul.slider > li');

		var _next = _hold.find('a.right');

		var _prev = _hold.find('a.left');

		var _count = _el.index(_el.filter(':last'));

		var _w = _el.outerWidth();

		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);

		var _active = 0;

		function scrollEl(){

			_wrap.eq(0).animate({

				marginLeft: -(_w * _active) + "px"

			}, {queue:false, duration: _speed});

		}

		_next.click(function(){

			_active++;

			if (_active > (_count - _wrapHolderW + 1)) _active = 0;

			scrollEl();

			return false;

		});

		_prev.click(function(){

			_active--;

			if (_active < 0) _active = _count - _wrapHolderW + 1;

			scrollEl();

			return false;

		});

	});

}

$(document).ready(function(){

	$('div.gallery-box').gallSlide({

		duration: 700,

		autoSlide: 4000

	});

});
