$(document).ready(function(){
    
	// BLOCCO ANIMAZIONE BKG
	$(".newsListLi").hoverIntent(stopSlide,playSlide);
	$(".bottombar_back").hoverIntent(stopSlide,playSlide);
	$("#slidebar_close").hoverIntent(stopSlide,playSlide);
	
	function stopSlide(){
		  $.doTimeout('slideTimeout');
		  $(".jbgallery").jbgallery("stop")
		}
	function playSlide(){
		   $.doTimeout( 'slideTimeout',2500, function(){
		  	 $(".jbgallery").jbgallery("play");
	  	   });
		}


	
	
	 // ANIMAZIONE TABS
	
    $('.tab-element').click(function() {
    	if($(this).attr('id') != 'tab_book')
    	{
			$('#bottombar').animate({left: -990}, 1000);
			$('#jbg-menu-opacity').animate({bottom: -30}, 1000);
			$('#jbg-menu').animate({bottom: -30}, 1000);
			$('#tab-container').animate({bottom: -100}, 1000);
			$('#topmenu').animate({'margin-top': 0}, 700);
			$('#text_subpage_' + $(this).attr('id')).show();
			$('#slidebar').animate({bottom: 0}, 500);
		}
    });
	
	
    $('#slidebar_close').click(function(){
		$(".jbgallery").jbgallery("stop");
    	$('#bottombar').animate({left: 0}, 1000);
    	$('#jbg-menu-opacity').animate({bottom: 0}, 1000);
    	$('#jbg-menu').animate({bottom: 5}, 1000);
    	$('#tab-container').animate({bottom: 25}, 1000);
    	$('#topmenu').animate({'margin-top': 16}, 700);
    	$('#slidebar').animate({bottom: -300}, 500, function(){
    		$(".text_subpage").hide();
    	});    	
    });
	
	$('.tab-element').mouseenter(function() {
		$.doTimeout('slideTimeout');
		$(".jbgallery").jbgallery("stop")
        var newHeight = $(this).find(".tab-txt").height() + 10;
        if (newHeight < 25) { newHeight = 25; } else { if (newHeight > 50) { newHeight = 60 } };
        $(this).stop().animate({ marginTop: 25 - newHeight }, { duration: 200 }).find(".tab-txt").css('color', '#ffffff');
    });

    $('.tab-element').mouseleave(function() {
        $(this).stop().animate({ marginTop: 25 }, { duration: 400 }).find(".tab-txt").css('color', '#787878');
		$.doTimeout( 'slideTimeout',2500, function(){
  			$(".jbgallery").jbgallery("play");
		});
    });
	
	
	// ANIMAZIONE NEWS
	
	$('.newsListLi').click(function() {
		var idThis = $(this).attr('id');
		$('.newsListLi[id!='+idThis+']').hide();
		$('#jbg-menu-opacity').animate({bottom: -30}, 800);
		$('#jbg-menu').animate({bottom: -30}, 800);
		$('#tab-container').animate({bottom: -100}, 800);
		$('#topmenu').animate({'margin-top': 0}, 700);
		$('#bottombar').animate({bottom: 25}, 500);
		$('#bottombar').animate({height: 190}, 800);
		$(this).animate({height: 170}, 800);
		$(this).animate({width: 770}, 250);
		$(this).children('a').animate({width: 770}, 350);
		$(this).children('a').animate({fontSize: 20}, 600);
		$(this).children('a').css("color","#DDDDDD");
		$('.subtext').animate({height: 85}, 300);
		$('.subtext').animate({fontSize: 11}, 600);
		$('.bottombar_back').show();
		$('.bottombar_read').show();
		$.doTimeout( 2500, function(){
  			$(".jbgallery").jbgallery("play");
		});		
    });
	
	$('.bottombar_back').click(function() {
		$(".jbgallery").jbgallery("stop");
		$('#bottombar').animate({height: 100}, 1000);
		$('#bottombar').animate({bottom: 80}, 500);
		$('#bottombar').animate({left: 0}, 1000);
		$('.newsListLi').animate({height: 70}, 1000);
    	$('#jbg-menu-opacity').animate({bottom: 0}, 1000);
		$('.subtext').animate({height: 40}, 300);
    	$('#jbg-menu').animate({bottom: 5}, 1000);
    	$('#tab-container').animate({bottom: 25}, 1000);
    	$('#topmenu').animate({'margin-top': 16}, 700);
		$('.newsListLi').animate({width: 310}, 350);
		$('.newsListLi a').animate({width: 310}, 350);
		$('.newsListLi a').animate({fontSize: 13}, 1000);
		$('.newsListLi a').css("color","#FFFFFF");
		$('.subtext').animate({fontSize: 10}, 1000);
		$('.bottombar_back').hide();
		$('.bottombar_read').hide();
		$(".jbgallery").jbgallery("play");
		$.doTimeout( 2500, function(){
  			$(".jbgallery").jbgallery("play");
		});
		
    });
		
	// JBGALLERY
	var _clicked = false;
	if(globalCheckGallery)
	{
		
		
		var jbOptions = {
			slideshow : true,
			caption : true,
			  timers    : {
			  fade      : 500,
			  interval  : 4000,
			  autohide  : 7000, 
			  after : function()
			  	{
					if (!_clicked) 
					{
						jQuery(".jbg-info").click();
						_clicked = true;
					}
				}  
			}
	
		};
	
	}
	else
	{
		var jbOptions = {
			menu : "simple",
			style: "zoom",
			slideshow : true,
			  timers    : {
			  fade      : 500,
			  interval  : 6500,
			  autohide  : 7000  
			},
			delays    : {
			  mousemove : 200,
			  resize    : 500,
			  mouseover : 800
			},
	
			caption : false
		};
		
	}
	$(".jbgallery").jbgallery(jbOptions);
	if(globalCheckGallery)
	{

		$('#jbg-caption').css("visibility" , "visible");
		$('#jbg-menu-opacity').hide();
		$('#jbgs-top-opacity').hide();
		$('#jbgs-top').hide();
	}
	
	

	
	var browserWidth = $(window).width();
	var browserHeight = $(window).height();
	
	if (browserHeight < 780) 
			{ 
				//$('#bottombar').hide();
				$('.container_text').css({"line-height":"16px", "top":"165px" });
				$('.container_h1').css({"font-size":"28px", "top":"85px"});
				
			}else{		
	}
	
	if (browserWidth < 980) 
			{ 
				//$('#bottombar').hide();
				$('ul#menutxt').css({"left":"280px"});
				$('ul#menutxt li').css({"margin-right":"20px", "font-size":"10px"});
			}else{		
	}
	
});




