$(document).ready(function(){
	
	
	
	
	jQuery.each($('.team_pic'), function() {
		var idr = $(this).attr('id');
		var teamid = idr.split('_')[1];
		
		$(this).hover (
			function () {
				$('#'+idr).children('a:eq(0)').children('img:eq(0)').fadeTo(50, 0.2,function(){$('#'+idr).children('a:eq(0)').children('img:eq(0)').fadeTo(500, 1.0)});
				$('.team_member_slide').fadeOut(50);
				$('#team_default_sidebar').fadeOut(50);
				$('#team_member_slide_'+teamid).fadeIn(50);
				//var teamcontentbodyheight = $('#team-contentbody').height();
				//var teammemberslideheight = $('#team_member_slide_'+teamid).height();
				//var targettop = ($(this).offset().top-256)+55;
				//if(teammemberslideheight + targettop > teamcontentbodyheight) {
				//	targettop = teamcontentbodyheight-teammemberslideheight-20;
				//}
				//$('#team-sidebar').animate( { top:targettop+"px" }, { queue:false, duration:500, "easing":'swing' } );
			}, 
			function () {
				$('.team_member_slide').fadeOut(50);
				$('#team_default_sidebar').fadeIn(50);
				//$('#team-sidebar').animate( { top:"0px" }, { queue:false, duration:500, "easing":'swing' }  );
			}
		);
		
		
		$('#'+idr).children('a.team_link').attr('rel','facebox[.team_box]');
		$('#'+idr).children('a.team_link').addClass('fancyzoom');
		$('#'+idr).children('a.team_link').attr('href','teamdetails.php?idr='+teamid);
		
		$('#'+idr).children('.team_name').children('a.team_link').attr('rel','facebox[.team_box]');
		$('#'+idr).children('.team_name').children('a.team_link').addClass('fancyzoom');
		$('#'+idr).children('.team_name').children('a.team_link').attr('href','teamdetails.php?idr='+teamid);
		
	});
	
	
	$('a[rel*=facebox]').facebox();
	
	
});


$(window).scroll(function () { 
var scrollTop = $(window).scrollTop();
var windowheight = $(window).height();
var docheight = $(document).height();
var contentheight = $('#team-maincontent').height();
var sidebarheight = $('#team_default_sidebar').height();

if(scrollTop<50) {
var target = 0;
} else {
var target = scrollTop-50;
}

if(target>contentheight-sidebarheight-20) {
target = contentheight-sidebarheight-20;
}

$('#team-sidebar').animate( { top:target+"px" }, { queue:false, duration:500, "easing":'swing' } );
});

/*
Shadowbox.init({
		continuous:true,
		players: ["iframe"]
	});
*/