$(document).ready(function(){
  $("#slider").slider({
    animate: true,
    change: handleSliderChange,
    slide: handleSliderSlide,
	orientation: 'vertical',
  	value: 360
  });
  
  (function(){
  	var pre_tab = $('.pannel li a:eq(0)');
	var pre_section = $('.gallery .section:eq(0)');
	
	$('.pannel li a').each(function(index){
		$(this).bind({
				click: toggle(index) 
				});								  
	});
	
	function toggle(id) {
		function _slide(e) {
			var new_tab = $(e.currentTarget);	
			var new_section = $('.gallery .section:eq(' + id + ')');
			
			pre_tab.removeClass('active');
			pre_section.hide();
			
			pre_tab = new_tab.addClass('active');
			pre_section = new_section.show();
			
			e.preventDefault();
		}
		return _slide;
	}
	
  })();
  
  $('#soundTrackList li:even').addClass('hilight');
});

function handleSliderChange(e, ui)
{
  var maxScroll = $("#text").attr("scrollHeight") - $("#chats").height();
  $("#text").animate({scrollTop: (100 - ui.value) * (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#text").attr("scrollHeight") - $("#chats").height();
  $("#text").attr({scrollTop: (100 - ui.value) * (maxScroll / 100)});
}
