	function init_active_galleries(){
	$('.gblock').each(function(){
		var _gid = $(this).attr('id').substr(3);
		init_thumb_click_handlers($(this));
		
		$(this).find('.gf_gl_text').remove();    
	})	
	}
	
	
   init_display_click = function(tg){ 
		    var display = tg.find('.gf_gl_display');
		    var thumbs = tg.find('.gf_gl_thumbs ul');

		    display.click(function(){

				var next = thumbs.find('li.selected').next(); 

				if (next.length == 1){
					next.find('a').trigger('click');
				}else{
					thumbs.find('li:first a').trigger('click')
				}

		    })
	}
	
	init_display_hover = function(tg){ 
		var display = tg.find('.gf_gl_display');
		var thumbs = tg.find('.gf_gl_thumbs ul'); 
		
		display.mousemove(function(e){
			    var mpos =  e.pageY - display.closest('.cblock').position().top; 
				if(mpos >= 430){
				   if($('.dblock').length == 0){
					  show_info(this)
					} 
				 }else{ 
					hide_info(this)
				}
		  })
		
		display.hover(function(e){ 
			
			var mpos2 =  e.pageY - display.closest('.cblock').position().top; 
			if(mpos2 >= 430){  
			if($('.dblock').length == 0){
				  show_info(this)
				}   
		     }
		      
			 
		},function(){
			  hide_info(this)
		});
		
		function show_info(tg){ 
			 var selection = thumbs.find('li.selected');
			 var title = selection.find('a').text();
			 var desc = selection.find('p:hidden').text();
			 var dblock = $('<div class="dblock"></div>');
			 var dcontent =$('<div style="margin:15px"></div>');
			 dblock.append(dcontent);
			 dblock.css({
				backgroundImage:"url(/gf_assets/ui/back_trans_80_black.png)",
				position:"absolute",
				bottom:0,
				left:0,
				color:'#fff',
				width:'100%',
				display:'none',
				borderTop:'1px solid #222'
			 })
			
			 
			if(title.length > 0){
				dcontent.append('<h1 style="color:#f90;font-size:120%">'+title+'</h1>');
			}
			
			if(desc.length > 0){ 
				dcontent.append('<p>'+desc+'</p>');
			} 
			
			if(title.length > 0 || desc.length > 0){
				$('.dblock').remove();
				display.append(dblock);
				dblock.slideDown('fast');
			 }
			 
			
		}
		
		function hide_info(tg){  
			 $('.dblock').slideUp('fast',function(){
				  $('.dblock').remove(); 
			});
			 
		}
		
		 
		
	}

	
	function init_thumb_click_handlers(tg){ 
		tg.find('div.gf_gl_thumbs a').click(function(){

			var display = $(this).closest('div').parent().find('.gf_gl_controls .gf_gl_display')
		    var has_img = $(tg).find('div.gf_gl_display img').width() > 0;
		    var _img = new Image();
		    $(_img).css({opacity:0});
  
			$(tg).find('div.gf_gl_display').html(_img); 

			
			$(_img).load(function(){ 
				center_img();
				$(_img).animate({opacity:1},'fast');  
		    })
		    .attr('src', $(this).attr('href'));
		     
		    
		    function center_img(){
						
			     var dw,iw,ih,ratio,nw,nh,offset;

		       	 dw =  display.width();
			     iw =  $(_img).width();
			     ih =  $(_img).height();
			     ratio = ih/iw; 
		   		 nh = display.height();
				 nw = nh/ratio;

				 $(_img).css({width:nw,height:nh}) 


				 if(iw == ih){ 
					 nh = 500;
				     nw = nh*1;
				     $(_img).css({width:nw,height:nh}) 
				 }


			     iw =  $(_img).width();
				 ih =  $(_img).height();



				 offset = (iw - dw)/2;
				 display.css({position:'relative'});
				 $(_img).css({left:-offset, position:'absolute'});
			     
	        };

		    
		    $(this).parent().addClass('selected');
		    $(this).parent().siblings().removeClass('selected');      
	
			return false; 
		 });
		
	       $(tg).find('div.gf_gl_thumbs a:first').trigger('click');
	
		   init_display_click(tg) 
		   init_display_hover(tg)
		
	}
	
