/*
 * Props
 */
var scrollerObj;
/*
 * resize
 */
function resizeTile()
{
	var numTiles = 4;
	var pageMargin = 30;
	var tileMargin = 15;
	var pageWidth = $(window).width();
	var tileWidth = 256;
	numTiles = Math.floor(pageWidth/240);
	tileWidth = Math.floor((pageWidth - pageMargin*2 - tileMargin*(numTiles-1))/numTiles) - 2;
	
	$("#contentWrapper .post").css('width', tileWidth+'px');
	$("#contentWrapper .post").css('height', tileWidth+'px');

	var imgs = $("#contentWrapper img");
	var divs = $("#contentWrapper .post");
	for (var i=0; i<imgs.length; i++)
	{
		imgs[i].width = tileWidth;
		imgs[i].height = tileWidth;
		$(divs[i]).css('margin-right', tileMargin+'px');
		$(divs[i]).css('margin-right', tileMargin+'px');
		if((i+1)%numTiles==0) $(divs[i]).css('margin-right', '0px');
	}
	///$(divs[divs.length-1]).css('margin-bottom', '40px');
	
	/* for iScroll */
	if($.os.name == 'ipad')
	{
		$("#scrollWrapper").css("height", $(window).height() - 40 + 'px');
		scrollerObj.refresh();
	}
}
/*
 * bind event
 */

$(function()
{
	$(window).bind("load", function()
	{
		/* for iScroll */
		if($.os.name == 'ipad')
		{
			document.addEventListener('touchmove', function(e){ e.preventDefault(); }, false);
			scrollerObj = new iScroll("scrollWrapper", {lockDirection:true, checkDOMChanges:true, vScroll:true, hScroll:false, vScrollbar:true, hScrollbar:false});
		}
		/* resize */
		resizeTile();
		$(window).bind(($.os.name == 'ipad')? "orientationchange" : "resize", function(aEvent)
		{
			resizeTile();
			$("body").css('height', 'auto');
		});

	});
});

