var isMoving = false;

var scrollToComment = function(){
	
	var pos = $('#comment').offset(); 
		
	//for Safari below
	$('body').animate({ scrollTop: pos.top + "px" }, { duration: 1000 });
		
	//for all other browsers below
	$('html').animate({ scrollTop: pos.top + "px" }, { duration: 1000 });
};

$(document).ready(function() {
	
	$('.grant-item').hover(function() {
		$(this).addClass('grant-hover');
	}, function() {
		$(this).removeClass('grant-hover');
	});
	
	$('.news-item').hover(function() {
		$(this).addClass('news-hover');
	}, function() {
		$(this).removeClass('news-hover');
	});
	
	$('#rotator-title-content a').click(function() {
		if (isMoving == false) {
			isMoving = true;
			
			var scrollwidth = $('#rotator-items').css("left");
			
			var num = parseFloat(scrollwidth, 10);
			
			var newwidth = num + 155;
			var unit = 'px';
        	
			if(newwidth > 0) {
					
			} else {
				//$('#rotating-items').css('left', newwidth + unit);
				$('#rotator-items').animate({left: newwidth}, 200);

			}
			
			window.setTimeout(function(){isMoving = false},500);
			//$('#rotating-items').css('left', newwidth + unit);
		} else {
			
		}
	});
	
	$('#rotator-next-content a').click(function() {
		//alert(isMoving);
		if (isMoving == false) {
			isMoving = true;
			//alert($isMoving);
			
			var scrollwidth = $('#rotator-items').css("left");
			
			var num = parseFloat(scrollwidth, 10);
			
			var newwidth = num - 155;
			var unit = 'px';
			
			
			if(newwidth < -349) {
			//if(newwidth < -697) {
			//if(newwidth < -175) {	
			} else {
				$('#rotator-items').animate({left: newwidth}, 200)
			}
			window.setTimeout(function(){isMoving = false},200);
			//alert(isMoving);
			//isMoving = false;

		} else {
			
		}

		
	});
	
	$('.about-nav li a').hover(function() {
		
		$('.about-parent').addClass('about-hover');
	
	}, function() {
		$('.about-parent').removeClass('about-hover');
	});

	$('.expert-nav li a').hover(function() {
		
		$('.expert-parent').addClass('expert-hover');
	
	}, function() {
		$('.expert-parent').removeClass('expert-hover');
	});
	

	
	$('.oa-nav li a').hover(function() {
		
		$('.oa-parent').addClass('oa-hover');
	
	}, function() {
		$('.oa-parent').removeClass('oa-hover');
	});
	
	
	
	$('.i-oa-parent').hover(function() {
		
		$('.i-oa-subnav').css("display", "block");
		$('li.i-oa-parent a').addClass("current-nav");
		$('li.i-oa-parent ul li a').removeClass("current-nav");
	
	}, function() {
		$('.i-oa-subnav').css("display", "none");
		$('.i-oa-parent a').removeClass("current-nav");
	});
	
	$('.i-about-parent').hover(function() {
		
		$('.i-about-subnav').css("display", "block");
		$('li.i-about-parent a').addClass("current-nav");
		$('li.i-about-parent ul li a').removeClass("current-nav");
	
	}, function() {
		$('.i-about-subnav').css("display", "none");
		$('.i-about-parent a').removeClass("current-nav");
	});
	
	
	$('li.nav03').hover(function() {
		$('li.nav03 ul').css('display', 'block');
		$(this).children("a").addClass("current-hover");
	}, function() {
		$('li.nav03 ul').css('display', 'none');
		$(this).children("a").removeClass("current-hover");
	});
	
	$('li.nav07').hover(function() {
		$('li.nav07 ul').css('display', 'block');
		$(this).children("a").addClass("current-hover");
	}, function() {
		$('li.nav07 ul').css('display', 'none');
		$(this).children("a").removeClass("current-hover");
	});
	
	$('.activity-overview').hover(function() {
		$(this).addClass("current-hover");
	}, function() {
		$(this).removeClass("current-hover");
	});
	
	/* FORM SCRIPTS */
	
	
	
	
	/*$('a.jNiceRadio').click(function(){
		
		$('#profession-physician-sub').css("display", "none");
		
		
	});
	*/
	$('.profession-parent a.jNiceRadio').click(function(){
		
		$('#profession-physician-sub').css("display", "block");
		
	});

});