
	window.addEvent('domready', function()
		{
			$$('a.external').each(function(link){
				link.target = "_blank";
			});


			if($chk($('slideshow_thumbs')))
				{			
					var slideshow = $('slideshow_thumbs');
					var cur_image = 'img1';
					
					slideshow.getElements('a').each(function(e) {
						e.addEvent('click',function(event) {
							new Event(event).stop();
							
							var lnk = e.get('id').replace(/lnk/,'');
							var lnk_id = e.get('id');
							var lnk_url = e.get('href');
							var img = 'img' + lnk;
							
							console.log('Clicked: ' + lnk_id + ', URL: ' + lnk_url + ', Image: ' + img);
							
							if(cur_image != img)
								{
									slideshow.getElements('a').each(function(e_lnk) { e_lnk.removeClass('current'); });
									
									if($chk($(img)))
										{
											//alert('image already exists');
											console.log('Element "' + img + '" already exists, fade in existing element.');
											
											// fade in selected image
											
											$(cur_image).fade('out')
											$(img).fade('in');
											cur_image = img;
											$(lnk_id).addClass('current');
										}
									else
										{
											//alert('image doesnt exist');
											console.log('Element "' + img + '" does not exist, create new image element then fade in.');
											
											var new_image = new Asset.image(
																											lnk_url,
																											{
																													id: img,
																													title: '',
																													onload: function(){
																														new_image.fade('hide');
																														new_image.inject($('slideshow'));
																														$(cur_image).fade('out');
																														new_image.fade('in');
																													}
																											}
																										);
											
											cur_image = img;
											$(lnk_id).addClass('current');
											
											
										}
								}
							else
								{
									console.log('Element "' + img + '" is currently visible element. Do nothing.');
								}
							
																									
						});																							 
					});
				}


});  // Window ready close
	
	
