// JavaScript Document

// Dénomination:
// nomtrigger_main
// nomtrigger_fond
// nomtrigger_trigger
// nomwin_main
// nomwin_fixe
// nomwin_move

var Up_Information_Timeout;
var Up_Information_On = false;

jQuery(function( $ ){
	/**
	 * Demo binding and preparation, no need to read this part
	 */
		//borrowed from jQuery easing plugin
		//http://gsgd.co.uk/sandbox/jquery.easing.php
		$.easing.elasout = function(x, t, b, c, d) {
			var s=1.70158;var p=0;var a=c;
			if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
			if (a < Math.abs(c)) { a=c; var s=p/4; }
			else var s = p/(2*Math.PI) * Math.asin (c/a);
			return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
		};
		$('a.back').click(function(){
			$(this).parents('div.pane').scrollTo( 0, 800, { queue:true } );
			$(this).parents('div.section').find('span.message').text( this.title );
			return false;
		});
		//just for the example, to stop the click on the links.
		$('ul.links').click(function(e){
			e.preventDefault();
			var link = e.target;
			link.blur();
			if( link.title )
				$(this).parent().find('span.message').text(link.title);
		});
	
});

function Show_Up_Information(value) {
	if (Up_Information_On) return false;
	Up_Information_On = true;
	$("#Up_Information").fadeTo(0,0).html(value).show().fadeTo('normal', 0.8, function() {});
	Up_Information_Timeout = setTimeout("Hide_Up_Information()", 5000);
}

function Hide_Up_Information(value) {
	clearTimeout(Up_Information_Timeout);
	$("#Up_Information").fadeTo('slow', 0, function() {
		$(this).html('');
		Up_Information_On = false;
	});
	
}

function Scroller(trig, win) {
	var monscroller_main = '#' + trig + '_main';
	var monscroller_fond = '#' + trig + '_fond';
	var monscroller_trigger = '#' + trig + '_trigger';
	var monwin_main = '#' + win + '_main';
	var monwin_fixe = '#' + win + '_fixe';
	var monwin_move = '#' + win + '_move';
		
	var height_3 = $(monwin_move).height();
    var heightBox_3 = $(monwin_fixe).height();

	// Initialise le scroller pour capter le mousewheel
	//$(monwin_move).mousewheel(function() {Show_Up_Information('not implented yet !');});

	var trigger_y_3 = $(monscroller_trigger).offset().top;

	//if (height_3 > heightBox_3) {
	  $(monscroller_trigger).draggable({
		  axis: 'y',
		  containment: 'parent',
		  drag: function() {
  
			  var y = $(this).offset().top - trigger_y_3;
			  var heightBox = $(monwin_fixe).height();			
			  var height = $(monwin_move).height()-heightBox;
			  var height_scroll = $(monscroller_fond).height() - $(this).height();
			  y2 = Math.round(height/height_scroll*y);
			 $(monwin_fixe).scrollTop(y2);
			 //$(monwin_fixe).scrollTo( { top:y2 }, 800);//, {easing:'elasout'} );
			 // ( '#target-examples', 800, {easing:'elasout'} )
			 // $paneOptions.scrollTo( 'li:eq(15)', 2500, { easing:'elasout' } );
			  
			  $("#info").html('y ['+y+'] height_scroll ['+height_scroll+'] height['+height+'] y2['+y2+']');
  
		  }
	  })
    //}
}
