function zoom(e) { var amount = Event.wheel(e); zoom_helper(amount); e.stop(); } function zoom_helper(amount) { var delta = 6; var new_width = $('large_image').width + (amount * delta); if( original_width == 0 ) { original_width = $('large_image').width; } if( new_width >= original_width ) { $('large_image').style.width = new_width + 'px'; } if ( zooming == 1 ) { window.setTimeout( "zoom_helper(" + amount + ")", 80 ); } } function zoom_reset() { stopzoom(); if( original_width > 0 ) { $('large_image').style.width = original_width + 'px'; } } function display_photo (e) { var element = Event.element(e); var id_arr = element.id.split('/'); $('large_image').src = '/machinery/database/' + id_arr[1] + '/' + id_arr[2] + '_m.png'; original_width = 0; $$('img.view_thumbnail').each( function (i) { i.removeClassName('selected'); } ); element.addClassName('selected'); } function startzoom(quantity) { if ( zooming == 0 ) { zooming = 1; window.setTimeout( "zoom_helper(" + quantity + ")", 80 ); } } function stopzoom() { zooming = 0; } function init() { $('large_image').observe('mousewheel', zoom); $('large_image').observe('DOMMouseScroll', zoom); $$('img.view_thumbnail').each( function (i) { i.observe( 'click', display_photo ); } ); $('img_zoom_reset').observe('click', zoom_reset); //$('img_zoom_in').observe('click', function () { zoom_helper(3); } ); $('img_zoom_in').observe('mousedown', function (e) { startzoom(2); } ); $('img_zoom_in').observe('mouseup', function (e) { stopzoom(); } ); //$('img_zoom_out').observe('click', function () { zoom_helper(-3); } ); $('img_zoom_out').observe('mousedown', function (e) { startzoom(-2); } ); $('img_zoom_out').observe('mouseup', function (e) { stopzoom(); } ); } Object.extend( Event, { wheel:function (e){ var delta = 0; if (!e) e = window.event; if (e.wheelDelta) { delta = e.wheelDelta / 120; if ( window.opera ) delta = delta * -1; } else if ( e.detail ) { delta = (e.detail * -1) / 3; } return Math.round(delta); } } ); var original_width = 0; var zooming = 0; document.observe('dom:loaded', init);