hideform = function ()
{
	get(window.id).appendChild(get(window.id + 'form'));
	get('popup').style.display = get('popupbg').style.display = 'none';
	get('close').onclick = function () {};
}

showform = function (e)
{
	var target = e ? e.target : window.event.srcElement;
	blockEvent(e);
	window.id = target.id.replace('link-', '');
	
	get('popupbg').style.height = document.documentElement.scrollHeight + 'px';
	get('popup').insertBefore(get(id + 'form'), get('popup-before'));
	get('popup').style.display = get('popupbg').style.display = '';
	get('close').onclick = hideform;
}

showformStatus = function (id)
{
	window.id = id;
	
	get('popupbg').style.height = document.documentElement.scrollHeight + 'px';
	get('popup').insertBefore(get(id + 'form'), get('popup-before'));
	get('popup').style.display = get('popupbg').style.display = '';
	get('close').onclick = hideform;
}

get = function (id)
{
	return document.getElementById(id) || false;
}

blockEvent = function (event)
{
	event = event ? event : window.event;
	if(event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if(event.preventDefault) event.preventDefault();
	else event.returnValue = false;
}

show = function (e)
{
	var target = e ? e.target : window.event.srcElement;
	target = target.tagName == 'A' ? target : target.parentNode;
	if (target.tagName == 'A')
	{
		blockEvent(e);
		get('photo').style.visibility = 'hidden';
		get('photodiv').className = 'photodiv';
		var img = new Image();
		img.src = target.rel;
		if (!img.height) 
		{
			img.onload = function () {
				get('photo').src = this.src;
				get('photo').style.visibility = 'visible';
				get('photodiv').className = 'photo';
			};
		}
		else 
		{
			get('photo').src = img.src;
			get('photo').style.visibility = 'visible';
			get('photodiv').className = 'photo';
		}
		var list = get('list');
		var links = list.getElementsByTagName('A');
		for (var i in links)
		{
			links[i].className = '';
		}
		target.className = 'sel';
	}
}

window.onload = function ()
{
	var photo = get('photo');
	var list = get('list');
	
	if (photo && list)
	{
		var links = list.getElementsByTagName('A');
		for (var i in links)
		{
			links[i].onclick = show;
		}
	}
	
	if (get('inquire') && get('showing'))
	{
		get('inquire').style.display = get('showing').style.display = 'none';
		get('link-inquire').onclick = get('link-showing').onclick = showform;
		if (get('inquire').className == 'form_active') showformStatus('inquire');
		if (get('showing').className == 'form_active') showformStatus('showing');
	}
	
	if (get('link-print'))
	{
		get('link-print').onclick = function (e)
		{
			blockEvent(e);
			window.print();
		}
	}
}
