$(document).ready(function( $ ) {

	    $('#nav0').addClass('selected');
		$('#pane-target').scrollTo( $('#section0'), 1000 ); //at page loading
	
	   	$("a[rel=external]").attr('target', '_blank');
	
	

	
/** --------------------------ajax--------------------------------------------------- **/	
	
	
	/* var $sections = $('#navigation a'),// Links on the left
			last = null;// Last section */


        var last = '';


		$('#loadcontent1').click(function(){
			if( last != this ){ // let's avoid needless requests
				//var url = 'html/' + this.hash.slice(1) + '.html';
				 // var url = 'page2.html';
				var url = 'http://www.bpl.it/bpl.it/page2.html';
				$('#logotype').html( '<p class="loading">Loading...</p>' ).load( url, function(){
					
				});
			}
		last = this;
		this.blur(); // Remove the awful outline
		return false;
		});



		$('#loadcontent2').click(function(){
			if( last != this ){ // let's avoid needless requests
				//var url = 'html/' + this.hash.slice(1) + '.html';
				  //var url = 'page3.html';
				var url = 'http://www.bpl.it/bpl.it/page3.html';
				$('#sldsh_6').html( '<p class="loading">Loading...</p>' ).load( url, function(){
					//this.scrollLeft = 0;//scroll back to the left
				
						$('#screen6').serialScroll({
							target:'#sldsh_6',
							items:'li',prev:'a.prev',next:'a.next',navigation:'#navigationsub li a',axis:'xy',constant:false,
							offset:0, start:0, duration:600,force:false,stop:true,lock:false,cycle:true, 
							easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
						    }
						});
				
				
				});
			}
		last = this;
		this.blur(); 
		return false;
		});


			$('#loadcontenttxc').click(function(){
				if( last != this ){ // let's avoid needless requests
					//var url = 'html/' + this.hash.slice(1) + '.html';
					  //var url = 'pagetxc.html';
					var url = 'http://www.bpl.it/bpl.it/pagetxc.html';
					$('#sldsh_1').html( '<p class="loading">Loading...</p>' ).load( url, function(){
						

						$('#screen1').serialScroll({
							target:'#sldsh_1',
							items:'li',prev:' a.prev',next:' a.next',
							offset:0, start:0, duration:600,force:true,stop:true,lock:false,cycle:true, 
							easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
						    }
						});


					});
				}
			last = this;
			this.blur(); 
			return false;
			});


				$('#loadcontentnoise').click(function(){
					if( last != this ){  
						  //var url = 'pagenoise.html';
						var url = 'http://www.bpl.it/bpl.it/pagenoise.html';
						$('#sldsh_2').html( '<p class="loading">Loading...</p>' ).load( url, function(){


							$('#screen2').serialScroll({
								target:'#sldsh_2',
								items:'li',prev:' a.prev',next:' a.next',
								offset:0, start:0, duration:600,force:true,stop:true,lock:false,cycle:true, 
								easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
							    }
							});


						});
					}
				last = this;
				this.blur(); 
				return false;
				});
		
		
				$('#loadcontentvafu').click(function(){
					if( last != this ){  
						 // var url = 'pagevafu.html';
						var url = 'http://www.bpl.it/bpl.it/pagevafu.html';
						$('#sldsh_3').html( '<p class="loading">Loading...</p>' ).load( url, function(){


							$('#screen3').serialScroll({
								target:'#sldsh_3',
								items:'li',prev:' a.prev',next:' a.next',
								offset:0, start:0, duration:600,force:true,stop:true,lock:false,cycle:true, 
								easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
							    }
							});


						});
					}
				last = this;
				this.blur(); 
				return false;
				});				
				



		//$sections.eq(0).click(); // Load the first section
	
	
/** --------------------------sub content--------------------------------------------------- **/	
	
		$(".toggle_container").hide(); 

			//Switch the "Open" and "Close" state per click
			$("h2.trigger").toggle(function(){
				$(this).addClass("active");
				$(this).addClass("activelink");
				}, function () {
				$(this).removeClass("active");
				$(this).removeClass("activelink");
				
			});

			//Slide up and down on click
			$("h2.trigger").click(function(){
				$(this).next(".toggle_container").slideToggle("fast");
				//alert (this);
			});
		
		/* subcycle */

         	$(".prev").mouseover(function(){
				$(this).addClass("activeprev");return false;
				}).mouseout(function (){
				$(this).removeClass("activeprev");
				return false;
			});
			
			
			$(".next").mouseover(function(){
				$(this).addClass("activenext");return false;
				}).mouseout(function (){
				$(this).removeClass("activenext");
				return false;
			});

/** --------------------------slide----------------------------------------------------- **/	
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};



$('#screen4').serialScroll({
	target:'#sldsh_4',
	items:'li',prev:'a.prev',next:'a.next',offset:0, start:0, duration:600,force:false,stop:true,lock:false,cycle:true, 
	easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
    }
});

/*
$('#screen5').serialScroll({
	target:'#sldsh_5',
	items:'li',prev:'a.prev',next:'a.next',navigation:'#navigation li a',
	offset:0, start:0, duration:600,force:false,stop:true,lock:false,cycle:true, 
	easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
    }
});	


$('#screen6').serialScroll({
	target:'#sldsh_6',
	items:'li',prev:'a.prev',next:'a.next',offset:0, start:0, duration:600,force:false,stop:true,lock:false,cycle:true, 
	easing:'easeOutQuart', jump: false, onBefore:function(){$(".prev").removeClass("activeprev");$(".next").removeClass("activenext");
    }
});
  */
/** --------------------------scrollEngine----------------------------------------------------- **/	


$('.link').click(function(event) {
	event.preventDefault();var gerolong=$(this).attr('href');var gerolong = gerolong.split("#");var gero='#'+gerolong[1];
	$('#main_nav ul li').removeClass('selected');
	if(gero==='#section0')
	                {
		            $('#nav0').addClass('selected');
	                }
    else if(gero==='#section1')
					{
					$('#nav1').addClass('selected');	
					}
    else if(gero==='#section2')
					{
					$('#nav2').addClass('selected');	
					}
	else if(gero==='#section3')
					{
					$('#nav3').addClass('selected');	
					};
	
	$('#pane-target').scrollTo($(gero), 500);
	});

/** ------------------------------------------------------------------------------------------- **/


   
});//close document ready
