$(document).ready(function(){
	
	hideFormText();
	
	// animate forms ***********************************************************
	var _slideHelp = 400;
	var _topHelp = $('#header div.get-hellp fieldset');
	_topHelp.active = false;
	_topHelp.form = $('input, select, textarea',_topHelp);
	var _tHeight = _topHelp.find('div.form-holder').height() + 6;
	_topHelp.hover(function(){
		this.timer = setTimeout(function(){
			_topHelp.animate({height:_tHeight},{queue:false, duration:_slideHelp});
		}, 300);
	}, function(){
		if (this.timer) clearTimeout(this.timer);
		if (!_topHelp.active)
			_topHelp.animate({height:61},{queue:false, duration:_slideHelp});
	});
	_topHelp.form.focus(function(){
		_topHelp.active = true;
	});
	_topHelp.form.blur(function(){
		_topHelp.active = false;
	});
	
	// click out ***************************************************************
	$('body').click(function(e){
		var _close = true;
		if(!e) e = window.event;
        var _target = (e.target || e.srcElement);
		if (!$(_target).is('div.get-hellp')) {
			var _parent = _target;
			for (var i=0; i<$(_target).parents().length; i++) {
				_parent = _parent.parentNode;
				if ($(_parent).is('div.get-hellp')) {
					_close = false;
					break;
				}
			}
			if (_close) {
				_topHelp.animate({height:61},{queue:false, duration:_slideHelp});
			}
		}
	});
	
	// accordion ***************************************************************
	if (typeof $().accordion == 'function') {
		$('ul.accordeon').accordion({
			autoHeight: false,
			collapsible: true,
			active: false
		});
	}
	
	// footer dynamic block ****************************************************
	var _slideDuration = 500;
	var _footerBt = $('#footer a.open-link');
	var _footerBlock = $('#footer div.tabs');
	var _open = false;
	_footerBt.click(function(){
		if (!_open) _open = true;
		else _open = false;
		_footerBlock.slideToggle(_slideDuration, function(){
			if (_open) {
				if (typeof $().scrollTo == 'function') {
					$(window).scrollTo(_footerBlock, 800);
				}
			}
		});
		return false;
	});
	
	// news fade ***************************************************************
	var _news = $('div.fade-box li');
	$('div.fade-box li').removeClass('active');
	$('div.fade-box li:first').addClass('active');
	var _switchTime = 8000 // 5 sec
	var _newsFade = 1000;
	var _newsTimer = setTimeout(function(){fadeNews()}, _switchTime);
	function fadeNews(){
		var _active = _news.filter('.active');
		_active.removeClass('active').fadeOut(_newsFade, function(){
			if (_active.next().is('li')) {
				_active.next().addClass('next');
			} else {
				_news.eq(0).addClass('next');
			};
			_news.filter('.next').fadeIn(_newsFade, function(){
				$(this).removeClass('next').addClass('active');
				_newsTimer = setTimeout(function(){fadeNews()}, _switchTime);
			});
		});
	};
	_news.hover(function(){
		if (_newsTimer) clearTimeout(_newsTimer);
	}, function(){
		_newsTimer = setTimeout(function(){fadeNews()}, _switchTime);
	});
	
});

// hide text form **************************************************************
function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}