var currentIndex = 1;
var myStories;







function includeStyle(file)  
{  
	var style  = document.createElement('link');  
	style.rel  = 'stylesheet';  
	style.type = 'text/css';  
	style.href = file;  
	document.getElementsByTagName('head').item(0).appendChild(style);  
}  
 









function initialize()
{
	
	
	
	
	
	includeStyle("/styles/hrsdc-rhdsc/headlineBlockJS.css");
	
	
	
	
	
	
	myStories = new countStories("story0XContainer0");

	document.getElementById('idStoryContainerWrapper').style.height = '450px';



	
	

	/* Fix Height thing here */ 
	var storyheights = new Array; 
		
	/* Walk through all of the stories and calculate the heights of the story titles */ 
	for ( var counter = 0; counter < myStories.StoryNumber.length; counter++)
	{
		/* For each story get the height for the story Title */ 
		storyheights[counter] = document.getElementById('storyTitle0' + myStories.StoryNumber[counter]).offsetHeight;
	}
	
	
	/* Walk through all of the stories and fix the caption heights */ 
	for ( var counter = 0; counter < myStories.StoryNumber.length; counter++)
	{
			
		/* Subtract the story Title Height from 150px */ 
		document.getElementById('storyCaption0' + myStories.StoryNumber[counter]).style.height = (150 - storyheights[counter]) + 'px'; 
		
		/* Set the StoryCatpion0X height */ 
		//alert(document.getElementById('storyCaption0' + myStories.StoryNumber[counter]).style.height );
	
	}
	
	for(var counter = 2; counter <= myStories.StoryNumber.length; counter++){

		hideNoEffect(counter);
		new Effect.Opacity('story0XContainer0' + myStories.StoryNumber[counter-1] , { from: 0, to: 0 , duration: 0 });
	
		
	}


	
}
	
//----------------------------------------------------------------------------

function show(featureNumber)
{
	currentIndex = featureNumber;
	new Effect.Opacity('story0XContainer0'+ myStories.StoryNumber[featureNumber-1], { from: 0, to: 1, duration: 0.5});
	showNoEffect(featureNumber);
}
		
//----------------------------------------------------------------------------

function showFast(featureNumber)
{
	currentIndex = featureNumber;
	new Effect.Opacity('story0XContainer0' + myStories.StoryNumber[featureNumber-1], { from: 0, to: 1, duration: 0.1});
	showNoEffect(featureNumber);
}
		
//----------------------------------------------------------------------------

function showNoEffect(featureNumber)
{
	currentIndex = featureNumber;
	document.getElementById('story0XContainer0' + myStories.StoryNumber[featureNumber-1]).className="displayBlock";
	//document.getElementById('btn0' + myStories.StoryNumber[featureNumber-1]).className="btnHover";		
}

//----------------------------------------------------------------------------

function hide(featureNumber)
{
	//alert(featureNumber);
	new Effect.Opacity('story0XContainer0' + myStories.StoryNumber[featureNumber-1], { from: 1, to: 0 , duration: 0.5 }); 
	setTimeout("hideNoEffect(" + featureNumber + ")",500);
}

//----------------------------------------------------------------------------

function hideFast(featureNumber)
{
	new Effect.Opacity('story0XContainer0' + myStories.StoryNumber[featureNumber-1], { from: 1, to: 0 , duration: 0.1 }); 
	setTimeout("hideNoEffect(" + featureNumber + ")",100);
}

//----------------------------------------------------------------------------

function hideNoEffect(featureNumber)
{
	
	document.getElementById('story0XContainer0'+ myStories.StoryNumber[featureNumber-1]).className="displayNone";
	//document.getElementById('btn0'+ myStories.StoryNumber[featureNumber-1]).className="btn0"+featureNumber;
}

//----------------------------------------------------------------------------

function overFeature(featureNumber)
{
	//hide previous feature
	hideFast(currentIndex);
	//check to see if we're at the end
	
	currentIndex = featureNumber;
	
	//show next feature
	setTimeout("showFast(" + currentIndex + ");",100);
}

//----------------------------------------------------------------------------

function nextFeature()
{
	//hide previous feature
	hide(currentIndex);
	//check to see if we're at the end
	if(currentIndex == myStories.StoryNumber.length){
		currentIndex = 1;
	}else{
		currentIndex = currentIndex+1;
	}
	//show next feature
	setTimeout("show(" + currentIndex + ");",500);
}

//----------------------------------------------------------------------------

function previousFeature()
{
	//hide this feature
	hide(currentIndex);
	//check to see if we're at the end
	if(currentIndex == 1){
		currentIndex = myStories.StoryNumber.length;
	}else{
		currentIndex = currentIndex-1;
	}
	//show next feature myStories.StoryNumber[0]
	setTimeout("show(" + currentIndex + ");",500);
}

//----------------------------------------------------------------------------

function nextFastFeature()
{
	//hide previous feature
	hideFast(currentIndex);
	//check to see if we're at the end
	if(currentIndex == myStories.StoryNumber.length){
		currentIndex = 1;
	}else{
		currentIndex = currentIndex+1;
	}
	//show next feature
	setTimeout("showFast(" + currentIndex + ");",100);
}

//----------------------------------------------------------------------------

function prevFastFeature()
{
	//hide this feature
	hideFast(currentIndex);
	//check to see if we're at the end
	if(currentIndex == 1){
		currentIndex = myStories.StoryNumber.length;
	}else{
		currentIndex = currentIndex-1;
	}
	//show next feature
	setTimeout("showFast(" + currentIndex + ");",100);
}

//----------------------------------------------------------------------------

function pauseAll()
{
	if (document.getElementById('pauseBtn').innerHTML == "Pause")
	{
		//pauseTimer();
		document.getElementById('pauseBtn').innerHTML = "Play";
		document.getElementById('idStoryContainerWrapper').onmouseover = "";
		document.getElementById('idStoryContainerWrapper').onmouseout = "";
	}
	else if(document.getElementById('pauseBtn').innerHTML == "Play")
	{
		//resumeTimer();
		document.getElementById('pauseBtn').innerHTML = "Pause";
		document.getElementById('idStoryContainerWrapper').onmouseover = new Function("pauseTimer();");
		document.getElementById('idStoryContainerWrapper').onmouseout = new Function("resumeTimer();");
	}



}




/*--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------*/



function rollOverMe(myId)
{
	document.getElementById(myId).style.background="url('/img/hrsdc-rhdsc/generic/rotator/btnBackgroundDarkBlueWide.jpg')";
	
}



function rollOutMe(myId)
{
	document.getElementById(myId).style.background="url('/img/hrsdc-rhdsc/generic/rotator/btnBackgroundBlueWide.jpg')";
}
