if ( document.getElementById && document.getElementsByTagName )
{
	if ( window.addEventListener )
	{
		window.addEventListener( 'load', initAnims, false );
	}
	else
	{
		if ( window.attachEvent )
		{
			window.attachEvent( 'onload', initAnims );
		}
	}
}

function initAnims()
{
    var animElements = document.getElementById( "end" );

    animElements.onmouseover = fadeColMem;
    animElements.onmouseout = fadeColRestore;

    function fadeColMem()
	{
		if ( !this.currentbgRGB && !this.currentfgRGB ) 
		{
			this.currentbgRGB = [255,255,255];
			this.currentfgRGB = [229,229,229];
		}

		doFadeMem( this, this.currentbgRGB, [229,229,229], this.currentfgRGB, [255,255,255], 6, 75, 1 );
    }
    
    function fadeColRestore()
	{
		if ( !this.currentbgRGB && !this.currentfgRGB )
			return;

		doFadeMem( this, this.currentbgRGB, [255,255,255], this.currentfgRGB, [229,229,229], 6, 75, 1 );
    }

    var animBox = document.getElementById( "com" );

    animBox.onmouseover = fadeCoColMem;
    animBox.onmouseout = fadeCoColRestore;
    animBox.onclick = contact_mail;

	function contact_mail()
	{
		location.href='mailto:contact@blucipmedia.com?subject=Info';
	}

    function fadeCoColMem()
	{
		if ( !this.currentbgRGB && !this.currentfgRGB && !this.currentCobgRGB ) 
		{
			this.currentbgRGB = [255,255,255];
			this.currentfgRGB = [229,229,229];
			this.currentCobgRGB = [255,255,255];
			this.currentCofgRGB = [255,255,255];
		}
		this.style.cursor = 'pointer';
		doFadeBothMem( this, document.getElementById( "end" ), this.currentbgRGB, [229,229,229], this.currentfgRGB, [255,255,255], this.currentCobgRGB, [229,229,229], this.currentCofgRGB, [209, 209, 209], 6, 75, 1 );
    }
    
    function fadeCoColRestore()
	{
		if ( !this.currentbgRGB && !this.currentfgRGB && !this.currentCobgRGB )
			return;
		this.style.cursor = 'default';
		doFadeBothMem( this, document.getElementById( "end" ), this.currentbgRGB, [255,255,255], this.currentfgRGB, [229,229,229], this.currentCobgRGB, [255,255,255], this.currentCofgRGB, [255, 255, 255], 6, 75, 1 );
    }
}

function doFadeMem( elem, startbgRGB, endbgRGB, startfgRGB, endfgRGB, steps, intervals, powr )
{
	var actStep = 0;
	if ( elem.fadeMemInt )
	{
		window.clearInterval( elem.fadeMemInt );
	}
var elem2 = document.getElementById( "logo" );
	elem.fadeMemInt = window.setInterval(
		function()
		{
			elem.currentbgRGB = [
				easeInOut(startbgRGB[0],endbgRGB[0],steps,actStep,powr),
				easeInOut(startbgRGB[1],endbgRGB[1],steps,actStep,powr),
				easeInOut(startbgRGB[2],endbgRGB[2],steps,actStep,powr)
				];
			elem.currentfgRGB = [
				easeInOut(startfgRGB[0],endfgRGB[0],steps,actStep,powr),
				easeInOut(startfgRGB[1],endfgRGB[1],steps,actStep,powr),
				easeInOut(startfgRGB[2],endfgRGB[2],steps,actStep,powr)
				];
			elem.style.backgroundColor = "rgb("+
				elem.currentbgRGB[0]+","+
				elem.currentbgRGB[1]+","+
				elem.currentbgRGB[2]+")";
			elem.style.color = "rgb("+
				elem.currentfgRGB[0]+","+
				elem.currentfgRGB[1]+","+
				elem.currentfgRGB[2]+")";
elem2.style.color  = "rgb("+
				elem.currentbgRGB[0]+","+
				elem.currentbgRGB[1]+","+
				elem.currentbgRGB[2]+")";
			actStep++;
			if ( actStep > steps )
			{
				window.clearInterval( elem.fadeMemInt );
			}
		}
		, intervals )
}

function doFadeBothMem( elem1, elem2, startbg2RGB, endbg2RGB, startfg2RGB, endfg2RGB, startbg1RGB, endbg1RGB, startfg1RGB, endfg1RGB, steps, intervals, powr)
{
	var actStep = 0;
	if ( elem1.fadeMemInt )
	{
		window.clearInterval( elem1.fadeMemInt );
	}
var elem3 = document.getElementById( "logo" );
	elem1.fadeMemInt = window.setInterval(
		function()
		{
			elem1.currentCobgRGB = [
				easeInOut(startbg1RGB[0],endbg1RGB[0],steps,actStep,powr),
				easeInOut(startbg1RGB[1],endbg1RGB[1],steps,actStep,powr),
				easeInOut(startbg1RGB[2],endbg1RGB[2],steps,actStep,powr)
				];
			elem1.currentCofgRGB = [
				easeInOut(startfg1RGB[0],endfg1RGB[0],steps,actStep,powr),
				easeInOut(startfg1RGB[1],endfg1RGB[1],steps,actStep,powr),
				easeInOut(startfg1RGB[2],endfg1RGB[2],steps,actStep,powr)
				];
			elem1.currentbgRGB = [
				easeInOut(startbg2RGB[0],endbg2RGB[0],steps,actStep,powr),
				easeInOut(startbg2RGB[1],endbg2RGB[1],steps,actStep,powr),
				easeInOut(startbg2RGB[2],endbg2RGB[2],steps,actStep,powr)
				];
			elem1.currentfgRGB = [
				easeInOut(startfg2RGB[0],endfg2RGB[0],steps,actStep,powr),
				easeInOut(startfg2RGB[1],endfg2RGB[1],steps,actStep,powr),
				easeInOut(startfg2RGB[2],endfg2RGB[2],steps,actStep,powr)
				];
			elem1.style.backgroundColor = "rgb("+
				elem1.currentCobgRGB[0]+","+
				elem1.currentCobgRGB[1]+","+
				elem1.currentCobgRGB[2]+")";
			elem3.style.color = "rgb("+
				elem1.currentCofgRGB[0]+","+
				elem1.currentCofgRGB[1]+","+
				elem1.currentCofgRGB[2]+")";
			elem2.style.backgroundColor = "rgb("+
				elem1.currentbgRGB[0]+","+
				elem1.currentbgRGB[1]+","+
				elem1.currentbgRGB[2]+")";
			elem2.style.color = "rgb("+
				elem1.currentfgRGB[0]+","+
				elem1.currentfgRGB[1]+","+
				elem1.currentfgRGB[2]+")";
			actStep++;
			if ( actStep > steps )
			{
				window.clearInterval( elem1.fadeMemInt );
			}
		}
		, intervals )
}

function easeInOut( minValue, maxValue, totalSteps, actualStep, powr )
{
	var delta = maxValue - minValue;
	var stepp = minValue + ( Math.pow( ( ( 1 / totalSteps ) * actualStep ), powr ) * delta );
	return Math.ceil( stepp );
}

