$(document).ready(function(){	
	
	// altezza delle colonne					   
	/*var height = $(window).height();
	$("#rightCol").height(height);
	$("#leftCol").height(height);*/
	
	// altezza delle colonne
	var wheight = $(window).height();	
	function setheight(){			
		$("#leftCol").height(wheight);
		$("#rightCol").height(wheight);
		/*var cheight = $('#rightCol').height();
		if(cheight<wheight){
			$("#rightCol").height(wheight);
		} */
	}
	setheight();
	
	$(window).scroll(function () { 
		wheight = $(window).height();
		setheight();
	});
	$(window).resize(function() {
		wheight = $(window).height();
		setheight();
	});
	
	
	// movimenti delle colonne	
	$("#rightCol").children().hide();
	$("#rightCol").css({ width: '0px' });
	$("#menu a").click(function(e){
		$("#menu a").removeClass('current');
		$("#rightCol").children().hide();
		var section = $(this).attr('name');
		$(this).addClass('current');
		e.preventDefault();
		if($("#rightCol").width='550'){
			$('#freccia').hide();
			$('#rightCol').animate({
				width: '0px'
				}, 1000, function() {
					$('#freccia').show();
					$('#rightCol').animate({
						width: '550px'
						}, 1000, function() {
							$('#'+section).fadeIn();
							var sheight = $('#'+section).height();
							if(sheight>wheight){alert(sheight);$('#rightCol').css({overflowY: 'scroll'});}
						}
					);				
				}
			);
			
		} else {		
			$('#freccia').show();
			$('#rightCol').animate({
				width: '550px'
				}, 1000, function() {
					$('#'+section).fadeIn();	
					/*if(section=='gallery'){
						$('#photos').jScrollPane({showArrows: true,autoReinitialise: true});
					}*/
				}
			);
		}
  	});
	
	// chiudo la colonna destra se clicco sul logo
	$("#logo a").click(function(e){
		$("#rightCol").children().hide();
		e.preventDefault();
		if($("#rightCol").width='550'){
			$('#freccia').hide();
			$('#rightCol').animate({
				width: '0px'
				}, 1000, function() {
								
				}
			);			
		} 
	});
	
	// chiudo la colonna destra se clicco sulla freccia
	$("#freccia a").click(function(e){
		$("#rightCol").children().hide();
		e.preventDefault();
		if($("#rightCol").width='550'){
			$('#freccia').hide();
			$('#rightCol').animate({
				width: '0px'
				}, 1000, function() {
								
				}
			);			
		} 
	});
	
	// paginazione gallery
	$('#photos .page').hide();
	var curtarget = $('.pagination a.current').attr('href');
	$(curtarget).show();
	
	$('.pagination a').click(function(e){
		e.preventDefault();
		var target = $(this).attr('href');
		$('.pagination a').removeClass('current');
		$(this).addClass('current');
		$('#photos .page').hide();
		$(target).show();
	});
	
	// zoom delle immagini in gallery
	$(".photo a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayColor'  :   '#000',
		'cyclic'        :   true,
		'titlePosition' :   'over'
	});
	
	//$("div#background").flashembed("preview.swf");
	flashembed("background", {src: "preview.swf", wmode: "opaque", w3c: true});
	flashembed("gallery_xl", {src: "flash_obj/gallery_2011.swf", width:470, height:240, wmode: "opaque", w3c: true});

});

// sostituzione font con cufon
Cufon.replace('h2', { fontFamily: 'Liberation Sans' });
Cufon.replace('#menu a', { fontFamily: 'Liberation Sans',hover: true }); 
Cufon.replace('#footer', { fontFamily: 'PF Tempesta Five' }); 
