$(document).ready(function(){
	ieHover('#menu li');
	clearInputs();
	claimForm();
	initAccordion();
	slideBox();
	btnFind();
	slideFooter();
});
/*--- slide footer function ---*/
function slideFooter(){
	var box_h = $('#footer > .block-hide');
	var _btn =  $('#footer > .diclamer');
	if(box_h.length && _btn.length){
		var _box = box_h.children();
		var _h;
		var _f = true;
		_btn.click(function(){
			if(_f){
				_f = false;
				if(!_box.is(':animated')){
					box_h.show();
					_h = _box.outerHeight();
					_box.css('margin-top', -_h);
				}
				_box.stop().animate({marginTop: 0}, 300);
			}
			else{
				_f = true;
				_h = _box.outerHeight();
				_box.stop().animate({marginTop: -_h}, 300, function(){
					box_h.hide();
				});
			}
			return false;
		});
	}
}
/*--- find button function ---*/
function btnFind(){
	var _btn = $('#btn-find');
	if(_btn.length){
		var _t = _btn.offset().top;
		$(window).scroll(function(){
			if($(window).scrollTop() > _t) _btn.css('top', $(window).scrollTop());
			else _btn.css('top', _t);
		});
	}
}
/*--- slide animation function ---*/
function slideBox(){
	var _hold = $('#munley-box');
	if(_hold.length){
		var _btn = _hold.find('a.btn');
		var box_h = _hold.find('.text-holder');
		var _box =  box_h.children();
		var _w;
		_btn.click(function(){
			if(!_box.is(':animated')){
				box_h.show();
				_w = _box.outerWidth();
				_box.css('margin-left', -_w);
			}
			_box.stop().animate({marginLeft: 0}, 300);
		});
		_hold.mouseleave(function(){
			_w = _box.outerWidth();
			_box.stop().animate({marginLeft: -_w}, 300, function(){
				box_h.hide();
			});
		});
		_box.mouseenter(function(){
			_box.stop().animate({marginLeft: 0}, 300);
		}).mouseleave(function(){
			_w = _box.outerWidth();
			_box.stop().animate({marginLeft: -_w}, 300, function(){
				box_h.hide();
			});
		});
	}
}


/*--- acccordion function ---*/
function initAccordion(){
	$('.accordion').each(function(){
		var _list = $(this).children();
		var _a = _list.index(_list.filter('.active:eq(0)'));
		_list.each(function(_i){
			var _el = $(this);
			_el.removeClass('active');
			this._btn = _el.children('.open-btn');
			this._box = _el.children('.inside').hide();
			if(_i == _a){
				this._box.show();
				_el.addClass('active');
			}
			this._btn.click(function(){
				if(_a != -1){
					_list.eq(_a).removeClass('active');
					_list.get(_a)._box.stop().animate({height: 0}, 400, function(){
						$(this).css({display: 'none', height: 'auto'});
					});
				}
				if(_a != _i){
					_list.eq(_i).addClass('active');
					if(!_list.get(_i)._box.is(':animated')){
						_list.get(_i)._h = _list.get(_i)._box.height();
						_list.get(_i)._box.css({height: 0, display:'block'});
					}
					_list.get(_i)._box.stop().animate({ height: _list.get(_i)._h}, 400, function(){
						$(this).height('auto');
					});
					_a = _i;
				}
				else{
					_a = -1;
				}
				return false;
			});
		});
	});
}
/*--- 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 ---*/
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;
		}
	});
}
/*--- claim form animation function */
function claimForm(){
	var _hold = $('#form-accident1');
	if(_hold.length){
		var box_h = _hold.find('.form-box');
		var _box = box_h.children();
		var _f = true;
		var _t, _h;
		var _f2 = true;
		var _f1 = true;
		_hold.find('input:text, textarea').focus(function(){	
			if(_t) clearTimeout(_t);
			_f1 = false;
			if(_f){
				_f = false;
				if(!_box.is(':animated')){
					box_h.show();
					_h = _box.outerHeight();
					_box.css('margin-top', -_h);
				}
				_box.stop().animate({marginTop: 0}, 300);
			}
		}).blur(function(){
			_f1 = true;
		});
		_hold.mouseleave(function(){
			_f2 = true;
			if(_f1){
				_t = setTimeout(function(){
					_f = true;
					_h = _box.height();
					_box.stop().animate({marginTop: -_h}, 300, function(){
						box_h.hide();
					});
				}, 500);
			}
		}).mouseenter(function(){
			_f2 = false;
			if(_t) clearTimeout(_t);
		});
		$('body').click(function(e){
			if(_f1 && _f2){
				_t = setTimeout(function(){
					_f = true;
					_h = _box.height();
					_box.stop().animate({marginTop: -_h}, 300, function(){
						box_h.hide();
					});
				}, 500);
			}
		});
	}
}

