
function resizePanel() {

	width = $(window).width();
	height = $(window).height();
	mask_height = height * $('.item').length;
	$('#wrapper, .item').css({width: width, height: height});
	$('#mask').css({width: width, height: mask_height});
	$('#wrapper').scrollTo($('a.selected').attr('href'), 0);
		
}


$(document).ready(function(){
                               
                                
var index=0; 
var winheight=$(window).height(); 

$('.content').height(parseInt(winheight - 80));	
if($('.content').height()>750)	$('.content').height(750);	
$('.page').height($('.content').height()-220);	 
$('#pagehome').height($('.content').height()-220);	
 
 
//$('#store .page,#info .page').jScrollPane();


var element_1 = $('#events .page').jScrollPane();
var api_1 = element_1.data('jsp')

var element_2 = $('#press .page').jScrollPane();
var api_2 = element_2.data('jsp')

/*var element_3 = $('#collections .page').jScrollPane();
var api_3 = element_3.data('jsp')*/
	
	 $('.panel a').click(function (e) { 
	 current = $(this);
		$('.panel a').removeClass("selected");
		current.addClass("selected");
                $('#load-collection').empty();
                if(vars.is_paused==true) api.playToggle();    //stoppa il supersized
                
		$('#wrapper').scrollTo($(this).attr('href'), 800, {onAfter:function(){ 
		
		
		//loading ajax pages
		if((current.attr('href')=="#events") && ($('.news-loaded').is(':empty')) ){
			$('.news-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load("../elenco_news.php?lang="+lang,
						function(){api_1.reinitialise() }); 
		}
		
		if((current.attr('href')=="#press") && ($('.press-loaded').is(':empty')) ){
			$('.press-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load("../elenco_press.php?lang="+lang,
						function(){api_2.reinitialise() }); 
		}
		
		/*if((current.attr('href')=="#collections") && ($('.gallery-loaded').is(':empty')) ){
			$('.gallery-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load("../elenco_photocoll.php?lang="+lang,
						function(){api_3.reinitialise()}); 
		}*/	
		
		} });		
		
		
		e.preventDefault();
		return false;
	});
	
	$(window).resize(function () {
		resizePanel();
	});
	
	 $("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'dark_square' /* light_rounded / dark_rounded / light_square / dark_square */
	 });
		
		
	//paginazioni e dettagli ajax
	$('.news-loaded a.ajaxlink').live('click', function(e) {
			var linkto=$(this).attr('rel');
			$('.news-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load(linkto,
						function(){ $(this).trigger("loadedEvent"); api_1.reinitialise()  });
		e.preventDefault();
		return false;
	})
	$('.press-loaded a.ajaxlink').live('click', function(e) {
			var linkto=$(this).attr('rel');
			$('.press-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load(linkto,
						function(){ $(this).trigger("loadedEvent"); api_2.reinitialise()  });
		e.preventDefault();
		return false;
	})
	
	/*$('.gallery-loaded a.ajaxlink').live('click', function(e) {
			var linkto=$(this).attr('rel');
			$('.gallery-loaded').empty()
				.html('<img src="../img/ajax-loader.gif" class="loading" />')
					.load(linkto,
						function(){  $(this).trigger("loadedEvent"); api_3.reinitialise() });
		e.preventDefault();
		return false;
	})*/
 	
	
	$('.news-loaded, .gallery-loaded, .press-loaded, #load-collection').live("loadedEvent", function(){
	$(".ppt").empty().remove();
	$(".pp_overlay").empty().remove();
	$(".pp_pic_holder").empty().remove();
 	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_square' });
	}); 	
	 
	 
	 
//SUPERSIZE	 
	 
$.supersized({
				
	// Functionality
	slide_interval:		8000,		// Length between transitions
	transition:		1, 			// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
	transition_speed:	1000,		// Speed of transition
	random:			1,
	
	// Components							
	slide_links:	false,	// Individual links for each slide (Options: false, 'num', 'name', 'blank')
	slides:		[			// Slideshow Images
	{image : '../img/001.jpg'},
	{image : '../img/002.jpg'},
	{image : '../img/003.jpg'}
	]
					
	});


//PHOTOBOOK, FULL AJAX

$('ul.menu_photobook li a').live('click', function(e) {
			var linkto = "../photobook.php?lang="+lang+"&pb="+$(this).attr('title');
                        var container = $('#site-container');
                        
			container.fadeOut(300,function(){
                                $(this).empty().show()
				.html('<div id="fp_loading" class="fp_loading" style="display:block"></div>')
					.load(linkto,
						function(){     container.hide();
                                                                $('#supersized').fadeOut(300,function(){
                                                                                $(this).empty();
                                                                                $('#fp_gallery').show();
                                                                                container.fadeIn(600);
                                                                                });
                                                                
                                                                 });
                         })               
		e.preventDefault();
                
		return false;
})

//PHOTOCOLL FULL AJAX

$('ul.menu_photocoll li a').live('click', function(e) {
                       if(vars.is_paused==false) api.playToggle();    //stoppa il supersized
                       
			var linkto = "../photocoll.php?lang="+lang+"&pb="+$(this).attr('title');
                        var container = $('#load-collection');
                        
			container.fadeOut(300,function(){
                                $(this).empty().show()
				.html('<div id="fp_loading" class="fp_loading" style="display:block"></div>')
					.load(linkto,
						function(){
                                                          container.hide().fadeIn(600);
                                                          container.trigger("loadedEvent");
                                                          });
                         })               
		e.preventDefault();
                
		return false;
})

});
