/**
 * Homepage Carousel
 *
 * By Richard Ye - http://www.yerich.net/
 * Made for hire by dlcreative via oDesk.com
 * oDesk username: richardye
 *
 * Copyright (c) ticescorner.com 2010, all rights reserved.
 *
 * Created: August 24, 2010
 */

function doHomepageCarousel(id){
	//calculate the top offset of the little while indicator arrow
	newarrowposition = 12 + $("#carousel_text_"+id).position().top - $("#carousel_text_1").position().top + (id-1) * 21;
	$("#homepage_carousel_arrow").stop(true, false);
	$("#homepage_carousel_arrow").animate({ top : newarrowposition}, 200);
	$("#homepage_carousel_images div[id!=carousel_image_"+id+"]").fadeOut(200);
	$("#carousel_image_"+id).fadeIn(200);
}

var anim;
function animateHomepageCarousel(i){
	i = ((i+1) % $("#homepage_carousel_images div").length);
	doHomepageCarousel((i+1));
	anim = setTimeout("animateHomepageCarousel("+i+")", 6000);
}

$(document).ready(function() {
	/* uncomment this for changing on mouse over. It's a bit buggy, though.
	$("#carousel_text_1").mouseover(function() {
		doHomepageCarousel(1);
		//odd little bug involving the arrow not moving; this should fix it
		setTimeout("animateHomepageCarousel(1)", 300);
	});
	$("#carousel_text_1").click(function() {
		doHomepageCarousel(1);
	});
	$("#carousel_text_2").mouseover(function() {
		doHomepageCarousel(2);
	});
	$("#carousel_text_2").click(function() {
		doHomepageCarousel(2);
	});*/

	$("#homepage_carousel_wrapper").mouseover(function() {
		clearTimeout(anim);
	});
	$("#homepage_carousel_wrapper").mouseout(function() {
		clearTimeout(anim);
		anim = setTimeout("animateHomepageCarousel(1)", 6000);
	});
	animateHomepageCarousel(1);
});
