$(document).ready(function(){
	$("#searchform").focusin(function(){
		$('#s').animate({width: "190px"}, 300);
	}).focusout(function(){
		$('#s').animate({width: "120px"}, 300 );
	});	
	
	$('.menu-item').each(function(){
		var under = $(this).children('a').attr('title');
		$(this).children('span').html(under);
	});
	
	$('.nav ul li').mouseenter(function(){
		$('.title').removeClass('active');
		$(this).children('.title').addClass('active');
	});
	
	$('.comments_quick').click(function(){
		$(this).children('.do_comment').fadeIn();
	});
	
	$('.thumbnails').hover(
		function(){
			$(this).children('.description').stop(true, true).css({'display': 'block', 'opacity': '0'}).animate({'opacity': 0.8}, 'slow');
		},
		function(){
			$(this).children('.description').stop(true, true).css({'display': 'block', 'opacity': '0.8'}).animate({'opacity': 0}, 'slow');
		}
	).click(function(){
		$(this).children('.description').stop(true, true).css({'display': 'block', 'opacity': '0.8'}).animate({'opacity': 0}, 'slow');
	});
	
	$('#gallery_post .thumbnails').each(function(){
		var title = $(this).attr('data-title');
		$(this).fancybox({
			'padding': '5',
			'centerOnScroll': true,
			'hideOnContentClick': true,
			'overlayColor': '#000',
			'overlayOpacity': '0.9',
			'showCloseButton': false,
			'showNavArrows': true,
			'title': title
		});
	});
	
	$('.fancy').each(function(){
		var title = $(this).attr('data-title');
		$(this).fancybox({
			'padding': '5',
			'centerOnScroll': true,
			'hideOnContentClick': true,
			'overlayColor': '#000',
			'overlayOpacity': '0.9',
			'showCloseButton': false,
			'showNavArrows': true,
			'title': title
		});
	});
	
	if ($('#gallery_post').length>0) {
		var numimages = $('#gallery_post img').length;
		var loaded = 0;
		$('#gallery_post img').each(function(){
			$(this).bind('load', function(){
				$(this).unbind('load');
				loaded++;
				if (loaded==numimages) {
					allImagesLoaded();
				}
			});
			
			if (this.complete || (jQuery.browser.msie && (parseInt(jQuery.browser.version)==6 || parseInt(jQuery.browser.version)==9))) {
				$(this).trigger('load');
			}
		});
	}
});

function allImagesLoaded() {
	$('.thumbnails').hide();
	$('.thumbnails').each(function(i){
		$(this).delay(i*100).fadeIn(400);
	});
}
