$(document).ready(function(){
	totalReel = $('#slider_content ul li').size();
	currentReel = 1+(Math.floor(Math.random()*totalReel));
	xPos = 0 - ((currentReel-1)*770);
	$('#slider_content ul').show().css({left:xPos});
	moose = true;
	autoMoose = true;
	reelDelay = 6000;	
	$('#slider_controls a').show().css({opacity:0.2});
	$('#slider_controls .next a').click(function(){
		if(moose==true && totalReel>currentReel){
			xPos = xPos - 770;
			currentReel = currentReel + 1;
			slideTo(xPos);
		}else if(moose==true){
			currentReel = 1;
			infiniteLoop('right');
		}
		return false;
	});	
	$('#slider_controls .prev a').click(function(){
		if(moose==true && currentReel>1){
			xPos = xPos + 770;
			currentReel = currentReel - 1;
			slideTo(xPos);
		}else if(moose==true){
			currentReel = totalReel;
			infiniteLoop('left');
		}
		return false;
	});	
	function infiniteLoop(dir){	
		moose = false;
		totalX = 770 - (770 * totalReel);
		if(dir == 'left'){
			$('#slider_content ul').prepend('<li>'+$('#slider_content ul li:last').html()+'</li>').css({left:-770}).animate({left:0},770,'easeInOutExpo',function(){
				$('#slider_content ul').css({left:totalX});
				$('#slider_content ul li:first').remove();
				moose = true;
			});
			xPos = totalX;
		}else if(dir == 'right'){
			$('#slider_content ul').append('<li>'+$('#slider_content ul li:first').html()+'</li>').animate({left:totalX-770},770,'easeInOutExpo',function(){
				$('#slider_content ul').css({left:0});
				$('#slider_content ul li:last').remove();
				moose = true;
			});
			xPos = 0;
		}
	}	
	$('#slider').hover(function(){
		$('#slider_controls a').stop([]).animate({opacity:1},200);
		autoMoose = false;
		$(this).stop([]);
	},function(){
		$('#slider_controls a').stop([]).animate({opacity:0.2},200);
		autoMoose = true;
		$(this).stop([]);
		autoMagical();
	});
	function autoMagical(){
		$('#slider').animate({opacity:1},reelDelay,function(){
			if(autoMoose == true){
				$('#slider_controls .next a').click();
			}
			autoMagical();
		});
	}	
	autoMagical();
	function slideTo(newX){
		moose = false;
		$('#slider_content ul').animate({left:newX},770,'easeInOutExpo',function(){
			moose = true;
		})
	}	
});
jQuery.easing['jswing'] = jQuery.easing['swing'];
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;
	}
});
jQuery(function( $ ){
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	var target = $('#content').get(0);
	target.scrollLeft = target.scrollTop = 0;
	$.localScroll.hash({
		target: target,
		axis:'xy',
		queue:true,
		duration:1500
	});	
	var $last = $([]);
	$.localScroll({
		target: target,
		axis:'xy',
		queue:true,
		duration:1300,
		easing:'easeOutQuart',
		hash:false,	
		onBefore:function( e, anchor, $target ){//'this' is the clicked link
			$last.removeClass('scrolling');
			$last = $(this).addClass('scrolling');
		}
	});
});
$(document).ready(function(){
	theContent = 'undefined';
	$('ul.selected li').hover(
		function () {
			theContent = $(this).children('a').attr('title');
			$(this).children('a').removeAttr('title');
			$(this).children('div').remove();
			$(this).prepend("<div><span>"+theContent+"</span><img src='images/tooltip.gif' alt='' /><div>");
			var leftMargin =  '-' + Math.round($(this).children('div').width() / 2) + 'px';
			$(this).children('div').css({marginLeft:leftMargin, opacity:0});
			$(this).children('div').animate({top:'-32px', opacity:1}, 400, 'easeOutQuart');
		}, 
		function () {
			$(this).children('a').attr('title', theContent);
			$(this).children('div').remove();
		}
	);
});
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(){
	$("#vrh").hide();
	$("#vrh_btn").toggle(
		function (){$("#vrh").slideDown("slow");},
		function hideEtc(){$("#vrh").slideUp("slow");}
	);
});