 
Event.observe(window, 'load', loadQuickviewEvents);


function loadQuickviewEvents(event) {
	try {
		loadQuickviewMouseEvents();
	} catch(e) {
		alert('The loadQuickviewEvents() function generated an error.');
	}
} 


function loadQuickviewMouseEvents(event) {
	try {
		var productThumbs = $$('.productImage');
		if (productThumbs) { productThumbs.each( 
				function(o) {
					o.observe('mouseover', showQuickviewOnMouseOver); 
					o.observe('mouseout', hideQuickviewOnMouseOut); 
				}
			);
		}
	} catch(e) {
		alert('The loadQuickviewMouseEvents() function generated an error.');
	}
}


function showQuickviewOnMouseOver(event) {

	try {
		var elt = Event.element(event);
		var productId = elt.id.slice(4);
		var productUrl = Event.findElement(event, 'a').href;

		productUrl = productUrl.replace(/product.asp/g, 'quickproduct.asp');
		
		var eltTD = Event.findElement(event, 'td')
		
		eltTD.id = 'tdq_' + productId;
		
		Element.makePositioned(eltTD);
			
		var eltA = document.createElement('a');
		eltA.id = 'a_' + productId;
		eltA.href = productUrl;
		eltA.style.border = 'none';
		
		var eltIMG = document.createElement('img');
		eltIMG.id = 'quickimage_' + productId;
		eltIMG.src = 'quickView.png';
		eltIMG.className = 'quickview';
		eltIMG.style.height = 38;
		eltIMG.style.width = 90;
		eltIMG.style.border = 'none';
		eltIMG.style.zIndex = 10;
		eltIMG.style.top = 100; 
		eltIMG.style.left = 25;
		eltIMG.style.position = 'absolute';
		
		eltA.appendChild(eltIMG);
		eltTD.appendChild(eltA);
		
		var myOffsetLeft = ((elt.getWidth() - 90) / 2);    //25;
		var myOffsetTop = ((elt.getHeight() - 38) / 2);     //75;
		
		Element.clonePosition(eltIMG, elt, 
			{
				setTop: true, 
				setLeft: true, 
				setHeight: false, 
				setWidth: false, 
				offsetLeft: myOffsetLeft, 
				offsetTop: myOffsetTop
			}
		);
		
		var quickviews = $$('.quickview').without(eltIMG);
		quickviews.each( function(o) { o.hide(); } );
		
		$(eltA).observe('click', openQuickviewWindow);
		
	} catch(e) {
		alert('The showQuickviewOnMouseOver() function generated an error.');
	}
}


function hideQuickviewOnMouseOut(event) {
	
	try {
		var eltTD = Event.findElement(event, 'td');
		var elt = eltTD.down('.productImage');
		
		var elementTop = elt.cumulativeOffset().top + 10;
		var elementLeft = elt.cumulativeOffset().left + 10;
		var elementHeight = (elementTop + elt.getHeight() - 20);
		var elementWidth = (elementLeft + elt.getWidth() - 20);
		var pointTop = Event.pointerY(event);
		var pointLeft = Event.pointerX(event);
		
		if ((pointTop >= elementTop) && 
			(pointTop <= elementHeight) &&
			(pointLeft >= elementLeft) &&
			(pointLeft <= elementWidth)) {
		} else {
			var quickviews = $$('.quickview');
			quickviews.each( function(o) { o.hide(); } );
		}
	} catch(e) {
		alert('The hideQuickviewOnMouseOut() function generated an error.');
	}
}


function openQuickviewWindow(event) {
	try {
		var elt = Event.findElement(event, 'a');
		event.returnValue = false;
		hs.htmlExpand(elt, 
			{ 
				objectType: 'iframe', 
				height: 475, 
				maxHeight: 700,
				minHeight: 300, 
				width: 550,
				allowHeightReduction: true
			}
		);
		Element.hide.delay(1, elt.firstDescendant());
	} catch(e) {
		alert('The openQuickviewWindow() function generated an error.');
	}
	try { 
		Event.stop(event); 
	} catch(e) { 
		alert('Failed to stop event in openQuickviewWindow() function.'); 
	}
	return false;
}


function closeQuickviewWindow() {
	try {
		var oCloseLink = window.parent.document.getElementById('highslide-close-link');
		try { oCloseLink.onclick(); } catch(e){}
		try { oCloseLink.click(); } catch(e){}
	} catch(e) {
		alert('The closeQuickviewWindow() function generated an error.');
	}
	return false;
}

