jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.browser.msie6 = jQuery.browser.msie &&
parseInt(jQuery.browser.version) == 6 &&
!window["XMLHttpRequest"];

jQuery.extend( jQuery.easing,
{
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});


// SLIDING FUNCTIONS

jQuery(function( $ ){
				
	//Easing equation for panel
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	
	/**
	 * 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 = $('#content').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
	 */
	$("#navigation").localScroll({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1300,
		easing:'easeOutQuart',
		hash:true,	
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
//			$("#content").css({height: 280});
//			if(anchor.id=="apropos" || anchor.id=="competences" || anchor.id=="emploi"){
//				$("#content").css({height: 280});
//			}			
		},
		onAfterFirst:function(anchor){				
		}
	});
	
});
		


jQuery.extend( jQuery.easing,
{
	
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}

});

$(document).ready(function () {
							
	var lastaccordion;
// ACCORDION
//	$('div.accordion > h3').click(function() {
//		$('#topPanel').css("height", "auto");
//		$(this).next().slideToggle('normal');
//	});	

	
// PANEL
	$("#topPanel").animate({ 
    	height: "0px",
    	opacity: 0
    }, 0 );
    
    $(".topPanelContent").fadeOut();
	var topPanelHidden = true;
	var topPanelShowing;
	var hasClosed;
	



	$(".topPanelLink").click(function(){
		var targetPane = $(this).attr('href');
		
		if(topPanelHidden != true){
			$('.topPanelLink').removeClass('selected');
      		$("#topPanel").animate({ 
				height: "0px",
				opacity: 0
      		}, 500);
      		$(".topPanelContent").fadeOut(500);
			if(jQuery.browser.msie6) {
			$("#global #toplogo a").css("background-image", "url(/images/logo_gris.gif)");
			}else{
			$("#global #toplogo a").css("background-image", "url(/images/logo_gris.png)");				
			}
      		hasClosed = true;
		}
			
			
		if(topPanelShowing != targetPane || topPanelHidden == true) {
			$(".topPanelContent").css("visibility", "visible");									  			
			topPanelShowing = targetPane;
			$(this).addClass('selected');
			$('div' + targetPane).animate({ 
				opacity: 1
			}, 500, function(){	
				$('div' + targetPane).fadeIn(500);
			});

			
		 	$('body').scrollTo( { top:0 , left:0}, 1000);
			$("#topPanel").animate({ 
				opacity: 1
			}, 0 );
//			if (topPanelShowing == "#abouts"){
//				$("#topPanel").animate({ 
//					height: 550,
//					opacity: 1
//				}, 500);
//			}else{
				$("#topPanel").animate({ 
					height: $(topPanelShowing).height()+20,
					opacity: 1
				}, 500, function(value) {
						if(topPanelShowing=='#contact') {
							  $("input#Nomprenom").select().focus();
						}
						if(topPanelShowing=='#login') {
							  $("input#user").select().focus();
						}		
  					});				
//			}
			if(jQuery.browser.msie6) {
				$("#global #toplogo a").css("background-image", "url(/images/logo_blanc.gif)");
			}else{
				$("#global #toplogo a").css("background-image", "url(/images/logo_blanc.png)");
			}
      		hasClosed = false;
			
			if(isIE) {
				$("#about_davide .image_apropos").css("background-image", "url(/images/davide.jpg)");
				$("#about_audrey .image_apropos").css("background-image", "url(/images/audrey.jpg)");			
			}
				
		}
		
		
		topPanelHidden = hasClosed;
		
		return false; 
    });

});
