	// FUNCTIONS
	var dif = 0;
	var ratio = 1;
	function doScroll(y) {
		$("#scrollContent").css('top',(-y*ratio)+'px');
	}
	function doScrollbar(top) {
		if(top<0) top = 0;
		if(top>dif) top = dif;
		$("#scrollbar div").css('top',top+'px');
		doScroll(top);
	}
	function scrollContentTo(fragment,top) {
		if(top==null) top = $("#center #"+fragment).position().top-10;
		doScrollbar(top/ratio);
	}
	var scrollbar_drag = false;
	function scrollbarHoverOff() {
		if(!scrollbar_drag) {
			$("#scrollbar div").css({
				backgroundImage:'url(inc/images/main_bg.jpg)',
				backgroundRepeat:'repeat-y',
				backgroundPosition:'0 0',
				backgroundColor:'#ffffff'
			})
		}
	}
	var play = true;		
	var ss = $("#slideshow ul");
	var end = ss.children().length;
	var curIndex = 1;
	var newIndex = 2;
	var ready = true;
	function doSlide(delta) {
		if(ready) {
			ready = false;
			clearTimeout(timer);
			newIndex = curIndex+delta;
			newIndex = newIndex<1?end:(newIndex>end?1:newIndex);
			if(newIndex<curIndex) {
				getSlide(newIndex).css('display','block');
				getSlide(curIndex).fadeOut(500,function() {
					finish();
				});
			} else {
				getSlide(newIndex).fadeIn(500,function() {
					getSlide(curIndex).css('display','none');
					finish();
				});
			}
		}
	}
	function getSlide(i) {
		return $("#slideshow ul li:nth-child("+i+")");
	}
	function finish() {
		curIndex=newIndex;
		ready = true;
		if(play) {
			timer = setTimeout(function() {
				doSlide(1);
			},3000);
		}
	}
	function switchMenu() {
		clearTimeout(switchBackTimer);
		$('.selected').removeClass('selected');
		$('#nav > li.current-page').removeClass('current-page');
		$('#nav > li.current-page-ancestor').removeClass('current-page-ancestor');
		$(this).parent().addClass('selected');
	}
	var original = {
		'selected': $('.current-page'),
		'ancestor': $('.current-page-ancestor')
	}
	function switchBack() {
		original.selected.addClass('current-page');
		original.ancestor.addClass('current-page-ancestor');
		$('.selected').removeClass('selected');
	}
	var timer = null;
	var switchBackTimer = null;
	var loaded = 0;
	$(function() {
		/*
		$("a[href*=#]").each(function() {
			var fragment = $(this).attr("href").split('#')[1];
			//alert(fragment);
			$(this).attr('href',$(this).attr('href').replace('#section','#_section'));
			$(this).click(function() {
				scrollContentTo(fragment);
			});
		});
		init();
		*/
		$("#nav > li > a").mouseover(switchMenu);
		$("#nav a").hover(function() {
			clearTimeout(switchBackTimer);
		},function() {
			clearTimeout(switchBackTimer);
			switchBackTimer = setTimeout(switchBack,2000);
		});
		// SLIDESHOW
		$("#slideshow").append(
			$("<div></div>")
			.append(
				$("<a href='javascript:void(0)'>&gt;</a>")
				.click(function() {
					doSlide(1);
					play = true;
				})
			)
			.append(
				$("<a href='javascript:void(0)'>&lt;</a>")
				.click(function() {
					doSlide(-1);
					play = false;
				})
			)
		);
		timer = setTimeout(function() {
			doSlide(1);
		},3000);
	});
	