jQuery.fn.gallSlide = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 7000
	},_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 _next = _hold.find('a.next');
		var _prev = _hold.find('a.prev');
		var _count = _el.index(_el.filter(':last'))+1;
		var _w = _el.outerWidth();
		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);
		var _t;
		var _active = _count;
		var temp = _el.clone();
		_wrap.append(temp);
		temp = _el.clone();
		_wrap.append(temp);
		var flag = true;
		
		_wrap.css({marginLeft: -(_w * _active) + "px"});
		function scrollEl(){
			_wrap.animate({
				marginLeft: -(_w * _active) + "px"
			}, _speed, function(){
				if (_active == _count+_count) {
					_active = _count
					_wrap.css({marginLeft: -(_w * _active) + "px"});
				}
				if (_active == _count-1) {
					_active = _count+_count-1
					_wrap.css({marginLeft: -(_w * _active) + "px"});
				}
				flag = true;
			});
		}
		function runTimer(){
			_t = setInterval(function(){
				if (flag) {
					flag = false;
					_active++;
					scrollEl();
				}
			}, _timer);
		}
		runTimer();
		_next.click(function(){
			if (flag){
				flag = false;
				_active++;
				if(_t) clearTimeout(_t);
				scrollEl();
				runTimer();
			}
			return false;
		});
		_prev.click(function(){
			if (flag) {
				flag = false;
				_active--;
				if (_t) clearTimeout(_t);
				scrollEl();
				runTimer();
			}
			return false;
		});
	});
}

function initZip(){
	$('div.tabs-wrapper').each(function(){
		var hold = $(this);
		var input1 = hold.find('#tab-1 > form.search-form input.text:eq(0)');
		var input2 = hold.find('#tab-2 > form.search-form input.text:eq(0)');
		var input3 = hold.find('#tab-2 > form.search-form input.text:eq(1)');
		
		input1.keyup(function(){
			input2.val(input1.val());
			input3.val(input1.val());
		});
	});
}

$(document).ready(function(){
	$('div.gallery').gallSlide({
		duration: 700,
		autoSlide: 6000
	});
	initZip();
});

