$(document).ready(function(){
	var panelCount = 0;
	var panelWidth = 540;
	var panel = 1;
	var navWidth = 0;
	
	panelCount = $('.panel').length;
	
	$('#panelContainer').css('width',panelCount*panelWidth);
	
	$('#nav li').each(function(){
		navWidth += $(this).width()+5;
	});
	
	$('#nav').css('width',navWidth);
	
	$('#bttn-left').click(function(){
		var pos = 0;
		if(panel == 1){
			pos = - (panelWidth*(panelCount - 1));
			panel = panelCount;
		}else{
			panel -= 1;
			pos = - (panelWidth*(panel - 1));
		}
		activeMenu(panel);
		$('#panelContainer').animate({left:pos},540);
		return false;
	});
	$('#bttn-right').click(function(){
		var pos = 0;
		if(panel == panelCount){
			pos = 0;
			panel = 1;
		}else{
			pos = - (panelWidth*panel);
			panel += 1;
		}
		activeMenu(panel);
		$('#panelContainer').animate({left:pos},540);
		return false;
	});
	
	$('#nav li a').each(function(){
		$(this).click(function(){
			var id = $(this).attr('href').replace('#','')*1;
			var pos = 0;
			panel = id;
			pos = - (panelWidth*(id-1));
			activeMenu(panel);
			$('#panelContainer').animate({left:pos},540,'expoinout');
			return false;
		});
	});
	
	$('.button').not('.btab').click(function(){
		var id = $(this).attr('href').replace('#','')*1;
		var pos = 0;
		panel = id;
		pos = - (panelWidth*(id-1));
		activeMenu(panel);
		$('#panelContainer').animate({left:pos},540,'expoinout');
		return false;
	});
	
	$('.btab').click(function(){
		var id = $(this).attr('href').replace('#tab','')*1;
		$('.tab').css('display','none');
		$('#tab'+id).fadeIn('slow');
		return false;
	});
	
	function activeMenu(id){
		$('#nav li').removeClass('here');
		$('#nav li a[href=#'+id+']').parent().addClass('here');
	}
	
	$("a.fancybox").fancybox({
		'hideOnContentClick': true
	});
});

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.extend( jQuery.easing,
{
	expoinout: function(x, t, b, c, d) {
		return jQuery.easing.easeInOutExpo(x, t, b, c, d);
	}
});

