function loadScripts(){
    now();

    $(document).ready(function(){
        onDomReady()
    });

    $(window).load(function () {
        onPageLoaded();
    });
}

function now(){

}

function onDomReady(){
        menu();
        menuEffects();
        style();
        customGallery();
        tag();   
        //scrollerRes();
        moveRes()
    }

function onPageLoaded(){
        overlay() 
}


function customGallery(){
	
		$('.custom-gallery li:first').addClass('first active');
		$('.custom-gallery li:last').addClass('last');

		img = '<img id = "big-image" src="' + $('.custom-gallery li:first a').attr('href') + '"/>'
		$('.image-container').append(img);

		var content = '<h2>' + $('.custom-gallery li:first a').find('span').text() + '</h2>' + $('.custom-gallery li:first a').find('.description').text();
		$('.page-bottom-text').html(content);
		
		$('.custom-gallery a').click(function(event){
		    event.preventDefault();
			//    bigImg = "<img src ='" + $(this).attr('href') + "' />";
		   	$('.custom-gallery li').removeClass('active');
		   	$(this).parent().addClass('active'); 
		   	
		   	$('.image-container > #big-image').css({'display' : 'none'});
		   	$('.image-container > #preloader').css({'display' : 'inline'});
		   	$('.image-container > #big-image').attr('src', $(this).attr('href'));
		   	//imageLink = $(this).attr('href');
		   	//$('.image-container').html('<img src="' + imageLink + '" />');
		   	
		   	//UNDER CONSTRUCTION -> TESTARE L'AFFIDABILITA' DEL BROWSER
		   	$('.image-container > img').load(function(){
		   		$('.image-container > #big-image').css({'display' : 'inline'});
		   		$('.image-container > #preloader').css({'display' : 'none'});
		   	})
		   	//$('.image-container').attr('href', $(this).attr('href') );
		   	var content = '<h2>' + $(this).find('span').text() + '</h2>' + $(this).find('.description').text();
		   	$('.page-bottom-text').html(content);   
	})
}

function style(){
	
}

function menuEffects(){
    $(".page_item").has('.children').mouseenter(function(){
         $(this).find('ul').stop(false,true).slideDown(250);
         $(this).addClass('in');
         $(this).mouseleave(function(){
            $(this).find('ul').stop(false,true).slideUp(250);
            $(this).removeClass('in');
        });
    });
}

function overlay(){
		
	// setup button action. it will fire our overlay 
	$(".video").overlay({		
		expose: '#789',		
		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			this.getOverlay().find("a.player").flowplayer(0).load();
		},		
		onClose: function(content) {
			$f().unload();
		}
	});
	
	$("a.player").flowplayer("http://www.faverolorenzo.com/wordpress/wp-content/themes/faverolorenzo/js/flowplayer/flowplayer-3.2.7.swf"); 
}

function tag(){
	$('.video').hover(function(){
		$(this).next('.tag').stop(false,true).animate({"bottom": "122px"}, "slow");
	},
	function(){
		$(this).next('.tag').stop(false,true).animate({"bottom": "62px"}, "slow");
	}
	)
}


function scrollerRes(){
	$('.menu-column').height($('.content-column').height());
	$(window).scroll(function(){
		var offset = $(window).scrollTop();
		$('#scroll-menu').css({
			'top':offset
		});
	})
}

function moveRes(){
	$("#scroll-menu a").click(function(event){
		event.preventDefault();
		id = $(this).attr('href');
		var move = $(id).offset().top - 140;
		
		$('html, body').animate({  
        	scrollTop: move  
    	}, 1000);  
    	
		console.log(move);
	});
}



