jQuery(document).ready(function(){
	clearInputs();
	ieHover('ul.catalog > li, div.div-class, span, #box, #nav > li');
	jQuery('div.navigation').each(function(){
		if(jQuery(this).children('div:empty').length == 2) jQuery(this).remove();
	});
});
/*---- clear inputs ---*/
function clearInputs(){
	jQuery('input:text, input:password, textarea').each(function(){
		var _el = jQuery(this);
		_el.data('val', _el.val());
		_el.bind('focus', function(){
			if(_el.val() == _el.data('val')) _el.val('');
		}).bind('blur', function(){
			if(_el.val() == '') _el.val(_el.data('val'));
		});
	});
}
/*--- IE6 hover ---*/
function ieHover(h_list, h_class){
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		if(!h_class) var h_class = 'hover';
		jQuery(h_list).mouseenter(function(){
			jQuery(this).addClass(h_class);
		}).mouseleave(function(){
			jQuery(this).removeClass(h_class);
		});
	}
}
/*--- gallery ---*/
jQuery(document).ready(function(){
	var _t;
	var _hold = jQuery('div.gallery-holder div');
	var _slide = _hold.find('ul');
	var _list = _slide.find('>li');
	var _prev = jQuery('.link-prev a');
	var _next = jQuery('.link-next a');
	var _d = _list.eq(1).outerWidth(true);	
	var _vis = Math.ceil(_hold.width()/_d);	
	var _ws = _list.length*_d;	
	var _wp2 = _vis*_d;
	var _x = 0;	
	var _a = 0;
	for	(var i=0; i < _vis; i++){	
		_list.eq(i).clone().appendTo(_slide);
	};
	_next.click(function(){
		if (_x<_ws){
			_x = _x + _d;
			_a++
			if (_a==_list.length){_a=0}
		}
		else {
			_slide.css({marginLeft:0});
			_x = _d; 
			_a=1;
		};
		RunAnimation(_x,_a);
		return false;
	})	
	_prev.click(function(){		
			if (_x>0){
				_x = _x - _d;
				_a--
				if (_a==-1){_a=_list.length - 1};
			}					
			else {
				_slide.css({marginLeft:-_ws});
				_x = _ws-_d;
				_a=_list.length - 1;
				
			};
		RunAnimation(_x,_a);
		return false;
	});
	var _t;
	function runTimer(){
		if(_t) clearInterval(_t);
		_t = setInterval(function(){
			if (_x<_ws){
				_x = _x + _d;
				_a++
				if (_a==_list.length){_a=0}
			}
			else {
				_slide.css({marginLeft:0});
				_x = _d; 
				_a=1;
			};	
			RunAnimation(_x,_a);
		}, 7000);
	}
	runTimer();
	function RunAnimation(_x,_a){
		_slide.animate({marginLeft: -_x}, {queue:false, duration:500, complete:function(){
			runTimer();
		}});
	};
});

