/* home functions */
var blipTimeout = new Array(null, null, null);
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

function toggleRO_blip(blipObj)
{
	blipList = blipObj.parentNode.parentNode.parentNode.getElementsByTagName('div');
	for(i=0; i<blipList.length; i++)
	{
		blipList[i].style.display = "none";
		blipTimeout[i] = null;
	}
	blipObj.parentNode.parentNode.getElementsByTagName('div')[0].style.display = "";
}

function keepBlipOpen(blipObj, blipTO_num)
{
	clearTimeout(blipTimeout[blipTO_num]);
	blipObj.parentNode.style.display = "";
}

function closeBlipFrame(blipObj, blipTO_num)
{
	blipTimeout[blipTO_num] = setTimeout(function(){
		blipList = blipObj.parentNode.parentNode.parentNode.getElementsByTagName('div');
		for(i=0; i<blipList.length; i++)
			blipList[i].style.display = "none";
	}, 50);
}

/* page change animation */
var objTop, objBottom, objBottom_holder, nextLink, logoMotto, homeContact_linx;

var topMinimumHeight = 90;
var topMaximumHeight = 396;
var topClosingCount = topMaximumHeight;
var topOpeningCount = topMinimumHeight;
var topSpeed01 = 10;
var topSpeed02 = 15;
var topSpeed03 = 28;
var closingTopEaseStep01 = 110;
var closingTopEaseStep02 = 155;
var closingTopEaseStep03 = 351;
var closingTopEaseStep04 = 396;

var openingTopEaseStep01 = 135;
var openingTopEaseStep02 = 331;
var openingTopEaseStep03 = 376;
var openingTopEaseStep04 = 396;

var botMinimumHeight = 0;
var botMaximumHeight = 195;
var bottom_paddingTop = 0;
var botClosingCount = botMaximumHeight;
var botOpeningCount = botMinimumHeight;
var botSpeed01 = 5;
var botSpeed02 = 10;
var botSpeed03 = 22;
var closingBotEaseStep01 = 15;
var closingBotEaseStep02 = 35;
var closingBotEaseStep03 = 145;
var closingBotEaseStep04 = 195;
var openingBotEaseStep01 = 50;
var openingBotEaseStep02 = 160;
var openingBotEaseStep03 = 180;
var openingBotEaseStep04 = 195;

var top_curSpeed = topSpeed02;
var bot_curSpeed = botSpeed02;
var logoMotto_count = 90;

function fadeOut(linx)
{
	nextLink = linx;
	objTop = document.getElementById('homePart_top');
	objBottom = document.getElementById('homePart_bottom');
	objBottom_holder = document.getElementById('homePart_bottom_holder');
	logoMotto = document.getElementById('logoMotto_div').style;
	homeContact_linx = document.getElementById('homeContact_link').style;	

	document.getElementById('blipFrame').style.display = "none";
	document.getElementById('blipFrame').parentNode.style.backgroundImage = "url(images/home_blip_demi_bg.gif)";

	run_fadeOut();
}

function run_fadeOut()
{
	if(topClosingCount>topMinimumHeight)
	{

		topClosingCount -= top_curSpeed;
		objTop.style.height = topClosingCount+"px";
		objTop.scrollTop = objTop.scrollHeight;
		if((topClosingCount<=closingTopEaseStep04)&&(topClosingCount>closingTopEaseStep03)) top_curSpeed=topSpeed02;
		else if((topClosingCount<=closingTopEaseStep03)&&(topClosingCount>closingTopEaseStep02)) top_curSpeed=topSpeed03;
		else if((topClosingCount<=closingTopEaseStep02)&&(topClosingCount>closingTopEaseStep01)) top_curSpeed=topSpeed02;
		else if(topClosingCount<=closingTopEaseStep01) top_curSpeed=topSpeed01;

		logoMotto.opacity = (logoMotto_count / 101); 
		logoMotto.MozOpacity = (logoMotto_count / 101); 
		logoMotto.filter = "alpha(opacity=" + logoMotto_count + ")";
		homeContact_linx.opacity = (logoMotto_count / 101); 
		homeContact_linx.MozOpacity = (logoMotto_count / 101); 
		homeContact_linx.filter = "alpha(opacity=" + logoMotto_count + ")";
		if(logoMotto_count > 0)
			logoMotto_count -= 10;

		botClosingCount -= bot_curSpeed;
		bottom_paddingTop += bot_curSpeed;
		objBottom.style.height = botClosingCount+"px";	
		objBottom_holder.style.height = botClosingCount+"px";
		objBottom_holder.style.paddingTop = bottom_paddingTop+"px";
		if((botClosingCount<=closingBotEaseStep04)&&(botClosingCount>closingBotEaseStep03)) bot_curSpeed=botSpeed02;
		else if((botClosingCount<=closingBotEaseStep03)&&(botClosingCount>closingBotEaseStep02)) bot_curSpeed=botSpeed03;
		else if((botClosingCount<=closingBotEaseStep02)&&(botClosingCount>closingBotEaseStep01)) bot_curSpeed=botSpeed02;
		else if(botClosingCount<=closingBotEaseStep01) bot_curSpeed=botSpeed01;

		if((BrowserDetect.browser=='Firefox')||(is_chrome)) setTimeout("run_fadeOut()",50);
		else run_fadeOut();
	}
	else
	{
		window.location = nextLink;
	}
}

