var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	$j('#disclaimer-btn').colorbox({inline:true, width:"30%"});
	
	//animate home page memberships
	var origMemName = $j('.memberships h2').html()
	$j('.membership-group').mouseenter(function (){
		var memName = $j(this).attr('name');
		$j('.memberships h2').html(memName);
	});
	
	$j('.membership-group').mouseleave(function (){
		$j('.memberships h2').html(origMemName);
	});


	if ($j('#media').length > 0 ||$j('#referrals').length > 0 || $j('#contact').length > 0){
		$j('.subnav-wedge').hide();
		$j('.nav-secondary > ul').css({"background-color" : "transparent"})

	}
	
	
	$j('.current_page_item > a >img').show();
	
	var topOffset = 104;
	
	$j(function() {
	    $j(window).scroll(function() {
	      if ($j(this).scrollTop() > topOffset) {
	        $j('.sidebar').addClass('pinned');
			$j('.sidebar').css({right: ($j(window).width() - 1000)/2 + 1 + "px", top: "15px"});	
	      } else {	
	        $j('.sidebar').removeClass('pinned');
			$j('.sidebar').css({right: 0, top: 0});	
	      }
	    });
	  });
	
	$j('.colorbox').colorbox({iframe:true, width:"80%", height:"80%"});
	

	

	$j('.video-swap').click(function (){
		$j(this).html('<iframe class="youtube" width="420" height="315" src="http://www.youtube.com/embed/'+$j(this).attr('videoID')+'?autoplay=1" frameborder="0" allowfullscreen></iframe>');
	});
	
	
	

	// $j('div.news-scroll ul').animate({
	// 		top:-$j('div.news-scroll ul li:nth-child('+liCount +')').offset().top
	// 	}, 'slow');
	
	// var liCount = 0;
	// 
	// function scrollLi (){
	// 	liCount++;
	// 	// $j('div.news-scroll ul').animate({
	// 	// 			scrollTop:$j('div.news-scroll ul li:nth-child('+liCount +')').position().top
	// 	// 		}, 'slow');
	// 	var liTop = $j('div.news-scroll ul li:nth-child('+liCount +')').position().top;
	// 	$j('div.news-scroll').scrollTop(liCount*100, 0);
	// 	//console.log(liCount, $j('div.news-scroll ul li:nth-child('+liCount +')').position().top);
	// };
	// var refreshIntervalId = setInterval(scrollLi, 1000)
	
	startScroll();
	
	$j('div.news-scroll').mouseenter(function (){
		$j('div.news-scroll ul').pauseAnimation();
		$j('.news-scroll').css({"overflow-y":"auto"});
	});

	$j('div.news-scroll').mouseleave(function (){
		$j('.news-scroll').css({"overflow-y":"hidden"});
		$j('div.news-scroll ul').css({'padding-top' : 0})
		$j('div.news-scroll ul').resumeAnimation();
	});
	
	function startScroll(){
		$j('div.news-scroll ul').css({"top": $j('div.news-scroll').height()/20});
		$j('div.news-scroll ul').startAnimation({"top":  -	$j('div.news-scroll ul').height()}, 120000, "linear", function(){
			resetScroll();
		});
	};
	
	function resetScroll(){
		$j('div.news-scroll ul').css({"top": "0"});
		startScroll();
	}

});

var depthCount = 100;
function showArticle(pageID){
	$j('#press-content-'+pageID).css({"z-index" : depthCount++});
	$j('#press-content-'+pageID).addClass('show-press').hide().fadeIn().click(function (){
		$j('.press-content').fadeOut(300, function (){
			$j(this).removeClass('show-press');
		})
	});
}

