
$(document).ready(function() {
	/*
	$('.try').toggle(
					function(){
						$('#section2 .lightBox').css({'marginRight':'0','width':'355px'});
						$('#section2 .innerContent').css({'marginRight':'390px'});
						},
					function(){
						$('#section2 .lightBox').css({'marginRight':'130px','width':'370px'});
						$('#section2 .innerContent').css({'marginRight':'520px'});
					});
	
		*/				   
						   
				   
	$('#slider').cycle({ 
		fx:    'fade', 
		delay: 1000 
	 });
	
	$('#newsSlider').cycle({ 
		fx:    'scrollDown', 
		delay: 1000 
	 });	


	$(".lightBox a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'padding'		: 2,
		'opacity'		: true
	});


$('.lightBox a').hover(
  function () {
	$(this).fadeTo("fast", 0.70);
  }, 
  function () {
	$(this).fadeTo("fast", 1);

  }
);




$('#section1 .lightBox a').first().addClass('first'); 
//$('#mainMenu .search').wrapInner('<span></span>');
$('#container #section8 h2:first').addClass('firstTitle')

// gestione menu
$('.subMainMenu a').click(
		function(){
		$('.subMainMenu a').removeClass('active');	
		$(this).addClass('active');
		});



	var menu = $('#mainMenu');
	var topmost_point = menu.offset().top;
    var left_ref = $('#container').offset().left;
	var PADDING_TOP = 0; // MAGIC NUMBER
    var REAL_TOP = topmost_point - PADDING_TOP ;
	var the_window = $(window);
	var nav_fixed = (menu.css('position') == 'fixed');
	the_window.scroll(function () {
        if (the_window.scrollTop() > REAL_TOP ) {
            if ($.browser.msie && $.browser.version == "6.0") {
                menu.css('top', the_window.scrollTop() + PADDING_TOP - 79); //offset
            } else if (!nav_fixed) {
        	    menu.css({
                    left: left_ref,
        	        top: PADDING_TOP,
        	        position: 'fixed'
        	    });
        	    nav_fixed = true;
        	}
        } else {
            if (nav_fixed) {
                menu.css({
                    position: 'absolute',
                    top: topmost_point, //offset
                    left: 0
                });
                nav_fixed = false;
            }
        }

	
	the_window.resize(function () {
	    left_ref = $('#container').offset().left;
	    if (nav_fixed) {
    	    menu.css('left', left_ref);
			
		}
		
	});
	});





$('#mainMenu li').first().addClass('extreme');
$('.orizontalMenu li').last().addClass('last');
//$('#mainMenu li').last().addClass('extreme');
//$('#mainMenu a').last().addClass('search');

$('#section7 h3').next().addClass('clearLeft');
$('#section7 h3').next().last().css('height','100px');


$('#privacy_check').next('label').addClass('privacy_check_label');

$('#mainMenu').localScroll();


// fix per gestione logout FEU
var target1 = $('#section8 .cms_form');
var target2 = $('#section9 .cms_form');
var anchor1 = '#dati-utente';
var anchor2 = '#area-riservata';

function rewrite(target,anchor) {
	var URL = '';
	var URL2= '';
	var URL = target.attr('action');
	if (URL)
		var URL2 = URL + anchor;
	target.attr('action', URL2);
}
rewrite(target1,anchor1);
rewrite(target2,anchor2);

$("a[href$=jpg]").addClass("jpg").attr('target','_blank');

$("a[href$=pdf]").addClass("pdf").attr('target','_blank');

$("a[href$=eps]").addClass("eps").attr('target','_blank');




$('#innerNews a:not(".nav")').facebox(); 
$('.archivio').facebox();


$('.privacy_testo a').facebox();



$('#section7B a,#section7B div.small').hover(function(){
var $target = $(this).children('span');

	$target.css({"bottom":"-80px","display":"block","opacity":"0.8", "left": "0"}).animate( { bottom:"0"}, 400 );	
		}, 

function() {
	var $target = $(this).children('span');

	$target.animate( {bottom:"-80px"}, 350 );
	
						 
						 });


});



// gestione news


var news = (function() {
    var current = 0;
    var WIDTH = 310;
    var newsContainer, scrollbox, liCount;
    
    
    function init() {
    	newsContainer = $("#newsPagination");
    	scrollbox = $("#news-scrollbox");
    	liCount = newsContainer.find("ul").length;
    	//console.log(newsContainer, liCount, scrollbox, WIDTH);
    	newsContainer.find("#footerNews").css({ display: "block" });
    	
    	goToCurrent();
    };
    
    function goTo(what) {
    	switch (what) {
    		case "previous":
		    	current--;
    		break;
    		case "next":
    			current++;
    		break;
    		default:
    			if (typeof what === "number") {
    				current = what;
    			}
    		break;
    	}
    	
    	current = Math.max(0, Math.min(liCount - 1, current));
    	goToCurrent();
    };
    
    function goToCurrent() {
//    	console.log(current);
    	if (!current) {
			$('.previous').unbind('click').addClass('inactiveP');
			$('.next').removeClass('inactiveN');
    	}
    	else if (current >= liCount - 1) {
			$('.next').unbind('click').addClass('inactiveN');
			$('.previous').removeClass('inactiveP');			
			
    	}
    	else {
			$('.previous').removeClass('inactiveP');
			$('.next').removeClass('inactiveN');
    	}

    	scrollbox.animate({ left: (-WIDTH * current) + "px" });
    };

    return {
    	init: init,
    	goTo: goTo
    }
})();


$(news.init);







