jQuery(document).ready(function($) {
	$('.page-curl').hover(function() {
	$('.page-curl .curl, .page-curl .img').stop(true)
	.animate({
	width : '300px',
	height : '299px'
	}, 500);
	}, function() {
	$('.page-curl .curl, .page-curl .img').stop(true)
	.animate({
	width : '50px',
	height : '50px'
	}, 220, animateCurl);
	}).find('img').each(function() {
		var el = $(this), h = el.height(), w = el.width();
		el.replaceWith($('<div class="img "/>').css({'background-image': 'url(' + el.attr('src') + ')', 'height': h, 'width': w}));
	});
	var animateCurl = function() {
		var selector = '.page-curl .curl, .page-curl .img', interval = 'slow', height = 50, width = 50, offset = (Math.random() * 5) + 10;

		if('undefined' === typeof pause) {
			var pause = 0;
		}

		if(0 === pause) {
			pause = 1;
			$(selector).animate({
			width : width+offset+'px',
			height : height+offset+'px'
			}, interval, 'swing')
			.animate({
				width : width + 'px',
				height : height + 'px'
			}, interval, 'swing', animateCurl);
		}
	};
	animateCurl();
});

