inMotion = false;

function snapshot_switch( snapshot, width, height ) {
	if( !inMotion ) {
		inMotion = true;
		new_frame = ( /blank/.test( $('frame_1').style.backgroundImage ) )
			? $('frame_1') : $('frame_2');
		old_frame = ( /blank/.test( $('frame_1').style.backgroundImage ) )
			? $('frame_2') : $('frame_1');
		new Effect.Fade( old_frame, 
						{ duration:.8,
						afterFinish:function() { 
							old_frame.style.backgroundImage = "url('/images/blank.gif')"; 
							} 
						} );
		cache_image = new Image;
		cache_image.onload = function() {
			new_frame.style.backgroundImage = 'url(' + snapshot + ')';
			new Effect.Appear( new_frame, {duration:.5, afterFinish:function() { inMotion = false; } } );
			}
		cache_image.src = snapshot;
		document.location = "#main_image";
		}
	} // end function snapshot_switch()


function snapshot_grow( targ, snapshot, width, height ) {
	if( $('snapshot_zoom').style.top != '0px' ) {
		new Effect.Morph( 'snapshot_zoom', { 
			style: { width: '40px', height: '40px' }, 
			afterFinish:function() {  
				snapshot_embiggenate( targ, snapshot, width, height );
				} 
			} );
		}
	else {
		snapshot_embiggenate( targ, snapshot, width, height );
		}
	} // end function snapshot_switch()

function snapshot_embiggenate( targ, snapshot, width, height ) {
	coords = get_coords( targ );
	$('snapshot_zoom').style.right = coords[0] + 'px';
	$('snapshot_zoom').style.top = coords[1] + 'px';
	$('snapshot_zoom').width = width + 'px';
	$('snapshot_zoom').height = height + 'px';
	x = new Image;
	x.onload = function() {
		$('snapshot_zoom').src = snapshot
		new Effect.Morph( 'snapshot_zoom', { 
			style: { width: width + 'px', height: height + 'px', opacity:'1' }, duration:.5 
			} );
		}
	x.src = snapshot;
	} // end function snapshot_embiggenate()

function snapshot_suck() {
	new Effect.Morph( 'snapshot_zoom', { 
		style: { width: '40px', height: '40px', opacity: '0' }, 
		afterFinish:function() {  
			$('snapshot_zoom').style.right = '0px';
			$('snapshot_zoom').style.top = '0px';
			} 
		} );
	}


function get_coords( targ ) {
	var posx = 820 - targ.offsetLeft - 40;
	var posy = targ.offsetTop;
//	if (!e) var e = window.event;
/*
	if( e.pageX || e.pageY ) {
		posx = e.pageX;
		posy = e.pageY;
		}
	else if( window.event.clientX || window.event.clientY ) {
		posx = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = window.event.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
		}
*/
//	origin = findOrigin( $('wrap_beta') );
//	posx = posx - origin[0];
//	posy = posy - origin[1];
	return new Array( posx, posy );
	} // end get_coords()

function findOrigin(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	return [curleft,curtop];
	} // end findOrigin()












function switch_region() {
	var destination = ( /\?/.test( document.location ) ) 
		? '/' + $F('languageselector')
		: '/' + $F('languageselector');
	document.location = destination;
	}



function comment() {
	var fields = new Array( 'your_name', 'your_comments' );
	var responses = new Array( 'your name', 'your comments' );
	return check_required( fields, responses, 'your_email' );
	$('comment_form').submit();
	} // end function comment()




function check_required( fields, responses, email ) {
	if( fields.length > 0 )
		for( var i=0; i<fields.length; i++ ) {
			if( $F( fields[i] ) === '' ) {
				$( fields[i] ).focus();
				alert( "Form field missing: " + responses[i] );
				return false;
				}
			}
	if( email != '' ) {
		pattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
		if( !pattern.test( $F( email ) ) ) {
			$( email ).focus();
			alert( 'Please enter a valid email address.' );
			return false;
			}
		}
	return true;
	} // end check_required()

