var currentHomeFeature2 = 1;
var transitionDelay2 = 700;
var slideDuration2 = 8000;
var showHideDuration2 = 150;
var homeFeatureCount2;
var intervalVar2;
var hitAreaTopX2, hitAreaTopY2, hitAreaBottomX2, hitAreaBottomY2;
var featureSelectOffSrc2 = "/images/home/features/homeFeatureSelectOff.gif";
var featureSelectOnSrc2 = "/images/home/features/homeFeatureSelectOn.gif"

$(document).ready( function(){

	// add feature heading mouseover event
	$("div.homeFeature2").hover(function() {
		clearInterval(intervalVar2);
		$(this).children(".homeFeatureSlide2").fadeIn(showHideDuration2);
	}, function() {
		$(this).children(".homeFeatureSlide2").fadeOut(showHideDuration2);
		startSlideshow2();
	});
	
	// feature navigation
	$("div#homeFeatureChoose2 a").click(function() { 
		clearInterval(intervalVar2); // stop slideshow
		this.blur();
		var currentId2 = this.href.split("#");
		currentId2 = parseInt(currentId2[1]);
		fadeHomeFeatures2(currentHomeFeature2, currentId2);
		updateCurrent2(currentId2);
		startSlideshow2(); // resume slideshow
		return false;
	});

	// auto slideshow
	homeFeatureCount2 = $(".homeFeature2").length;
	startSlideshow2();
	
});

function startSlideshow2() {
	if (homeFeatureCount2 > 1) {
		intervalVar2 = setInterval("advanceSlideshow2()", slideDuration2);
	}
}

function advanceSlideshow2() {
	// determine what next slide is
	if (currentHomeFeature2 == homeFeatureCount2) {
		nextSlide2 = 1;
	} else {
		nextSlide2 = currentHomeFeature2 + 1;
	}
	fadeHomeFeatures2(currentHomeFeature2, nextSlide2);
	updateCurrent2(nextSlide2);
}

function fadeHomeFeatures2(oldNum2, newNum2) {
	$("#hfd_" + oldNum2).fadeOut(transitionDelay2);
	$("#hfd_" + newNum2).fadeIn(transitionDelay2)
}

function updateCurrent2(newNum2) {
	$("#currentCount").text(newNum2.toString());
	currentHomeFeature2 = newNum2;
	$("#homeFeatureOptions ul li").removeClass("selectedFeature");
	$("#hfl_" + newNum2).parent().addClass("selectedFeature");
	$("#homeFeatureChoose a img").attr("src", featureSelectOffSrc2);
	$("#homeFeatureChoose a img#hfd_select_" + newNum2).attr("src", featureSelectOnSrc2);
}

function showFeatureList(mouseX, mouseY) {
	if ((mouseX < hitAreaTopX2) || (mouseY < hitAreaTopY2)) {
		return false;
	} else if ((mouseX > hitAreaBottomX2) || (mouseY > hitAreaBottomY2)) {
		return false;
	} else {
		return true;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}