$(document).ready(function() {
	
	//SCROLLING POSITION 
	var message = $( "#header" );
	var originalMessageTop = message.offset().top;
	var view = $( window );
	 
	view.bind(
	"scroll resize",
		function(){
		 
		var viewTop = view.scrollTop();
		 
		if (
		(viewTop > originalMessageTop) &&
		!message.is( ".header-fixed" )
		){
		 
		message
		.removeClass( "header-absolute" )
		.addClass( "header-fixed" )
		;
		 
		} else if (
		(viewTop <= originalMessageTop) &&
		message.is( ".header-fixed" )
		){
		 
		message
		.removeClass( "header-fixed" )
		.addClass( "header-absolute" )
		;
		 
		}}
	);
	
	
	// HOMEPAGE PANEL IMAGE HOVER
	$("#homepage .panel a img").hover(
		function() {
		$(this).stop().animate({"opacity": "1"}, 0);
		},
		function() {
		$(this).stop().animate({"opacity": "0"}, 700);
	});
	
	

	
	
	// NEWS LIST IMAGE HOVER
	$("#news-list .article").hover(
		function() {
		$(this).find("img").stop().animate({"opacity": "1"}, 100);
		$(this).find("h2").stop().css("color", "#cc0723");
		},
		function() {
		$(this).find("img").stop().animate({"opacity": "0"}, 800);
		$(this).find("h2").stop().animate({"color": "#808080"}, 800);
	});
	
	
	// EVENTS SPHERE IMAGE HOVER
//	$("#intro-inner").hover(
//		function() {
//		$(this).find("#cycle").stop().animate({"opacity": "1"}, 250);
//		$(this).find("p").stop().animate({"opacity": "0"}, 250);
//		},
//		function() {
//		$(this).find("#cycle").stop().animate({"opacity": "0"}, 250);
//		$(this).find("p").stop().animate({"opacity": "1"}, 250);
//	});
	
	
	//FANCYBOX
	$("a.fancybox").fancybox({
		'padding'			: 	0,
		'hideOnContentClick': 	false,
		'width'				: 	546,
		'height'			: 	400,
		'transitionIn'		:	'fade',
		'transitionOut'		:	'fade',
		'speedIn'			:	1200,
		'speedOut'			:	200,
		'overlayShow'		:	true,
		'overlayOpacity'	:	0.5,
		'overlayColor'		:	'#efefef',
		'autoScale'     	: 	false,
		'autoDimensions'	:	false,
		'type'				: 	'iframe',
		'scrolling'			:	'no'
	});
	
	
	//CYCLE
	$('#cycle').cycle({ 
		fx:		  'fade',
	    timeout:  200,
	    speed:    450
	});
	
	$('#slideshow').cycle({ 
	    prev:   '#prev', 
	    next:   '#next',
	    speed:  200,
	    timeout: 0 
	});
	
	
	// NEWS LIST LAYOUT
	var $wall = $('#news-list');
	
	      $wall.masonry({
	        singleMode: true, 
	        itemSelector: '.article:visible'
	      });
	
	      $wall.infinitescroll({
	        navSelector  : '#page_nav',  // selector for the paged navigation 
	        nextSelector : '#page_nav a',  // selector for the NEXT link (to page 2)
	        itemSelector : '.box',     // selector for all items you'll retrieve
	        loadingImg : 'img/loader.gif',
	        donetext  : 'No more pages to load.',
	        debug: false,
	        errorCallback: function() { 
	          // fade out the error message after 2 seconds
	          $('#infscr-loading').animate({opacity: .8},2000).fadeOut('normal');   
	        }
	      },
	        // call masonry as a callback.
	        function( newElements ) { $(this).masonry({ appendedContent: $(newElements) }); }
	      );
	
	//$(document).ready(function(){
	//	$('#news-list').masonry({ singleMode: true });
	//});
	
});
