
// SLIDING FUNCTIONS

jQuery(function( $ ){
	
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://www.freewebs.com/flesler/jQuery.ScrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	var target = $('#container-slide').get(0);//the scrolled div
	
	/**
	 * restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
	 * could use $(target).scrollTo( 0, {axis:'xy'));
	 * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
	 */
	target.scrollLeft = target.scrollTop = 0;
	
	//scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
	
	var $last = $([]);//save the last link
	
	/**
	 * NOTE: In the former version of the demo, I called $('#navigation').localScroll()
	 * Now I want to also affect the >> and << links, so I'll use $.localScroll() instead
	 */
	$.localScroll({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1200,
		hash:false,
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			this.blur();//remove the awful outline
			
		}
	});
	
	
	
			//by default, the scroll is only done vertically ('y'), change it to both.
			$.scrollTo.defaults.axis = 'xy'; 			
			//this one is important, many browsers don't reset scroll on refreshes
			$('div#content-pages').scrollTo( 0 );//reset all scrollable panes to (0,0)
			$.scrollTo( 0 );//reset the screen to (0,0)
			

			
			//Target examples bindings
			var $paneTarget = $('#content-pages');	
			
			$('#content_home').click(function(){
				$paneTarget.stop().scrollTo( '0', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			$('#content_objetivos').click(function(){
				$paneTarget.stop().scrollTo( '495', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			$('#content_formacao').click(function(){
				$paneTarget.stop().scrollTo( '990', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			$('#content_adicionais').click(function(){
				$paneTarget.stop().scrollTo( '1485', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});

			$('#content_portfolio').click(function(){
				$paneTarget.stop().scrollTo( '1980px', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			$('#content_clientes').click(function(){
				$paneTarget.stop().scrollTo( '2475px', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			$('#content_contact').click(function(){
				$paneTarget.stop().scrollTo( '2970px', 1000, {
					onAfter:function(){
						$("#gallery").hide();
					}
				});
			});
			
			// PNG hack
			$(document).pngFix();
			
			// Controls the full screen mode
			$("a.full").click(function(){
		 	$("div#content-pages").slideToggle("fast");
			$(this).toggleClass("active");
				return false;
			});
			
			$('.clearme').example(function() {
			 return $(this).attr('title'); 
			});
			
	/**
	 *  HIDE THE NAV UNTIL THE PAGE HAS FULLY LOADED
	 * 
	 */
	
	/**
	 *  CONTROL FORMACAO
	 * 
	 */
	 
	 $("#page_formacao div").css({ opacity: 0 });
	 $("#page_formacao h3 a").click(
		function(){
			$(this).addClass("formacao_active");
			$(this).parent().siblings("h3").children("a").removeClass("formacao_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 0.8}, 400 );
			return false;
		}
	);
	 
	 /**
	 *  CONTROL ADICIONAIS
	 * 
	 */
	 
	 $("#page_adicionais div").css({ opacity: 0 });
	 $("#page_adicionais h3 a").click(
		function(){
			$(this).addClass("adicionais_active");
			$(this).parent().siblings("h3").children("a").removeClass("adicionais_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 0.8}, 400 );
			return false;
		}
	);
	 
	/**
	 *  CONTROL CLIENTES
	 * 
	 */
	 
	 $("#page_clientes div").css({ opacity: 0 });
	 $("#page_clientes h3 a").click(
		function(){
			$(this).addClass("clientes_active");
			$(this).parent().siblings("h3").children("a").removeClass("clientes_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 0.8}, 400 );
			return false;
		}
	);
	
	/**
	 *  CONTROL THE NEWS
	 * 
	 */
	 
	 $("#page_programacao div").css({ opacity: 0 });
	 $("#page_programacao h3 a").click(
		function(){
			$(this).addClass("news_active");
			$(this).parent().siblings("h3").children("a").removeClass("news_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 0.8}, 400 );
			return false;
		}
	);
	
});