//SOME VARIABLES WE NEED
var paused;
var t;
var story;
var mpy=10;
var cos;

//START ALL OUR PROCESSES
window.onload = initiation();

function initiation() 
{
	pic1= new Image(15,50); 
	pic1.src="right_folder.png"; 
	pic2= new Image(15,50); 
	pic2.src="left_folder.png"; 
	t=setTimeout("StoryBoxTransition(1)",3000);
	setTimeout("RectifyHeight()",3000);
}





//Rectify Footer Height
function RectifyHeight() {
	var htmlheight = document.getElementById("thebody").offsetHeight;
	var additionalpx = htmlheight-(document.getElementById("footer").offsetTop - 75);
	document.getElementById("footer").style.height = additionalpx+"px";
}






// TRANSITION THE STORY BOXES ON THE FRONT PAGE OF THE WEBSITE
function StoryBoxTransition(i) {
//	alert('This is working '+i);


	if (i==null) {	
		i=1; 
	}


	story = "story"+i;
	var storybutton = "storybutton"+i;

	document.getElementById("storybox").innerHTML=document.getElementById(story).innerHTML;

	document.getElementById("storybox").style.opacity = 0;
	document.getElementById("storybox").style.filter = 'alpha(opacity=0)';

	for (var y=1;y<11;y++) {
		setTimeout('setOpacity('+y+')',100*y);
		if (y==10) {
				if (i==5) {		
		//			t=setTimeout("StoryBoxTransition(1)",5000);
					setTimeout("easetransition(1)",6000);
				} else {
					var x = i+1;
		//			t=setTimeout("StoryBoxTransition("+x+")",5000);
					setTimeout("easetransition("+x+")",6000);
				}
		}

	}
}



// SET OPACITY FOR FADED TRANSITIONS

	function setOpacity(value) {
		document.getElementById("storybox").style.opacity = value/10;
		//alert(document.getElementById('storybox').style.opacity);
		document.getElementById("storybox").style.filter = 'alpha(opacity=' + value*10 + ')';
	}




// SET FADE OUT FOR TRANSITIONS

	function setFade(value) {
		document.getElementById("storybox").style.filter = 'alpha(opacity=' + value*10 + ')';
	}


// FADE OUT
function fadeout(value,thei) {
	value=mpy;
	mpy=mpy-1;
	setOpacity(value);
	//alert(mpy+" | v: " +value);
			if (mpy==-1) {
				mpy=10;
				clearInterval(cos);
				StoryBoxTransition(thei);
			}
}



// EASE TRANSITION
	function easetransition(value2) {
			cos = setInterval("fadeout("+mpy+","+value2+")",mpy*10);
	}

// PAUSE STORY BOXES
function PauseStoryBoxTransition(i) {
	paused="yes";
	clearTimeout(t);
	StoryBoxTransition(i)
}