//Feature Navigation
$(document).ready(function(){
	$("#feature2, #feature3").hide();
	$("#featureNav1 a").click(function(){
		runGat('Home Page Feature', 'Tab - Clarkson: An Overview')
		$("#featureNav").css("background-position", "right -40px");
		$("#notes").fadeIn();
		$("#notesOpen").hide();
		$("#featureNav a").removeClass("active");
		$(this).addClass("active");
		$("#featureContainer").css("background", "url(/_site_support/images/homeFeatureBg.png)");
		$("#feature1").fadeIn();
		$("#feature2, #feature3").hide();
		return false;
	});
	$("#featureNav2 a").click(function(){
		runGat('Home Page Feature', 'Tab - Meet Clarkson')
		$("#featureNav").css("background-position", "right center");
		$("#notes").fadeIn();
		$("#notesOpen").hide();
		$("#featureNav a").removeClass("active");
		$(this).addClass("active");
		$("#featureContainer").css("background", "url(/_site_support/images/homeFeatureBg.png)");
		$("#feature2").fadeIn();
		$("#feature1, #feature3").hide();
		return false;
	});
	$("#featureNav3 a").click(function(){
		runGat('Home Page Feature', 'Tab - Browse the Campus')
		$("#featureNav").css("background-position", "right 40px");
		$("#notes, #notesOpen").hide();
		$("#featureNav a").removeClass("active");
		$(this).addClass("active");
		$("#featureContainer").css("background", "none");
		$("#feature3").fadeIn();
		$("#feature1, #feature2").hide();
		return false;
	});
});

//Run jQuery Cycle
$(document).ready(function() {
	$("#feature1 .slideshow").cycle({
		random: 1,
		timeout: 0, 
		speedIn: 1000,
		speedOut: 200,
		prev: '#feature1 .previous',
        next: '#feature1 .next',
		pager: '#thumbnails ul', 
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#thumbnails ul li:eq(' + idx + ') a'; 
		} 
	});
	$("#feature2 .slideshow").cycle({
		random: 1,
		timeout: 0, 
		speedIn: 1000,
		speedOut: 200,
		prev: '#feature2 .previous',
        next: '#feature2 .next' 
	});
});

//Carousel
$(function() {
	var step = 1; 
	var current = 0; 
	var maximum = $('#thumbnails ul li').size(); 
	var visible = 4; 
	var speed = 200; 
	var liSize = 160;

	var ulSize = liSize * maximum; 
	
	if(current == 0) { $('#thumbnails .arrowleft').addClass("disabled"); } else { $('#thumbnails .arrowleft').removeClass("disabled"); };   

	$('#thumbnails ul').css("width", ulSize+"px").css("left", -(current * liSize));

	$('#thumbnails .arrowright').click(function() { 
		if(current + step < 0 || current + step > maximum - visible) {return false; }
		else {
			current = current + step;
			$('#thumbnails ul').animate({left: -(liSize * current)}, speed, null);
			if(current == 0) { $('#thumbnails .arrowleft').addClass("disabled"); } else { $('#thumbnails .arrowleft').removeClass("disabled"); };
			if(current + step > maximum - visible) { $('#thumbnails .arrowright').addClass("disabled"); } else { $('#thumbnails .arrowright').removeClass("disabled"); };
		}
		return false;
	});

	$('#thumbnails .arrowleft').click(function() { 
		if(current - step < 0 || current - step > maximum - visible) {return false; }
		else {
			current = current - step;
			$('#thumbnails ul').animate({left: -(liSize * current)}, speed, null);
			if(current == 0) { $('#thumbnails .arrowleft').addClass("disabled"); } else { $('#thumbnails .arrowleft').removeClass("disabled"); };
			if(current + step > maximum - visible) { $('#thumbnails .arrowright').addClass("disabled"); } else { $('#thumbnails .arrowright').removeClass("disabled"); };
		}
		return false;
	});
});

//Thumbnail Navigation Variables
$(document).ready(function() {
	var thumbCount = $("#thumbnails .wrapper ul").children().size();
	if (thumbCount == 1 ) {
		$("#thumbnailsNav").hide();
	};
	if (thumbCount >= 2 && thumbCount <= 4 ) {
		$("#thumbnailsNav .arrowleft").addClass("disabled");
		$("#thumbnailsNav .arrowright").addClass("disabled");
	};
});
