jQuery(document).ready(function() {


// Navigation Hover
	$('.nav ul li').hover(function(){
		$(this).toggleClass('hover');
	}, function() {
		$(this).toggleClass('hover');
	});
	
// Contact List
	$('.slider').click(function(){
		$('input.live_search').val('');
		$('input.live_search').focus();
		toggle_slidebar($(this).attr("title"));
		toggle_list($(this).attr("title"));
	});
	
	function toggle_slidebar(x){
		if( ! $('#slidebar').hasClass("current") || x == "close" ){
			$('#slidebar').animate({width: 'toggle'});
			$('#slidebar').toggleClass("current");
			
			if( x == "close" ){
				$('li.slider').removeClass("current");
				$('li.slider').parent('ul').removeClass('current');
				$('#list .contacts').removeClass("current");
			}else{
				$('.slider.'+x).siblings().removeClass("current");
				$('.slider.'+x).addClass("current");
				if( $('.slider.'+x).hasClass('last') ){
					$('.slider.'+x).parent('ul').toggleClass('current');
				}
			}
		}else{
			if($('.'+x).hasClass("current")){
				$('.'+x).removeClass("current");
				$('#slidebar').animate({width: 'toggle'});
				$('#slidebar').toggleClass("current");
				$('li.slider').parent('ul').removeClass('current');
				$('#list .contacts').removeClass("current");
			}else{
				if( $('.slider.'+x).hasClass('first') ){
					$('.slider.'+x).parent('ul').removeClass('current');
				}else if( $('.slider.'+x).hasClass('last') ){
					$('.slider.'+x).parent('ul').toggleClass('current');
				}else{
					$('.slider.'+x).parent('ul').removeClass('current');
				}
				$('.slider').removeClass("current");
				$('.slider.'+x).addClass("current");
			};
		}
	};
	
	function toggle_list(x){
		var item = '.'+x;
		if( ! $('.link'+item).hasClass("current") ){
			
			$('.link'+item).addClass("current");
			$('.link'+item).siblings('div').removeClass("current");
			
			$('#list '+item).siblings('div').hide();
			$('#list '+item).siblings('div').removeClass("current");
			
			$('#list '+item).toggleClass("current");
			$('#list '+item).show();
		}
	}
	
// Live Search for List

	// $('.live_search').focus(function() {
	// 	var live_class = $(this).attr("id");
	// 	$(this).liveUpdate("."+live_class,$(this),$('.live_search_clear'));
	// });
	$('input#members').quicksearch('div.member_min');
	
	
//Scroll the menu on mouse move above the #sidebar layer
	$('#list').mousemove(function(e) {
		//Sidebar Offset, Top value
		var s_top = parseInt($('#slidebar #list').offset().top + 50);
		  
		//Sidebar Offset, Bottom value
		var s_bottom = parseInt($('#slidebar #list').height() + s_top);
		
		//Roughly calculate the height of the menu by multiply height of a single LI with the total of LIs
		var mheight = parseInt($('.contacts.current div.item').height() * $('.contacts.current div.item').length);
		
		//I used this coordinate and offset values for debuggin
		// $('#debugging_mouse_axis').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
		// $('#debugging_status').html(Math.round(((s_top - e.pageY)/100) * mheight / 2));
		
		//Calculate the top value
		//This equation is not the perfect, but it 's very close
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 6)
		
		//Animate the #menu by chaging the top value
		$('.contacts.scroll').animate({top: top_value}, { queue:false, duration:500});
	}).mouseleave(function() {
		var s_top = 0;
		var s_bottom = 0;
		var mheight = 0;
		var top_value = 0;
		$('.contacts.current').animate({top: top_value}, { queue:false, duration:500});
		return false;
	});
	
	// if ($(window).width() < 1050) {$("#content").css("padding-top","95px");};
	// 
	// $(window).resize(function() {
	// 	if ($(window).width() > 1024) { 
	// 		$('#content').animate({
	// 			paddingTop: "85px"
	// 		}, { duration: 500, queue: false });
	// 	}else{
	// 		$('#content').animate({
	// 			paddingTop: "95px"
	// 		}, { duration: 500, queue: false });
	// 	}
	// });
	// 
	// $('textarea.expanding').autogrow({
	// 	maxHeight: 250,
	// 	minHeight: 30,
	// 	lineHeight: 0
	// });
});


