// FPC Splash
//
// Built from parts of other javascript examples

function change_splash(data)
{
	var selected;
	if( data == null )
	{
		var rand = Math.floor( Math.random() * splashContent.length ) ;
		selected = convert[rand];
	}
	else
		selected = data.title;
	
	if( document.getElementById )
	{
		opacity( 'splash_top', 100, 0, 1 );
		//change splash text
		//childNodes[2] = first <p> && childNodes[3] = second <p>
		var featureStory = document.getElementById( 'feature_story' );
		//alert( featureStory.childNodes.length );
		if( featureStory.childNodes.length == 11 )
		{
			featureStory.childNodes[5].innerHTML = splashContent[selected]["text1"];
			featureStory.childNodes[7].innerHTML = splashContent[selected]["text2"];
			
			//change the full story link
			var storyLink = featureStory.childNodes[9].childNodes[0];
			storyLink.setAttribute("href", splashContent[selected]["link"]);
			storyLink.innerHTML = splashContent[selected]["link-text"];
		}
		else if( featureStory.childNodes.length == 5 )
		{
			featureStory.childNodes[2].innerHTML = splashContent[selected]["text1"];
			featureStory.childNodes[3].innerHTML = splashContent[selected]["text2"];
			
			//change the full story link
			var storyLink = featureStory.childNodes[4].childNodes[0];
			storyLink.setAttribute("href", splashContent[selected]["link"]);
			storyLink.innerHTML = splashContent[selected]["link-text"];
		}

		//change the splash image
		document.getElementById( 'featureimage' ).childNodes[0].src = splashContent[selected]["image"];
		
		opacity( 'splash_top', 0, 100, 500 );
		
		//change the selected tab
		var tabs = document.getElementById( 'splashtab' );
		for( var i = 0; i < tabs.childNodes.length; i++ )
		{
			if( tabs.childNodes[i].nodeName != "#text" )
			{
				if( tabs.childNodes[i].childNodes[0].title == selected )
					tabs.childNodes[i].className = "selected";
				else
					tabs.childNodes[i].className = "";
			}
		}
		
		return false;
	}
	else
	{
		return true;
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}
