// fixa storbild höjd
$(document).ready(function() {
	$('.attachment-bigimg').removeAttr('height');
});

// IE fix för nyheter (varannan bakgrund)
$(document).ready(function() {
	$("#news ul li:nth-child(odd)").css("background-image","url('wp-content/themes/tofta/img/front-news-bg.png')");
	$("#news ul li:nth-child(odd)").css("background-repeat","repeat");
});


// galleri
$(document).ready(function() {
	
	
	
		$("#gallerybutton_start").click(function(){
			$("#masthead").slideUp(500, function(){
				
				$("#slider").slideUp(500, function(){
					$("#gallery").height($(window).height());
					$("#gallery").delay(200).slideDown(500, function(){
						$('#gallery_grid').fadeIn(500);
						$("#gallerybutton_start").fadeOut(500);
						$("#gallerybutton_exit").fadeIn(500, function(){
							//$('.active_image').hide().attr('src',$('.galleryimg:first-child').attr('href')).fadeIn(500);

								$('.active_image_container').empty();
								
								$('.active_image_container').append('<img src="'+$('.galleryimg:first-child').attr('href')+'" alt="" class="active_image" />');
								$('.active_image_container img').load(function(){
									$(this).delay(1000).show(0);
								});

						});
					});
					
				});
				
			});
			
		
		
		$("#gallerybutton_exit").click(function(){
			
			$(".active_image").fadeOut(500, function(){
				$("#gallery").slideUp(500, function(){
					$("#masthead").delay(200).slideDown(500, function(){
						$("#slider").slideDown(500);
						$('.gallery_grid_up').hide();
					});
				});
			});
			
		});
	});

	
	$(".galleryimg").click(function(e){
		e.preventDefault();
		
		//$('.active_image').attr('src',$(this).attr("href")).hide().show(0);
		
		var href = $(this).attr("href");
		$('.active_image_container').empty();
		$('.active_image_container').append('<img src="'+href+'" alt="" class="active_image" />');
		
		$('.active_image_container img').load(function(){
			$(this).fadeIn(500);
		});
		
		/*$('.active_image').attr('src',$(this).attr("href")).hide(0, function(){
			$('.active_image').load().fadeIn(500);
		});*/
		
	});
	

	
	$(".gallery_grid_down").click(function(e){
		e.preventDefault();
		
		$('#gallery_grid').animate({scrollTop: '+=60'},'500');
		$('.gallery_grid_up').fadeIn(500);
	});
	
	$(".gallery_grid_up").click(function(e){
		e.preventDefault();
		
		$('#gallery_grid').animate({scrollTop: '-=60'},'500');
	});
	
	
});
