	$(function(){
		var shadows = [
			{ path: '/img/shadows/shadow-small-1.gif', width: 138, height:142, shadowDepth: {x:5, y:5} },
			{ path: '/img/shadows/shadow-small-2.gif', width: 138, height:137, shadowDepth: {x:5, y:5} }/*,
			{ path: '/img/shadows/shadow-large-1.gif', width: 462, height:596, shadowDepth: {x:6, y:9}, name:'large-1' }*/
		];
		
		function rnd(n){
			return (Math.floor(Math.random() * n));
		}
		
		function renderShadow(shadowWrap){
			var dims = {width:shadowWrap.outerWidth(), height:shadowWrap.outerHeight() };
			var shadow = shadows[rnd(shadows.length)];

			if(shadowWrap.attr('forceShadow')){
				for(var i=0; i<shadows.length; i++){
					if(shadows[i].name == shadowWrap.attr('forceShadow')){
						shadow = shadows[i];
					}
				}
			}

			var shadowImage = $('<img src="'+shadow.path+'" class="shadow-image" />');
			shadowWrap.append(shadowImage);
			shadowImage.css({
				width:dims.width + 'px',
				height:dims.height + 'px',
				'margin-top': '-' + dims.height + 'px',
				left: '-' + parseInt(dims.width * (shadow.shadowDepth.x / shadow.width).toFixed(2)) + 'px',
				bottom: '-' + parseInt(dims.height * (shadow.shadowDepth.y / shadow.height).toFixed(2)) + 'px'
			});
		}
	
		$('.shadow').each(function(index){
			var innerImage = $(this).find('img:eq(0)');
			$(this).removeClass('shadow').addClass('shadow-js');			

			if(innerImage.length && innerImage.height() == 0){
				$(innerImage).data('shadowWrap',  this);
				innerImage.load(function(){
					renderShadow($($(this).data('shadowWrap')));
				});
			}else{
				renderShadow($(this));
			}
		});
	});

