jQuery(document).ready(function($){

/** Bio Link Boxes
//-------------------------------*/


$("a.biolink").click(function(e){
	var the_box = $(this).next(".biolink-box");
	$(the_box).show();
	$(".clickoff-box").show();
	$(".cancel-button").show();
	var class_box = $(this).parent().parent(".class-box");
	var leftCoord = e.pageX; // e.pageX + 20;
	var box_y = $(the_box).height() / 2;
	var class_box_y = $(class_box).height() / 2;
	var offset = class_box_y -box_y;
	
	$(the_box).css({left: leftCoord + "px", top:  offset + "px"});
	
});

$(".cancel-button, .clickoff-box").click(function(){
	$(".biolink-box").hide();
	$(".clickoff-box").hide();
});


$("a.biolink").hover(function(e){
	var the_box = $(this).next(".biolink-box");
	var class_box = $(this).parent().parent(".class-box");
	var box_height = $(the_box).height;
	$(the_box).show();
	$(".clickoff-box").hide();
	$(".cancel-button").hide();
	$(this).mousemove(function(e){
		/*if($.browser.msie){
			var leftCoord = e.pageX; // e.pageX + 20;			
		}else{
			var leftCoord = e.pageX - 150; // e.pageX + 20;						
		}*/
		var leftCoord = e.pageX;
		var box_y = $(the_box).height() / 2;
		var class_box_y = $(class_box).height() / 2;
		var offset = class_box_y - box_y;
		$(the_box).css({left: leftCoord + "px", top: offset + "px"});				
	});
}, function(){
	
	var the_box = $(this).next(".biolink-box");
	$(the_box).hide();
});


/**
	Homepage Slider
*/

window.count = 1;
var slideCount = $(".rotating-slide").length;
var timeOutTime = 6000;
slideTimeout = setInterval(rotateSlide, timeOutTime);

function getCount(){
		return window.count;
}

function setCount(newCount){
	if(!(newCount == slideCount+1) && !(newCount == getCount())){
		window.count = newCount;
	}
}

//Login Arrows

if($("#login-expanded-wrapper").hasClass("showme")){
$("#login-expanded-wrapper").slideDown(function(){
	if($(this).is(":visible")){
		$(this).parent().children(".members-login").children(".login-link").css({backgroundPosition: "103px 8px"});
	}
});
}

setSliderUnderline(getCount());
function rotateSlide(){
$(".shown-list-item").removeClass("shown-list-item");
		if(getCount() == 0){
			$(".rotating-slide").fadeOut();
			setSliderUnderline(getCount());
			setCount(getCount()+1);
		}else if(getCount() < slideCount && !getCount() == 0)
		{
			$(".rotating-slide").fadeOut();
			$(".slider-"+getCount()).fadeOut(function(){
				setCount(getCount()+1);
				setSliderUnderline(getCount());
				$(".slider-"+getCount()).delay(100).fadeIn();
			});
		}else{
			$(".rotating-slide").fadeOut();
			$(".slider-"+getCount()).fadeOut(function(){
				setCount(1);
				setSliderUnderline(getCount());
				$(".slider-"+getCount()).delay(100).fadeIn();
			});
		}
}

$(".slider-link").click(function(){
	clearInterval(slideTimeout);
	var linkVal = parseInt($(this).html());
	setCount(linkVal);
	showSlide(linkVal);
	setSliderUnderline(getCount());
});

$(".btn-slider-right").click(function(){
$(".shown-list-item").removeClass("shown-list-item");
	clearInterval(slideTimeout);
	if(getCount() == slideCount){
		setCount(1);
		showSlide(getCount());
		setSliderUnderline(getCount());
	}else{
		setCount(getCount()+1);
		showSlide(getCount());
		setSliderUnderline(getCount());
	}
});


$(".btn-slider-left").click(function(){
$(".shown-list-item").removeClass("shown-list-item");
	clearInterval(slideTimeout);
	if(getCount() == 1){
		setCount(slideCount);
		showSlide(getCount());
		setSliderUnderline(getCount());
	}else{
		setCount(getCount()-1);
		showSlide(getCount());
		setSliderUnderline(getCount());
	}
});

function setSliderUnderline(slideNumber){
	removeSliderUnderline();
	$(".slider-link-"+slideNumber+" a.slider-link").css({"text-decoration":"underline"});
}

function removeSliderUnderline(){
	$(".slider-link").css({"text-decoration":"none"});
}

function showSlide(index){
	$(".rotating-slide").fadeOut(function(){
		setCount(index);
	});
		$(".slider-"+index).delay(100).fadeIn();
}

}); //End Document Ready
