$(document).ready( function(){

	$.localScroll({offset: {top:-168} });

	var windowheight = $(window).height();
	var layoutheight = $("body").height();
	if ( windowheight > layoutheight ) { $("body").css({height: windowheight}); }
	
	
	//Scroll to Top
	$("#toTop").hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#toTop').fadeIn();
			} else {
				$('#toTop').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#toTop').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
	
	
	
	// check for hash on page load and update side bar nav
	if(window.location.hash != '') {
		$('#sidebar li').removeClass('sidecurrent');
		$('#sidebar li a').each(function(index) {
			if($(this).attr('href') == window.location.hash) {
				$(this).parent('li').addClass('sidecurrent');
			}
		});
	}
	
	
	// on click update side bar styles
	$('#sidebar li a').click(function(event) {
		$('#sidebar li').removeClass('sidecurrent');
		$(this).parent('li').addClass('sidecurrent');
	});
	
	
	
	// media acordian
	//faq accordion
	$('.accordion h3').click(function() {
		if( $(this).next().is(':visible')==false ){
			$(this).next().css("height", $(this).next().height());
			$('#accordion h3').removeClass('acc_title_on');
			$(this).next('ul').slideUp();
			$('#accordion h3').next().slideUp();
			$(this).addClass('acc_title_on');
			$(this).next().slideDown();
		}else{
			$(this).next().slideUp();
			$(this).removeClass('acc_title_on');
		}
		return false;
	});
	
	
	// person profile
	$('.view_person').click(function(event) {
		var block = $(this).parent('div').children('div.person_details');
		var href = $(this);
		if($(block).css('display') == 'block') {
			
			$(block).slideUp(400, function() {
				$(href).removeClass('view_person_open');
			});
		} else{
			$(block).slideDown(400);
			$(this).addClass('view_person_open');
		}
	});
	
	
	$(".gotovideo").click(function() {
		$.fancybox({
				'padding'		: 1,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'titleShow'		: false,
				'overlayColor'	: '#000',
				'overlayOpacity': .8,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				   	 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
	
	
	// ====================
	// = Request PSD form =
	// ====================
	
		$("#request_form").validate();
		
		$('#submit_psd_form').click(function(event) {
			if($('input.fundoption:checked').length == 0) {
				alert('Please select K2 Fund PDF!');
				return false;
			} else {
				return true;
			}
		});
 		
	
	
});

