var iInitialInterval = 2000; // milliseconds
var iLoopInterval    = 10000; // milliseconds
var iFadeInterval    = 1500; // milliseconds
var iOpacityVisible  = 100;
var iOpacityHidden   = 0;
var bDirection       = false;
var sTitleID         = "PageTitleDiv";
var sElement1A       = "TitlePrefixSpan";
var sElement1B       = "TitleDotSpan";
var sElement2        = "TitleSuffixSpan";


function gotoHref ( endcodedValue )
{
  var decodedValue = "";

  for ( var i = 0; i < endcodedValue.length; i += 2 )
  {
    var letter = "";
    letter = endcodedValue.charAt( i ) + endcodedValue.charAt( i + 1 )
    decodedValue += String.fromCharCode( parseInt( letter, 16 ) );
  }
  
  location.href = decodedValue;
}


function window_onload ()
{
	overrideDoPostBack();
	
	if ( document.getElementById( "Error" ) != null )
	{
		document.location.href = "#Error";
	}
	else
	{
		scrollToCoordinates();
	}
	
	if ( window.page && window.page == "Home" )
	{
		var oTitle = document.getElementById( sTitleID );
		oTitle.innerHTML = '<span id="' + sElement1A + '" class="homeTitle" style="opacity: 100; -moz-opacity: 100; filter: alpha(opacity=100);">www.</span><span class="homeTitle">After-Death</span><span id="' + sElement1B + '" class="homeTitle" style="opacity: 100; -moz-opacity: 100; filter: alpha(opacity=100);">.</span><span class="homeTitle">Com</span><span id="'+ sElement2 + '" class="homeTitle" style="opacity: 0; -moz-opacity: 0; filter: alpha(opacity=0);">munication</span>';
		setTimeout(  "processOpacity()", iInitialInterval );
		setInterval( "processOpacity()", iLoopInterval );
	}
	
	if ( document.forms && document.forms.length > 0 && document.forms[ 0 ] )
	{
		document.forms[ 0 ].onsubmit = form_onsubmit;
	}
}

function form_onsubmit ()
{
	var oShell = document.getElementById( "Shell" );
	//var oProcessing = document.getElementById( "Processing" );
	
	//if ( oShell && oProcessing )
	if ( oShell )
	{
		oShell.style.display = "none";
		//oProcessing.style.display = "inline-block";
	}
	
	return true;
}


function overrideDoPostBack ()
{
	if ( ( typeof( __doPostBack ) != "undefined" ) )
	{
		__doNetPostBack = __doPostBack;
		__doPostBack    = __doADCPostBack;
	}
}


function __doNetPostBack( eventTarget, eventArgument ) 
{

}


function __doADCPostBack ( eventTarget, eventArgument )
{
	updateScrollCoordinates();
	form_onsubmit();
	__doNetPostBack( eventTarget, eventArgument );
}


function updateScrollCoordinates ()
{
	var oScrollLeft = document.getElementById( "ScrollLeft" );
	var oScrollTop  = document.getElementById( "ScrollTop" );
	
	if ( oScrollLeft && oScrollTop )
	{
		var x = 0;
		var y = 0;
		
		if ( typeof( window.pageYOffset ) == 'number' )
		{
			y = window.pageYOffset;
			x = window.pageXOffset;
		}
		else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			y = document.body.scrollTop;
			x = document.body.scrollLeft;
		}
		else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			y = document.documentElement.scrollTop;
			x = document.documentElement.scrollLeft;
		}
  	
		oScrollLeft.value = x;
		oScrollTop.value  = y;
	}
}


function scrollToCoordinates ()
{
	var oScrollLeft = document.getElementById( "ScrollLeft" );
	var oScrollTop  = document.getElementById( "ScrollTop" );

	if ( oScrollLeft && oScrollTop && oScrollLeft.value != "" && oScrollTop.value != "" )
	{
		var x = parseInt( oScrollLeft.value, 10 );
		var y = parseInt( oScrollTop.value,  10 );
		
		scrollTo( x, y );
	}
}


function processOpacity ()
{
	var iTimer, iSpeed, i;
	
	iTimer = 0;
	iSpeed = Math.round( iFadeInterval / 100 );

	for ( i = iOpacityHidden; i <= iOpacityVisible; i++ )
	{
		if ( bDirection )
		{
			setTimeout( "swapOpacity( " + ( i ) + " )", ( iTimer * iSpeed ) );
		}
		else
		{
			setTimeout( "swapOpacity( " + ( iOpacityVisible - i ) + " )", ( iTimer * iSpeed ) );
		}

		iTimer++;
	}

	bDirection = !bDirection;
}


function swapOpacity ( iOpacity )
{
	var oElement1A, oElement1B, oElement2;
	
	oElement1A = document.getElementById( sElement1A );
	oElement1B = document.getElementById( sElement1B );
	oElement2  = document.getElementById( sElement2 );
	
	updateOpacity( oElement1A, iOpacity );
	updateOpacity( oElement1B, iOpacity );
	updateOpacity( oElement2, ( iOpacityVisible - iOpacity ) );
}


function updateOpacity ( oElement, iOpacity )
{
	oElement.style.opacity      = ( iOpacity / 100 );
	oElement.style.MozOpacity   = ( iOpacity / 100 );
	oElement.style.KhtmlOpacity = ( iOpacity / 100 );
	oElement.style.filter       = "alpha(opacity=" + iOpacity + ")";
}


function launchJukebox ()
{
	window.open( sRootPath + "/Pages/Jukebox.aspx", "jukebox", "menubar=no,status=no,location=no,width=400,height=150,toolbar=no,scrollbars=no" );
}



window.onload = window_onload; 



