/* 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');
		var _el = _hold.find('ul > li');
		var _elLinks = _hold.find('ul > li > a');
		var _next = _hold.find('a.link-next');
		var _prev = _hold.find('a.link-prev');
		var _holdIMG = $('.box-photo > li');
		var _count = _el.index(_el.filter(':last'));
		var _h = _el.outerHeight();
		var _wrapHolderH = Math.ceil(_wrap.parent().height()/_h);
		var _active = 0;
		var _activeIMG = _holdIMG.index(_holdIMG.filter('.active'));
		if (_activeIMG <0) _activeIMG = 0;
		var _tmp = _activeIMG;
		_holdIMG.removeClass('active').css({opacity: 0}).eq(_activeIMG).addClass('active').css({opacity: 1});
		function scrollEl(){
			_wrap.eq(0).animate({
				marginTop: -(_h * _active) + "px"
			}, {queue:false, duration: _speed});
		}
		_next.click(function(){
			_active += _wrapHolderH;
			if (_active > (_count)) _active = 0;
			scrollEl();
			return false;
		});
		_prev.click(function(){
			_active -= _wrapHolderH;
			if (_active < 0) _active = _count-(_count%_wrapHolderH);
			scrollEl();
			return false;
		});
		/*_elLinks.click(function(){
			if (_activeIMG != _elLinks.index($(this))){
				_activeIMG = _elLinks.index($(this));
				_holdIMG.eq(_tmp).removeClass('active').animate({
					opacity: 0
				},{queue:false, duration:_speed});
				_holdIMG.eq(_activeIMG).addClass('active').animate({
					opacity: 1
				},{queue:false, duration:_speed});
				_tmp = _activeIMG;
			}
			return false;
		});*/
	});
}

$(document).ready(function(){
	$('div.gallery').gallSlide({
		duration: 500,
		autoSlide: 4000
	});
});
