get = function (id)
{
	return document.getElementById(id) || false;
}

openLinksForJump = function (e)
{
	var target = e ? e.target : window.event.srcElement;
	if (target.tagName !== 'A')
	{
		blockEvent(e);
		get('fastjump').className = get('fastjump').className.search('open') == -1 ? get('fastjump').className.replace('closed', 'open') : get('fastjump').className.replace('open', 'closed');
	}
}

closeLinksForJump = function ()
{
	get('fastjump').className = get('fastjump').className.replace('open', 'closed');
}

showFormSearch = function (e)
{
	blockEvent(e);
	if (window.passiveBird)
	{
		window.passiveBird();
	}
	get('overlay').style.height = (document.documentElement.scrollHeight) + 'px';
	get('overlay').style.display = get('search').style.display = '';
	var top = (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) + (document.documentElement.clientHeight / 2) - (get('search').clientHeight / 2);
	get('search').style.top = (top > 0 ? top : 0) + 'px';
	get('from').className = 'js';
	get('from').onclick = function () {
		get('to').value = get('from').innerHTML;
	}
	window.onresize = window.onscroll = resize;
}

showListProducers = function (e)
{
	blockEvent(e);
	if (window.passiveBird)
	{
		window.passiveBird();
	}	
	get('overlay').style.height = (document.documentElement.scrollHeight) + 'px';
	get('overlay').style.display = get('producers').style.display = '';
	var top = (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) + (document.documentElement.clientHeight / 2) - (get('producers').clientHeight / 2);
	get('producers').style.top = (top > 0 ? top : 0) + 'px';
	window.onresize = window.onscroll = resize;
}

resize = function ()
{
	get('overlay').style.height = (document.documentElement.scrollHeight) + 'px';
}

closeFormSearch = function (e)
{
	blockEvent(e);
	get('overlay').style.display = get('search').style.display = 'none';
	if (window.activeBird)
	{
		window.activeBird();
	}
	get('from').onclick = window.onresize = window.onscroll = function () {};
}

closeListProducers = function (e)
{
	blockEvent(e);
	get('overlay').style.display = get('producers').style.display = 'none';
	if (window.activeBird)
	{
		window.activeBird();
	}
	window.onresize = window.onscroll = function () {};
}

closeErrorBlock = function (e)
{
	blockEvent(e);
	get('error-block').parentNode.removeChild(get('error-block'));
}

closeErrorBlockLogin = function (e)
{
	blockEvent(e);
	get('error-block-l').parentNode.removeChild(get('error-block-l'));
}

switchBrandListToGroup = function (e)
{
	blockEvent(e);
	get('brandlist-ul').style.display = 'none';
	get('brandlist').style.display = 'none';
	get('group_brandlist-ul').style.display = '';
	get('group_brandlist').style.display = '';
}

switchBrandListToAll = function (e)
{
	blockEvent(e);
	get('brandlist-ul').style.display = '';
	get('brandlist').style.display = '';
	get('group_brandlist-ul').style.display = 'none';
	get('group_brandlist').style.display = 'none';
}



blockEvent = function (event)
{
	event = event || window.event;
	if(event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if(event.preventDefault) event.preventDefault();
	else event.returnValue = false;
}

if (window.loadFuncs)
{
	window.loadFuncs[window.loadFuncs.length] = function ()
	{
		if (get('fastjump'))
		{
			get('fastjump').className = get('fastjump').className.replace('open', 'closed');
			get('fastjump').onclick = openLinksForJump;
		}
		if (get('link-search'))
		{
			get('link-search').onclick = showFormSearch;
			get('close-search').onclick = closeFormSearch;
		}
		if (get('link-producers'))
		{
			get('link-producers').onclick = showListProducers;
			get('close-producers').onclick = closeListProducers;
		}
		if (get('error-block') && get('close-error-block'))
		{
			get('close-error-block').onclick = closeErrorBlock;
		}
		if (get('error-block-l') && get('close-error-block-l'))
		{
			get('close-error-block-l').onclick = closeErrorBlockLogin;
		}
		
		// бренды в каталоге
		if (get('to_group') && get('to_all') && get('brandlist-ul') && get('group_brandlist-ul'))
		{
			get('to_group').onclick = switchBrandListToGroup;
			get('to_all').onclick = switchBrandListToAll;
		}
		
		if (get('showForm') && get('form')) 
		{
			if (get('form').className.search('error') == -1)
			{
				get('showForm').onclick = function (e) {
					blockEvent(e);
					get('form').style.display = '';
					this.className = 'nojs';
				}
				get('showForm').className = 'js';
				get('form').style.display = 'none';
			}
		}		

		
		//document.onclick = closeLinksForJump;
	}
}
else
{
	window.loadFuncs = new Array(function ()
	{
		if (get('fastjump'))
		{
			get('fastjump').className = get('fastjump').className.replace('open', 'closed');
			get('fastjump').onclick = openLinksForJump;
		}
		if (get('link-search'))
		{
			get('link-search').onclick = showFormSearch;
			get('close-search').onclick = closeFormSearch;
		}
		if (get('link-producers'))
		{
			get('link-producers').onclick = showListProducers;
			get('close-producers').onclick = closeListProducers;
		}
		if (get('error-block') && get('close-error-block'))
		{
			get('close-error-block').onclick = closeErrorBlock;
		}
		if (get('error-block-l') && get('close-error-block-l'))
		{
			get('close-error-block-l').onclick = closeErrorBlockLogin;
		}
		
		// бренды в каталоге
		if (get('to_group') && get('to_all') && get('brandlist-ul') && get('group_brandlist-ul'))
		{
			get('to_group').onclick = switchBrandListToGroup;
			get('to_all').onclick = switchBrandListToAll;
		}
		
		if (get('showForm') && get('form')) 
		{
			if (get('form').className.search('error') == -1)
			{
				get('showForm').onclick = function (e) {
					blockEvent(e);
					get('form').style.display = '';
					this.className = 'nojs';
				}
				get('showForm').className = 'js';
				get('form').style.display = 'none';
			}
		}		
		//document.onclick = closeLinksForJump;
	});
}
