window.addEvent('domready', function() {

childdivs = $('thumb_container').getChildren();
first_thumb_div = childdivs[1];
first_thumb_div_elements = first_thumb_div.getChildren();

$('the_image').src = first_thumb_div_elements[0].title;
$('granite_name').innerHTML = first_thumb_div_elements[0].name;
    
			$$('.change_pic').each(function(a){
      		
							a.addEvents({
          		click: function(){
							
										 var image = a.title;
										 var current_height = $('image_container').getStyle('height').toInt();
										 
										 var myFx = new Fx.Tween($('image_container'));
    								 myFx.set('height', current_height);
										 
										 $('image_container').addClass('ajax-loading2');
										 
										 var myFx = new Fx.Tween('the_image', {property: 'opacity'});
                      myFx.start(1,0).chain(
                          //Notice that "this" refers to the calling object (in this case, the myFx object).
                          function(){ $('the_image').src = image;	 }
                      );
										 														
														
											
											$('the_image').addEvent('load', function() {
            											var image_height = $('the_image').getStyle('height').toInt();
            											var myFx = new Fx.Tween($('image_container'));
                          				myFx.start('height', image_height+45).chain(
            											function(){ $('the_image').fade('in'); }
																	);
											});
											
											$('granite_name').innerHTML = a.name;
											
											position1 = a.getPosition();				
						
											active_position_left = a.offsetParent.offsetLeft;
											active_position_top = a.offsetParent.offsetTop;
											
											var myFx = new Fx.Morph($('pic_window'),{
                      }).start({ 
											'top': active_position_top + 'px',
                      'left': active_position_left + 'px'       
                      }); 

                                
                              

										 
          		}
          
          	});
										 
      });
	
});
