var currentPreview = null;
var magnifireProcess_show = {}, magnifireProcess_hide = {};

function showPreview(event, caller) {
	
	var template = document.getElementById('win');
	
	if (document.getElementById('win_' + caller.getAttribute('value'))) {
		var item = document.getElementById('win_' + caller.getAttribute('value'));
		var image = document.getElementById('moreinfo_' + caller.getAttribute('value') + '_image');
		image.src = image.getAttribute('defaultsrc');
		
		var callRequst = document.getElementById('win_' + caller.getAttribute('value') + '_tnk');
		if (callRequst.callRequestHTML) callRequst.innerHTML = callRequst.callRequestHTML;
		callRequst.className = '';
		
	} else {
		var item = template.cloneNode(true);
		item.id = 'win_' + caller.getAttribute('value');
		document.body.appendChild(item);
		item.detail = document.getElementById('moreinfo_' + caller.getAttribute('value'));
		item.detail.style.display = 'block';
		item.getElementsByTagName('div')[2].appendChild(item.detail);
	}

	if (!item.isOpen) {
		if (currentPreview != null && currentPreview != item) {hidePreview(currentPreview);}
		currentPreview = item;

		item.opacity = 0;
		item.style.display = '';
//		document.title += item.offsetWidth + '';
		item.style.left = (window.innerWidth) ? ((window.innerWidth - item.offsetWidth) / 2) : ((document.body.offsetWidth - item.offsetWidth) / 2);
		item.style.top = (window.innerHeight) ? ((window.innerHeight - item.offsetHeight) / 2 + document.body.scrollTop) : ((document.body.offsetHeight - item.offsetHeight) / 2 + document.body.scrollTop);
		
		magnifireProcess_show[item.id] = setInterval(function() {magnifire(item, .3)}, 1);
		item.isOpen = true;
	}
}

function hidePreview(item) {
	var postAction = function() {
		magnifireProcess_hide[item.id] = setInterval(function() {magnifire(item, -.8)}, 1);
		item.isOpen = false;
		currentPreview = null;
		var _ = document.getElementById('moreinforequest_cur');
		if (_) {_.removeAttribute('id'); _.id = null;}
	}
	
	if (document.getElementById('moreinforequest_cur')) {
		hideRequestForm(document.getElementById('moreinforequest_cur'), postAction);
	} else {
		postAction();
	}
}


function magnifire(element, inc, postAction) {
	element.opacity += inc;

	if (element.opacity < 0) {
		clearInterval(magnifireProcess_hide[element.id]);
		element.style.display = 'none';
		if (postAction) postAction();
//		return;
	}
	if (element.opacity > 1) {
		clearInterval(magnifireProcess_show[element.id]);
		if (postAction) postAction();
		if (element.runtimeStyle) {element.runtimeStyle.filter = ''; return;}
	}
	
	if(element.runtimeStyle) {
		element.runtimeStyle.filter = 'Alpha(opacity=' + element.opacity*100 + ')';
	} else {
		element.style.opacity = element.opacity;
	}
}




function getParentByType(element, type) {
	while (element.getAttribute('type') != type) {
		element = element.parentNode;
	}
	return element;
}