jQuery.noConflict(); var $ = jQuery;
$(function() {

/********************************************************************************/
//intinitescroll
/********************************************************************************/

	$('#contents').infinitescroll({		
		navSelector: ".navigation",
		nextSelector: ".navigation a:first",
		itemSelector: ".post",
		loadingText: "",
		bufferPx: 1200,
		donetext: ""			
	},function(){
		initImg();
	});

	$(window).scroll(function(){
		if($(window).scrollTop()>0){
			if($('.menu').css('opacity')==0){
				$('.menu').animate({'opacity':'1'},{queue:false},1000);	
			}								
		}else{
			$('.menu').animate({'opacity':'0'},{queue:false},1000);									
		}
		$(".post").each(function(){
			var myY = $(this).offset().top-$(window).scrollTop()-$(window).height();
			if(myY < 0 && myY > $(this).height()*-1){
				var txt = $(this).find(".description").html();
				$("#unit_"+$(this).attr('id')).fadeIn();
				//test(txt);
					//$("#info").html(txt);
			}else{
				$("#unit_"+$(this).attr('id')).fadeOut();
			
			}
		});
	});

	initImg();


$.timer(1000, function (timer) {
	$("#sidebar").animate({'opacity':'1'},1200,function(){
		$("#randomimage").animate({'opacity':'1'},1200,function(){
			$.timer(1000, function (timer) {
				$("body").scrollTo("#posts",1200);
				timer.stop();
			});
		});	
	});
    timer.stop();
});
	
//$(function() {
});

/********************************************************************************/
//initImg
/********************************************************************************/

function initImg(){

	$(".post").each(function(){
		if($(this).find("p").data('rescaled') !='true'){
			var txt = $(this).find(".description").html();
			$("#info").append("<div class='unit' id='unit_"+$(this).attr('id')+"'><div class='info_title'>"+$(this).find(".post_title").html()+"</div>"+txt+"</div>");
			//alert("added");
		}
	});

	$(".post p").each(function(){
		if($(this).data('rescaled') !='true'){
			$(this).find("a").attr('href','#');
			if($(this).data('rescaled')==null){
				$(this).data('rescaled','true');		
				var myParent = "#"+$(this).parent().attr('id');
				//var num = $(myParent).find("p").index(this)+1;
				//$(this).append("<div class='img_num'>"+num+"</div>");
				var max = 3;
				var n = Math.floor(Math.random()*max+1)
				if(n==1){
					$(this).css('width','600px');
				}else{
					$(this).css('width','280px');
				}
				var max = 3;
				var n = Math.floor(Math.random()*max+1)
				$(this).css('margin-top',80*n+"px");
			}
		}
	});
	
}


