$(function(){
	
	// INSERISCE LA TABELLA E VI RACCHIUDE I CONTENUTI
	$("#container").wrapInner(document.createElement("tr"));
	$("#container").wrapInner(document.createElement("table"));
	$("article, figure").wrap("<td>");
	
	// LAZY LOAD
	$("img").lazyload({ 
		effect : "fadeIn" 
	});
	
	// RENDE DRAGGABILE IL DOCUMENTO
	var intX = null;
	var once = 0;
	
	$('#container').mousedown( function( event ) {
		$('html,body').stop();
		intX = event.pageX;
		return false; // disabilita la selezione
	});

	$(document).mousemove( function( event ) {
		if( intX !== null ) {
			var moveX = $(window).scrollLeft() + -(event.pageX - intX);
			$(window).scrollLeft(moveX); 

			if($(window).scrollLeft() == 0 ){
				if(!once){
					intX = event.pageX;
					once = 1;
				}
				$('#container').css({ left: -moveX });
			}

			$(this).css({ 'MozUserSelect' : 'none' }); // disabilita la selezione in Firefox Win
			return false; // disabilita la selezione in Safari Mac, Firefox Mac, IE7
		}
	});

	$(document).mouseup( function( event ) {
		if( intX !== null ) {
			once = 0;
			intX = null;		
			
		}
	});

	// abilita la selezione di elementi fondamentali
	$('input, select, option, label, textarea, button').mousedown( function(){
		$( this ).focus();
	});
	
	// BACK BUTTON	
	$('#back').click( function() {
		var parentEl = $('html,body');
		if ($.browser.opera){
			parentEl = $('html');
		}
		parentEl.stop().animate({scrollLeft: '0', scrollTop: '0' }, 1000);
		return false;
	});


});
