function CanvasClock(id, opt) {
	var elem = document.getElementById(id);
	if(!elem || !elem.getContext || typeof opt !== "object") {
		return false;
	}
	var ctx = elem.getContext("2d"), bg = new Image();
	bg.src = opt.background;

	function dot() {
		elem.width = bg.width;
		elem.height = bg.height;
		ctx.drawImage(bg, 0, 0, bg.width, bg.height);
		var r = bg.width / 2;
		ctx.beginPath();
		ctx.arc(r, r, 1, 0, Math.PI * 2, false);
		ctx.fill();
	}
	function line(angle, n, color) {
		var r = bg.width / 2;
		if(color==1)
			ctx.strokeStyle="rgba(0,255,44,1)";
		else
			ctx.strokeStyle="rgba(0,0,0,1)";
		ctx.beginPath();
		ctx.moveTo(r, r);
		ctx.lineTo(r + Math.cos(angle) * (r - n), r + Math.sin(angle) * (r - n));
		ctx.stroke();
	}
	function draw() {
		var d = new Date(), h = d.getHours(), m = d.getMinutes(), s = d.getSeconds();
		if(h > 12) {
			h -= 12;
		}
		dot();
		var alfa = ((h * Math.PI) / 6) - Math.PI / 2;
		ctx.lineWidth = 3;
		if(m > 30) {
			alfa += Math.PI / 12;
		}
		if(m > 15) {
			alfa += Math.PI / 24;
		}
		line(alfa, 18, 0);
		alfa = ((m * Math.PI) / 30) - Math.PI / 2;
		ctx.lineWidth = 2;
		line(alfa, 2, 0);
		alfa = ((s * Math.PI) / 30) - Math.PI / 2;
		ctx.lineWidth = 1;
		line(alfa, 5, 1);
		setTimeout(draw, 1000);
	}
	bg.onload = function() {
		draw();
	};
}
onload = function() {
	var c = new CanvasClock("clock", {
		background: "images/immagine_orologio.png"
	});
};

jQuery(document).ready(function(){
	jQuery(function () {
	  var img = new Image();
	  var img2 = new Image();
	  var linktemp = '';
	  var chks = false;
	  jQuery(img2)
		.load(function () {  
		  jQuery(this).hide();
		  jQuery('#loader2')
			.append(this);
		})
		.error(function () {
		})
		.attr('src', 'images/immagine_2.jpg');
	  jQuery(img)
		.load(function () {
			if(!chks){
				jQuery(this).hide();
				jQuery('#loader #contents')
				.removeClass('loading')
				.append(this);
				jQuery(this).fadeIn();
				chks=true;
			}
		})
		.error(function () {
		})
		.attr('src', 'images/immagine_1.jpg');
	});
		jQuery('#contents').hover(
			function(){
				linktemp=jQuery('#loader img').attr('src');
				jQuery('#loader img').attr('src', jQuery('#loader2 img').attr('src'));
				jQuery('#loader2 img').attr('src', linktemp);
			},
			function(){
				linktemp=jQuery('#loader img').attr('src');
				jQuery('#loader img').attr('src', jQuery('#loader2 img').attr('src'));
				jQuery('#loader2 img').attr('src', linktemp);
			}
		);
	jQuery('#loader').click(function() {
		location.href="http://shop.postalmarket.it/casa";
	});
	});
