$(document).ready(function() {
	// set default variables
	window.numHeroSlides = $(".hero-slide").length;
	window.currHeroSlide = 1;
	window.heroDuration = 13000;
    window.slideDuration = 2000;

	

        if ($("#the-team").length) {
           $("#the-team").css("overflow-x", "hidden");
           $("#the-team").css("overflow", "hidden");
           $("#the-team").css("height", "532px");
           $("#the-team ol#scroll-groove").css("display", "block");

           $("#scroll-groove li").bind("click", clickName);
           $(".info").hide();

           $("#clark").click();
        }


	// start the home hero rotation
	window.heroInterval = setInterval(home_showNextHero, window.heroDuration);

	// create the binds for the hero area
	$(".next-hero").show().bind("click", home_clickNextHero);
	$(".previous-hero").show().bind("click", home_clickPreviousHero);
	$(".goto-hero").show().bind("click", home_gotoHero);


	// create the binds for the scrollTo calls
	$("body.app .main-navigation ul .scrollLink").click(function(e) {
		e.preventDefault();
		var myAnchor = "#" + $(this).attr("id").split("-")[1];
		$.scrollTo(myAnchor, 250);
	});

	var gallery = $("#product-navigation");
	var placeholder = gallery.find("#product-detail-window .slider img");
	gallery.find("#product-detail-nav ul li a").click(function() {
		var href = this.href;
		placeholder.attr("src", href);
		//placeholder.fadeOut("fast", function() {
		//$(this).attr("src", href).fadeIn("fast");
		//});
		return false;
	}); 
     
});


function ame_hideHero(theSlide, theDir) {
	var newLeft;

	if (theDir == "next") {
		newLeft = "-1025px";
	} else if (theDir == "previous") {
		newLeft = "1025px";
	}

	$(theSlide).animate({
		"left": newLeft
	}, {
		"duration": "slow"
	});	
}

function ame_showHero(theSlide, theDir) {
	var newLeft;

	if (theDir == "next") {
		newLeft = "1025px";
	} else if (theDir == "previous") {
		newLeft = "-1025px";
	}

	$(theSlide).css({"left": newLeft});
	$(theSlide).animate({
		"left": 0
	}, {
		"duration": "slow"
	});
}

function home_clickNextHero(e) {
	clearInterval(window.heroInterval);
	home_showNextHero(e);
}

function home_showNextHero(e) {	
	var currSlide = window.currHeroSlide++;
	var nextSlide = window.currHeroSlide;
	
	if (nextSlide > window.numHeroSlides) {
		nextSlide = 1;
		window.currHeroSlide = 1;
	}
	
	ame_hideHero("#slide-" + currSlide, "next");
	ame_showHero("#slide-" + nextSlide, "next");
}

function home_clickPreviousHero(e) {
	clearInterval(window.heroInterval);
	home_showPreviousHero(e);
}

function home_showPreviousHero(e) {	
	var currSlide = window.currHeroSlide--;
	var nextSlide = window.currHeroSlide;
	
	if (nextSlide < 1) {
		nextSlide = window.numHeroSlides;
		window.currHeroSlide = window.numHeroSlides;
	}

	ame_hideHero("#slide-" + currSlide, "previous");
	ame_showHero("#slide-" + nextSlide, "previous");
}


