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


	/* prototip */

	$($$('a.tooltip')).each(function(el) {
		new Tip(el, $($(el.rel)), {style: 'customtip' });

	});


	// check scrolling isn't active
	var $isScrolling = false;
	
	// scrolling speed (pixel/second)
	var $scrollSpeed	= 1000;
	// minimum/maximum animation time
	var $minAnitime		= 200; // 500 msec = 0.5 sec
	var $maxAnitime		= 1500; // 1500msec = 1.5sec

	// hover effect for gradiented list
	$j('.gradiented-list li').mouseover(function() {
		$j(this).addClass('gradiented');
	});

	$j('.gradiented-list li').mouseout(function() {
		$j(this).removeClass('gradiented');
	});



	// change page
	$j('#nav li a').click(function() {
			
		// block if scrolling is active
		if($isScrolling) { return; }
	
		// determine requested page
		var nav_tab	= $j(this);
		var page 	= nav_tab.attr('href').replace('#', '');
	
		// activate tab
		$j("#nav li a.active").removeClass('active');
		$j(nav_tab).addClass('active');

		// get container and panels
		var container	= $j('#scrolling');
		var new_panel 	= $j('#' + page + '-panel');
		var old_panel 	= $j('.open');


		// if requested page is already visible, block
		if(new_panel.hasClass('open')) { return; }


		// calculate height

		var new_height 	= new_panel.height();
		var old_height	= old_panel.height();
		// get absolute difference in pixel
		var diff	= Math.abs(new_height - old_height);

		// calculate animation time for fadeOut
		var anitime1	= (diff / $scrollSpeed) * 1000;

		
		if(anitime1 < $minAnitime ) { anitime1 = $minAnitime; }
		if(anitime1 > $maxAnitime) { anitime1 = $maxAnitime; }

		// calculate animation time for resize (anitime1 + 10%)
		var anitime2	= anitime1 + anitime1/10;
		// calculate animation time for fadeIn (anitime1 + 20%)
		var anitime3	= anitime1 + 2 * (anitime1/10);
	 
		// positioning of new panel (top left)
		new_panel.css({
				position: "absolute",
				left:	"0px",
				top:	"0px",
				zIndex:	"900"
				});

		// set scrolling as active
		$isScrolling = true;

		// fadout old page
		old_panel.fadeOut({duration: anitime1, complete: function() { 
									old_panel.hide(); 
									old_panel.addClass('hidden'); 
									old_panel.removeClass('open'); 
				}});
		
		// resize container
		
		container.animate({height: new_height + "px"}, {duration: anitime2});

		// fadein new page
		new_panel.fadeIn({duration: anitime3, complete: function() {
							// reset position to "normal"
							new_panel.css({
								position: "static",
								left:	"0px",
								top:	"0px",
									zIndex:	"0"
							});
							new_panel.removeClass('hidden');
							new_panel.addClass('open');
							// set scrolling to inactive							
							$isScrolling = false;
							}}
				);

		});
});




