$(document).ready(function() {
	// INIT
	var slide 	= 0;
	var param	= 0;
	var active 	= false;
	var slider 	= true;
	// ARRAY
	var loc = ['67','82','63','82','97','52','81'];	
	// reset
	function reset_o() {
		$('#pane-target').stop(true);
		// hide
		$('li.r-0').hide();
		$('li.r-1').hide();
		$('.subslide').hide();
		for(i=0;i<10;i++) { 
			$('.icons li:eq('+i+')').removeClass(); 
			$('.pijlen .p-'+i).stop().hide();
			$('li.slide.s-'+i).hide();
		}
		$('li.slide.s-0').show();
	};
	function showTabs() {
		for(i=1;i<10;i++) {
			$('.icons li:eq('+i+')').show(); 	
		}
	}
	// changetab
	function changeTab(t,e,c) {
		// reset
		reset_o();
		slide = t;
		// show index
		$('.icons li:eq('+t+')').addClass('current');
		$('.pijlen .p-'+t).show();
		//
		$('ul.p-'+t+' .nr0').stop().hide().animate({marginTop: '-=200'});
		$('ul.p-'+t+' .nr1').stop().hide().animate({marginTop: '-=200'});
		// show first marker
		$('li.slide.s-'+t).show();
		if(c=='true') {
			$('li.nr0 a').css({backgroundPosition:'0px -193px'});
			showInnerTab(0);
		}
		// scroll
		$("#pane-target").scrollTo( 'li:eq('+e+')', 1500, {
			queue:true,
			onAfter:function() {
				animateArrows();
			}		
		});
	}
	function showContentTab(t,e) {
		// ugly info solution based in the index
		if(t>0) {
			// hide all the others
			for(i=0;i<10;i++) $('.ps-'+i).hide(); 
			// show current index
			$('.ps-'+t).show(); 
		} else {
			// hide all the others
			for(i=0;i<10;i++) $('.ps-'+i).hide(); 
			// show current index
			$('.ps-0').show(); 
		}
	}
	function animateArrows() {
		$('ul.p-'+slide+' .nr0').stop().show().animate( {marginTop: '+=200'}, {duration: 400, specialEasing: {marginTop: 'easeOutBounce'}, complete: function() {} });;
		$('ul.p-'+slide+' .nr1').stop().show().animate( {marginTop: '+=200'}, {duration: 600, specialEasing: {marginTop: 'easeOutBounce'}, complete: function() {} });;
	}
	function showInnerTab(e) {
		// hide
		$('li.nr0 a').css({backgroundPosition:'0 0'});
		$('li.nr1 a').css({backgroundPosition:'0 0'});
		$('.subslide').hide();
		// show
		$('li.nr'+e+' a').css({backgroundPosition:'0px -193px'});
		$('li.s-'+slide+' ul.pijlerinfo li.r-'+e).show();
	}
	function checkParam() {
		if(param<loc.length-1) {
			param++;
		} else {
			param=0;
		}
	}
	function killTimer(t) {
		if (active) {
			active = !active;
			$(this).stopTime('controlled');
			if(t!="false") reset_o();
		}
	}
	function startTimer() {
		if (!active) {
			active = !active;
			$(this).everyTime(5000, 'controlled', function() {
				checkParam();
				changeTab(param,loc[param]);
			});
		}
	}
	// INIT
	reset_o();
	$('.home-foto').click(function(){ killTimer(); showContentTab(0,loc[0]); changeTab(0,loc[0],'true'); }); // index, location
	$('.icons ul li:eq(0)').click(function(){ killTimer(); showContentTab(0,loc[0]); changeTab(0,loc[0],'true'); }); // index, location
	$('.icons ul li:eq(1)').click(function(){ killTimer(); showContentTab(1,loc[1]); changeTab(1,loc[1],'true'); }); // index, location
	$('.icons ul li:eq(2)').click(function(){ killTimer(); showContentTab(2,loc[2]); changeTab(2,loc[2],'true'); }); // index, location
	$('.icons ul li:eq(3)').click(function(){ killTimer(); showContentTab(3,loc[3]); changeTab(3,loc[3],'true'); }); // index, location
	$('.icons ul li:eq(4)').click(function(){ killTimer(); showContentTab(4,loc[4]); changeTab(4,loc[4],'true'); }); // index, location
	$('.icons ul li:eq(5)').click(function(){ killTimer(); showContentTab(5,loc[5]); changeTab(5,loc[5],'true'); }); // index, location
	$('.icons ul li:eq(6)').click(function(){ killTimer(); showContentTab(6,loc[6]); changeTab(6,loc[6],'true'); }); // index, location

	$('.nr0 a').click(function(){ killTimer('false'); showInnerTab(0); });
	$('.nr1 a').click(function(){ killTimer('false'); showInnerTab(1); });
	
	$('.icons li:eq(0)').addClass('current');
	$('#pane-target').scrollTo( 'li:eq('+loc[0]+')', 0, { 
		queue:true,
		onAfter:function() {
			startTimer();
		}
	});
	showTabs();
});
