/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
 * Home Controller, v1.0
 * (c) 2004 timallen.com
 * created by bivia of bivia.com, July 22 2004
 * $Id: homeController.js,v 1.3 2005/01/31 09:49:31 bcurtis Exp $
 *
 * handles animation and motion on the home page
 *~~~~*/

var Hm = {};

function bv_homeInit() {
	Hm = {
			title : document.getElementsByTagName('h1')[0],
			bigTim : document.getElementById('bigTim'),
			header : document.getElementById('homeHeader'),
			footer : document.getElementById('footer'),
			content : document.getElementById('homeContent'),
			news : document.getElementById('homeHeadlines').getElementsByTagName('div')[0],
			control : document.getElementById('homeScrollControls')
		}
//	bv_setOpacity(Hm.title, 100);
//	bv_setOpacity(Hm.content, 0);
	Hm.title.style.visibility = "visible";
	Hm.header.style.visibility = "hidden";
	Hm.content.style.visibility = "hidden";
	Hm.footer.style.visibility = "hidden";
	bv_homeScrollerInit();
	bv_homeClickablesInit();
}
bv_addListener(window, 'docload', bv_homeInit);





function bv_homeHeaderDescend() {
	var Top = Math.ceil(parseInt(Hm.header.style.top) *0.8);
	if (Top > -1) Top = 0;
	Hm.header.style.top = Top +"px";
	if (Top < 0) setTimeout("bv_homeHeaderDescend()", 15);
}

function bv_homeTitleDash() {
	var Right = Math.ceil((parseInt(Hm.title.style.right) -374) *1.2) +374;
	if (Right > 3000) Right = 3000;
	Hm.title.style.right = Right +"px";
	if (Right < 3000) setTimeout("bv_homeTitleDash()", 15);
}
function bv_homeContentDash() {
	var Right = Math.floor((parseInt(Hm.content.style.right) -50) *0.8) +50;
	if (Right < 50) Right = 50;
	Hm.content.style.right = Right +"%";
	if (Right > 50) setTimeout("bv_homeContentDash()", 15);
	else if (navigator.platform == "MacPPC" && navigator.appName == "Microsoft Internet Explorer") {
		// fix a drawing error
		window.resizeBy(-1,0);
		window.resizeBy(1,0);
	}
}

function bv_swipeFade() {
	if (bv_homeTimer) clearTimeout(bv_homeTimer);
	Hm.title.onclick = null;
	Hm.bigTim.onclick = null;
	Hm.footer.style.visibility = "visible";

	Hm.content.style.right = "150%";
	Hm.content.style.visibility = "visible";
	setTimeout("bv_homeContentDash()", 750)

	Hm.title.style.right = "376px";
	Hm.title.style.visibility = "visible";
	bv_homeTitleDash();

	Hm.header.style.top = "-100px";
	Hm.header.style.visibility = "visible";
	setTimeout("bv_homeHeaderDescend()", 1250);

}

function bv_homeClickablesInit() {
	Hm.title.onclick = bv_swipeFade;
	Hm.bigTim.onclick = bv_swipeFade;
}

var bv_homeTimer = null;
function bv_animHome() {
	var Wait = 1500; // 3 seconds default after page load
	if (document.cookie.match(/\bskipIntro=true\b/i))
		Wait = 25;
	document.cookie = "skipIntro=true";
	bv_homeTimer = setTimeout('bv_swipeFade();', Wait);
}
bv_addListener(window, 'load', bv_animHome);





function bv_scrollNewsUp() {
	bv_scrollNewsTo(Hm.news.currScroll +1);
}
function bv_scrollNewsDown() {
	bv_scrollNewsTo(Hm.news.currScroll -1);
}
function bv_scrollNewsTo(Row) {
	Hm.control.firstChild.style.visibility = "inherit";
	Hm.control.lastChild.style.visibility  = "inherit";
	if (Row <= 0) {
		Row = 0;
		Hm.control.firstChild.style.visibility = "hidden";
	} else if (Row >= Hm.news.maxScroll) {
		Row = Hm.news.maxScroll;
		Hm.control.lastChild.style.visibility = "hidden";
	}
	Hm.news.currScroll = Row;
	bv_scrollNews();
}

function bv_scrollNews() {
	if (Hm.news.timer) clearTimeout(Hm.news.timer);
	var Dest   = -1 * Hm.news.currScroll * Hm.news.scrollIncrement;
	var Top    = parseInt(Hm.news.style.top);
	var Dist   = Math.abs(Dest - Top);
	var Diff   = Dest - Top;
	if (Dist > 1) {
		Top += Math.ceil(0.25* Diff);
		var AtDest = false;
	} else {
		Top = Dest;
		var AtDest = true;
	}
	Hm.news.style.top = Top +"px";
	if (!AtDest) Hm.news.timer = setTimeout("bv_scrollNews()", 15);
}

function bv_homeScrollerInit() {
	Hm.news.timer = null;
	Hm.news.style.top = "0px";
	Hm.news.scrollIncrement = 150;
	Hm.news.currScroll = 0;
	Hm.news.maxScroll = Math.ceil(parseInt(Hm.news.offsetHeight) - parseInt(Hm.content.offsetHeight)) / Hm.news.scrollIncrement;
	Hm.news.down = bv_scrollNewsDown;
	Hm.news.up = bv_scrollNewsUp;
	Hm.control.firstChild.onclick = Hm.news.down;
	Hm.control.lastChild.onclick = Hm.news.up;
	bv_scrollNewsTo(Hm.news.currScroll);
}

