$(document).ready(function(){

						thumbs = $('a.thumb').addClass('loading');
						//thumbs.find('img').css({opacity:0,display:'none'});
						
						//	preloading thumbs
						var i = 0;
						
						function preloadThumb(i, n) {
						/*	pre = new Image();
							pre.src = thumbs.eq(i).find('img').attr('src');
							pre.onload = function(){
								thumbs.eq(i).find('img').css({display:'block'}).animate({opacity:1}).parent().removeClass('loading');
								if(i<n) {
									i++;
									preloadThumb(i, n);
									//alert(i);
								}
								
							}*/
						}
						//for(i=0;i<thumbs.length;i++)
							//preloadThumb(i, thumbs.length);
						//preloadThumb(1, thumbs.length);
						loader = new Image();
						loader.src = url_base+'css/images/loading.gif';
						loader.onload = function(){preloadThumb(0, thumbs.length);}
						
					
						
						
						
						bigThumb = $('.gallery .big-thumb');//.prepend('<img src="'+thumbs.eq(0).attr('href')+'" alt="" style="display:none;"/>');
						bigImage = $('.gallery .big-thumb img');
						bigImageTitle = $('.gallery .big-thumb p.title');
						
						
						bigThumb.find('a.next').click(function(){
							thumbs.eq(bigThumb.attr('next')).click();
						});
						bigThumb.find('a.prev').click(function(){
							thumbs.eq(bigThumb.attr('prev')).click();
						});
						
						$('.gallery h4.title').css({cursor:'pointer'}).click(function(){
							if(!$(this).parent().hasClass('visible') && $('body').hasClass('gallery')) {
									$('.second .gallery').removeClass('visible').animate({height:82,opacity:.5});
									galleryThumbCount = $(this).parent().find('a.thumb').length;
									$(this).parent().addClass('visible').animate({height:82+(Math.ceil(galleryThumbCount/5-1)*50+12),opacity:1});
								}								
						});
						
						thumbs.each(function(i){
							$(this).attr('next', i+1).attr('prev', i-1)
							.bind('click', function(){
								bigImage.css({display:'block'});
								if($(this).attr('prev')==-1) {bigThumb.find('a.prev').css({display:'none'})}else{bigThumb.find('a.prev').css({display:'block'})};
								if($(this).attr('next')==thumbs.length) {bigThumb.find('a.next').css({display:'none'})}else{bigThumb.find('a.next').css({display:'block'})};
							
								if(!$(this).parent().hasClass('visible')  && $('body').hasClass('gallery')) {
									$('.second .gallery').removeClass('visible').animate({height:82,opacity:.5});
									galleryThumbCount = $(this).parent().find('a.thumb').length;
									
									
									$(this).parent().addClass('visible').animate({height:82+(Math.ceil(galleryThumbCount/5-1)*50+12),opacity:1});
								} else { if(!$('body').hasClass('gallery'))$('.second .gallery').css({overflow:'visible'})}								
								
								if($(this).attr('href')!='javascript://') {
									var href = $(this).attr('href');
									$('.gallery a.thumb[href=javascript://]').attr('href', bigImage.attr('src'));
									thumbs.removeClass('current');
									$(this).attr('href', 'javascript://').addClass('current');
									var title = $(this).attr('title');
									
									bigThumb.attr('next', $(this).attr('next')).attr('prev', $(this).attr('prev'));
									
									ratio = 0;
									preloader = new Image();
									preloader.src = href;

									
									
									if($.browser.msie) {
										bigImage.attr('src', href);
										bigImageTitle.html(title);
										//$('h2').html('preloading '+href);
									}else {
									
										bigThumb.addClass('loading').find('img').fadeOut();
										//alert(href);
									
										preloader.onload = function(){
											
											bigImageTitle.fadeOut(300, function(){$(this).html(title)});
											ratio=preloader.width/preloader.height;
											height = Math.floor(bigThumb.width()/ratio);
											bigImage.fadeOut(100, function(){
												bigThumb.animate({height:height+40}, function(){
													bigImage.attr('src', href).fadeIn();
													
													bigThumb.removeClass('loading');
													bigImageTitle.fadeIn();
												});
											});
											
										};
									}
									

								}
							
							
							//bigImage.attr('src', href);
							
							//$(this).attr('href', href);
							});
							if(i==0) $(this).click();
						});
						
						
						
					});
