$(function(){
	
	var blocks_num = $(".post").length;
	
	var pics_num = new Array;
	var first_num = new Array;
	var first_pic = new Array;
	var color = new Array;
	
	
	$(".post").each(function(blocks_num){
								pics_num[blocks_num] = $(this).find(".entry-content img").length;
								first_num[blocks_num] = Math.floor(Math.random()*pics_num[blocks_num]);
								var first_pic = $(this).find(".entry-content img").eq(first_num[blocks_num]).attr("src");
								//alert(first_pic);
								$(this).find(".first-pic img").attr("src",first_pic);
								//.attr("width",Math.floor(Math.random()*3+4)*50);
								
								//color[blocks_num]="background-color:#"+Math.floor(Math.random()*Math.pow(2,24)).toString(16);
								//$(this).attr("style",color[blocks_num]);
								
								$(this).find("img").load(function(){
													   $(this).parent().parent().attr("height",$(this).height());
													   $(this).parent().parent().attr("width",$(this).width());
													   })
								
									  })
	
	 var last_pic = new Image();
	 last_pic.src = $(".post").eq(blocks_num-1).find(".first-pic img").attr("src");
	 //alert(last_pic.src);
	 
	 Array.prototype.min = function()
        {
        return Math.min.apply({ }, this)
        } ;

    Array.prototype.max = function()
        {
        return Math.max.apply({ }, this)
        } ;

    $.fn.masonry = function()
        {
        this.each(function()
            {
            var wall = $(this);
			
			//alert(wall.html());

            if (wall.children().length > 0)
                {
                if (wall.children('.masonryWrap').length == 0)
                    {
                    wall.wrapInner('<div class=\"masonryWrap\"></div>')
                    }

                var mWrap = wall.children('.masonryWrap');
                var brick = mWrap.children();
                var brickW = brick.outerWidth(true);
                var colCount = Math.floor(mWrap.width() / brickW);
                var colH = new Array();

                for (i = 0; i < colCount; i++)
                    {
                    colH[i] = 0
                    }

                mWrap.css({ position: 'relative' });
                brick.css({ float: 'none', position: 'absolute', display: 'block' }).each(function()
                    {
                    for (i = colCount - 1; i > -1; i--)
                        {
                        if (colH[i] == colH.min())
                            {
                            var thisCol = i
                            }
                        }

                    $(this).css({ top: colH[thisCol], left: brickW * thisCol });
                    colH[thisCol] += $(this).outerHeight(true)
                    });

                mWrap.height(colH.max())
                }

            return this
		  
		  })
        }
	domasonry = function() {
		 $(".out #content").masonry({  columnWidth: 300  });
		 $(".in .entry-content").masonry({  columnWidth: 300  });
		 }	
		setTimeout(domasonry,1000);
		
		$(".single .entry-content p").fadeTo(500,0.2).hover(function(){
																$(this).fadeTo(300,1) 
																	 },function(){
																		$(this).fadeTo(300,0.2) 
																	 })
		

	 

})
