document.observe("dom:loaded", function() {
	// Wire up the other image links beneath the main product image
    $('Product-Image').select('a').each(function(link) {
		try {
		    link.observe('click', function(event) {
				open(this.href, 'other_image_popup', 'height=500,width=500,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
				Event.stop(event);
			});
		} catch(e) {
			// nothing
		}
	});

    try {
		// Wire up add-to-cart and add-to-req-list buttons
		$('itemDisplayAddToCart').observe('click', function(event) {
			Add2ShopCart(document.getElementById('Product-Order-Add-Form'));
			Event.stop(event);
		});
	} catch (e) {
		// nothing
	}

    try {
		$('itemDisplayAddToReqList').observe('click', function(event) {
			Add2ReqList(document.getElementById('Product-Order-Add-Form'));
			Event.stop(event);
		});
	} catch (e) {
		// nothing
	}

	// Wire up the tab control at the bottom of the page
    var tabs  = $('Product-Tabs').select('li');
	var panes = $('Product-Tab-Panes').select('.tab-panes');
	tabs.each(function(tab) {
	    // add handler to link to activate the clicked tab and hide others
		try {
		    tab.select('a')[0].observe('click', function(event) {
				$('Product-Tabs').select('.active').invoke('removeClassName', 'active');
				$('Product-Tab-Panes').select('.active').invoke('removeClassName', 'active');
				tab.addClassName('active');
				var paneId = this.href.slice(this.href.indexOf('#') + 1);
				$(paneId).addClassName('active');
				Event.stop(event);
			});
		} catch(e) {
			// nothing
		}
	});
});