var backTo_home = readCookie('backTo_home')
if(!backTo_home) var backTo_home = false;

function initHome()
{
	if(!backTo_home)
	{
		document.getElementById('homePart_top_holder').style.display = "block";
		document.getElementById('homePart_top').scrollTop = document.getElementById('homePart_top').scrollHeight;
		document.getElementById('homePart_bottom_holder').style.display = "block";

		document.getElementById('blipFrame').style.display="block";
		document.getElementById('blipFrame').parentNode.style.background = "none";
		createCookie('backTo_home',true,0);
	}
	else
	{
		objTop = document.getElementById('homePart_top');
		objTop.style.height = topMinimumHeight+"px";
		
		objBottom = document.getElementById('homePart_bottom');
		objBottom.style.height = botMinimumHeight+"px";
		objBottom_holder = document.getElementById('homePart_bottom_holder');
		bottom_paddingTop = botMaximumHeight;
		objBottom_holder.style.paddingTop = bottom_paddingTop+"px";

		document.getElementById('homePart_top_holder').style.display = "block";
		document.getElementById('homePart_bottom_holder').style.display = "block";

		objTop.scrollTop = objTop.scrollHeight;

		logoMotto = document.getElementById('logoMotto_div').style;
		logoMotto.opacity = 0;
		logoMotto.MozOpacity = 0;
		logoMotto.filter = "alpha(opacity=0)";
		homeContact_linx = document.getElementById('homeContact_link').style;
		homeContact_linx.opacity = 0;
		homeContact_linx.MozOpacity = 0;
		homeContact_linx.filter = "alpha(opacity=0)";
		logoMotto_count = 40;
		run_fadeIn();
	}
}

function run_fadeIn()
{
	if(topOpeningCount<topMaximumHeight)
	{
		topOpeningCount += top_curSpeed;
		objTop.style.height = topOpeningCount+"px";
		objTop.scrollTop = objTop.scrollHeight;
		
		if((topOpeningCount>=openingTopEaseStep01)&&(topOpeningCount<openingTopEaseStep02)) top_curSpeed=topSpeed03;
		else if((topOpeningCount>=openingTopEaseStep02)&&(topOpeningCount<openingTopEaseStep03)) top_curSpeed=topSpeed02;
		else if((topOpeningCount>=openingTopEaseStep03)&&(topOpeningCount<openingTopEaseStep04)) top_curSpeed=topSpeed01;

		logoMotto.opacity = (logoMotto_count / 101); 
		logoMotto.MozOpacity = (logoMotto_count / 101); 
		logoMotto.filter = "alpha(opacity=" + logoMotto_count + ")";
		homeContact_linx.opacity = (logoMotto_count / 101); 
		homeContact_linx.MozOpacity = (logoMotto_count / 101); 
		homeContact_linx.filter = "alpha(opacity=" + logoMotto_count + ")";
		if(logoMotto_count <= 90)
			logoMotto_count += 10;

		botOpeningCount += bot_curSpeed;
		bottom_paddingTop -= bot_curSpeed;
		objBottom.style.height = botOpeningCount+"px";
		
		objBottom_holder.style.height = (botMaximumHeight - bottom_paddingTop)+"px";
		objBottom_holder.style.paddingTop = bottom_paddingTop+"px";

		if((botOpeningCount>=openingBotEaseStep01)&&(botOpeningCount<openingBotEaseStep02)) bot_curSpeed=botSpeed03;
		else if((botOpeningCount>=openingBotEaseStep02)&&(botOpeningCount<openingBotEaseStep03)) bot_curSpeed=botSpeed02;
		else if((botOpeningCount>=openingBotEaseStep03)&&(botOpeningCount<openingBotEaseStep04)) bot_curSpeed=botSpeed01;

		if(BrowserDetect.browser=='Firefox') setTimeout("run_fadeIn()",50);
		else setTimeout("run_fadeIn()",5);
	}
	else
	{
		topClosingCount = topMaximumHeight;
		topOpeningCount = topMinimumHeight;
		botClosingCount = botMaximumHeight;
		botOpeningCount = botMinimumHeight;
		top_curSpeed = topSpeed02;
		bot_curSpeed = botSpeed02;
		logoMotto_count = 90;
		document.getElementById('blipFrame').style.display="block";
		document.getElementById('blipFrame').parentNode.style.background = "none";
		objTop.style.height = topMaximumHeight+1+"px";
	}
}

window.onload = initHome;
window.onunload = function(){};

