/*--- faid gallery ---*/
function faidGall(){
	var stay_time = 7000; //in ms
	var change_speed = 500; //in ms
	var _hold = $('#faid-gall');
	if(_hold.length){
		var _list = _hold.children('div.slider');
		if(_list.length > 1){
			var _a = _list.index(_list.filter('.active:eq(0)'));
			if(_a == -1) _a = 0;
			var _f = true;
			var _f1 = true;
			var _t;
			if($.browser.msie && $.browser.version < 7) _list.removeClass('active').hide().eq(_a).addClass('active').show();
			else _list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
			var btn_h = $('<ul class="numbers"></ul>');
			_hold.append(btn_h);
			for(var i = 0; i < _list.length; i++){
				btn_h.append('<li><a href="#">'+(i+1)+'</a></li>');
			}
			var _btn = btn_h.find('a');
			_btn.eq(_a).addClass('active');
			
			_hold.mouseenter(function(){
				if(_t) clearTimeout(_t);
				_f = false;
			}).mouseleave(function(){
				if(_t) clearTimeout(_t);
				_f = true;
				if(_f && _f1){
					_t = setTimeout(function(){
						if(_a < _list.length - 1) changeEl(_a + 1);
						else changeEl(0); 
					}, stay_time);
				}
			});
			_btn.click(function(){
				_f1 = false;
				changeEl(_btn.index(this));
				return false;
			});
			function changeEl(_ind){
				if(_t) clearTimeout(_t);
				if(_ind != _a){
					_btn.eq(_a).removeClass('active');
					_btn.eq(_ind).addClass('active');
					if($.browser.msie && $.browser.version < 7){
						_list.eq(_a).removeClass('active').hide();
						_list.eq(_ind).addClass('active').show();
					}
					else{
						_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:change_speed});
						_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:change_speed});
					}
					_a = _ind;
				}
				if(_f && _f1){
					_t = setTimeout(function(){
						if(_a < _list.length - 1) changeEl(_a + 1);
						else changeEl(0); 
					}, stay_time);
				}
			}
			if(_f && _f1){
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0); 
				}, stay_time);
			}
		}
		
	}
}
/*--- IE6 hover ---*/
function ieHover(h_list){
	if ($.browser.msie && $.browser.version < 7){
		$(h_list).hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});
	}
}
/*---- clear inputs ---*/
function clearInputs(){
	$('input:text, input:password, textarea').each(function(){
		if(!this.val) this.val = this.value;
		this.onfocus = function(){
			if(this.value == this.val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this.val;
		}
	});
}

$(document).ready(function(){
	ieHover('#navigation > li');
	clearInputs();
	faidGall();
});
