$(document).ready(
	function(){				
		$('.article').hide();
		
		$.fn.preloadArticle = function(){
			var articleId = ($(this).attr("id")).replace("article_","");
			$(this).children('.preloader').show();
			$(this).children('.content').hide();
			
			$(this).show();
			
			var content = $(this).children('.content');
			
			content.children('.iContainer').load("/"+lang+"/images/"+articleId,function(){ 
				$(this).children('img').load(function() { $(this).removeClass('hidden').addClass('loaded'); content.checkImageLoad(); } );
				
			});

		};
		
		$.fn.checkImageLoad = function(){
			var allLoaded = true;
			this.children('.iContainer').children('img').each(function(){ if (!$(this).hasClass('loaded')) allLoaded = false; });
			if (allLoaded) {
				$(this).parent().children('.preloader').hide();	
				$(this).fadeIn(600,function() {
					$(this).parent().next().next().preloadArticle();
				});
			}		
		}
		
		$.fn.testNext = function(){
			alert($(this).attr('class'));
		}
		
		$('.article:first').preloadArticle();
		
	}
);
