/* =====================================================================
	Homepage JavaScript Library - Portland Community College
	Written by Gabriel McGovern <gabriel.mcgovern@pcc.edu>
	Compress with jsmin <http://fmarcia.info/jsmin/test.html>
	Change Log: 
		2009-08-26 gabriel mcgovern: Created									  				 
 * ===================================================================== */
 
// globals
var photoWidth = 470; 	// image + margin - set by hand
var current = 0;		// track current - should be 0 for first
var photoAmount; 		// number of photos - set in featureSetup


// Getting Started
$(document).ready(function(){ 	   
	$("#profile-slider, #profile-select").hide().load("/build-feature.html", function(){ featureSetup(); }); // load features - then call setup function 			   
	hoverSetup();
});



// add hover and click actions (audience and promo combined)
function hoverSetup(){
	$("#snav div.audience, #promo").hover(
      function () {
        $(this).addClass("over");
      },function () {
        $(this).removeClass("over");
      });    
	$("#snav div.audience,#promo").click(function () { 
      window.location = $(this).find("a").attr("href"); 
    });
}



// Set up feature for animation
function featureSetup(){
	
	// wait for images to load
	$("#profile-slider img").load(function(){ 
		$("#profile-select a img").height(27).width(46); //fade all but first
		$("#profile-slider").fadeIn("fast", function(){ 
			$("#profile-select").fadeIn("slow");
		});
	});

	$("#profile-select a").hover(
      function () {
        $(this).addClass("over");
      },function () {
        $(this).removeClass("over");
      });
	
	$("#profile-slider a").hover(
      function () {
        $("#profile-pane").addClass("over");
      },function () {
        $("#profile-pane").removeClass("over");
      });
	
		
	$("#profile-select a").click(function () { 
		var thisNum = $("#profile-select a").index(this);
		animateTo(thisNum);		
		return false;
	});
	
	
	// set photoAmount 
	photoAmount = $("#profile-slider img").length;

	animateTo(current);
}



// And here is the animation
function animateTo(num){
	if(num>=0 && num< photoAmount){
		var offset = num * photoWidth; // get proper offset
		$("#profile-slider").stop().animate({left:"-"+offset+"px"},"fast","swing", function () {afterAnimate(num)}  );
	}
}



// After animate update everything
function afterAnimate(num){
	// set current 
	current = num; 
	$("#profile-select a").removeClass("current");
	$("#profile-select a:eq("+current+")").addClass("current"); //fade all but first

}
