// JavaScript Document


//testing functions

function alertTest() {
	
	alert("Hey this alert was called from sheldonschiffer.js");
}




//Setup global variables

//These are for SLIDE SHOW WITH FADES
var slideCount = 0; //associates the slide number to the array position

var fadeDuration = 1000; 

var theSlideShowTimer;

var fadeTriggerTimer;

var fadeOutTimer;

var fadeInTimer;

var theImages = new Array();  //Stores images


//SLIDE SHOW WITH FADES

//code by Sheldon Elias Schiffer

//January 20, 2012



slideArray(); //Pre-loads the slide array once for the whole page view

//Using Flow-Based approach, this is the control method
function slideShowMain () {
		
		//alert("slideShowMain is active.");
		
		changeSlide(); 
		
		slideCounter();
		
		fadeTriggerTimer = setTimeout("fadeOut();", 5000);
		//Even though a timer object is cconstructed from method,
		//the method is still running, and the timer is on.
		//This is length of time before fade in/out sequence
		
		slideShowTimer = setTimeout("slideShowMain();",6000);
		//total time of one slide on screen, including face
		//behavior
}

//Slide manipulation methods that associate image in <div>, to 
//images stored in array, to be loaded into <div>
function slideArray() {
	
	//alert("slideArray is active.");
	
	theImages[0] = new Image();
	theImages[0].src = "images/stills/transmigration/Transmigration-Home_Sheldon-Schiffer.png";
	theImages[1] = new Image();
	theImages[1].src = "images/stills/nailed/Nailed-Home_Sheldon-Schiffer.png";
	theImages[2] = new Image();
	theImages[2].src = "images/stills/disclosures/Disclosures-Home_Sheldon-Schiffer.png";
	theImages[3] = new Image();
	theImages[3].src = "images/stills/comeuppance/Comeuppance-Home_Sheldon-Schiffer.png";
	theImages[4] = new Image();
	theImages[4].src = "images/stills/malecon/Portraits-on-the-Malecon-Home_Sheldon-Schiffer.png";
	theImages[5] = new Image();
	theImages[5].src = "images/stills/BVF/Black-Velvet-Flag-Home_Sheldon-Schiffer.png";
	/*theImages[6] = new Image();
	theImages[6].src = "images/stills/onegative/O-Negative-Home_Sheldon-Schiffer.png";*/
	theImages[6] = new Image();
	theImages[6].src = "images/stills/MOT/Memories-of-Tata-Home_Sheldon-Schiffer.png";
		
	/*
	theImages[8] = new Image();
	theImages[8].src = "test_09.png";
	theImages[9] = new Image();
	theImages[9].src = "test_10.png";
	theImages[10] = new Image();
	theImages[10].src = "test_11.png";
	*/
	
}

function slideCounter() {
	
	slideCount++;
	
	if (slideCount >= theImages.length) {
		
		slideCount = 0;
		
	}
		
}



function changeSlide() {
	
	window.document.slideShow.src = theImages[slideCount].src;
	
}



	
//Opacity manipulation methods that effect the <div> that holds
//the images being changed and faded 
function setOpacity(newOpacity) {
	
	//alert("setOpacity is active.");
	
	var element = document.getElementById("slideShowHolder");
	//Element ID name taken from <div> on html page, be sure
	//to give this name in the id property of the <div>
	
	element.style.opacity = newOpacity;
	
	//alert("setOpacity is active.");
	
	if (newOpacity <= 0) {
		
		element.style.opacity = 0;
		
		clearTimeout(fadeOutTimer);
		
		fadeIn();
		
	}
	
}


function fadeOut() {

	//alert("fadeOut is active.");

	clearTimeout(fadeTriggerTimer);
	
	var j;

	for (i = 0; i <= 10; i += 1) {
		
		j = (10 - i)/10;
		
		fadeOutTimer = setTimeout("setOpacity(" + (1 - j) + ");", j * fadeDuration);
		//Notice that with the second j value at .9, the result is that
		//the new opacity becomes .1, but the timer will execute at
		//.9 seconds from the first iteration. (Later!) Then, at the 2nd
		//to last iteration, j is .1, so opacity will be .9, but
		//executed at .1 seconds (Earlier!). So the timers expire in
		//reverse order of their creation from the loop. Allowing a fade out.
		
		//If confused, make a chart for the iterations and time/opacity values.
		
	}
	
}

function fadeIn() {
	
	for (i = 0.01; i <= 1; i += 0.1) { // Must start i > 0 (.01)  to avoid recursive loop
		
		setTimeout("setOpacity(" + i + ");", i * fadeDuration);
		//Notice that with the second i value at .11, the result is that
		//the new opacity becomes .11, and the timer will execute at
		//.11 seconds from the first iteration. (Earlier!) Then, at the
		//last iteration, i is .91, so opacity will be .91, and
		//executed at .91 seconds (earlier). So the timers expire in
		//forward order of their creation from the loop. Allowing fade in.
		
		//If confused, make a chart for the iterations and time/opacity values
	}
	
}


//TRAILER PRESENTATION SWITCH

//code by Sheldon Elias Schiffer

//January 15, 2012


function trailerPresentationOn() {
	var ele1 = document.getElementById("trailerPresentationElement");
	
	var ele2 = document.getElementById("displayBackgroundElement");
	
		ele1.style.visibility = "visible";
		
		ele2.style.visibility = "hidden";
	
} 

function trailerPresentationOn_2() {
	var ele1 = document.getElementById("trailerPresentationElement_2");
	
	var ele2 = document.getElementById("trailerPresentationElement");
	
		ele1.style.visibility = "visible";
		
		ele2.style.visibility = "hidden";
	
} 

function trailerPresentationOff() {
	var ele1 = document.getElementById("trailerPresentationElement");
	
	var ele2 = document.getElementById("displayBackgroundElement");
	
		ele1.style.visibility = "hidden";
		
		ele2.style.visibility = "visible";
	
}


function trailerPresentationOff_2() {
	var ele1 = document.getElementById("trailerPresentationElement_2");
	
	var ele2 = document.getElementById("displayBackgroundElement");
	
		ele1.style.visibility = "hidden";
		
		ele2.style.visibility = "visible";
	
} 


//SWAPPING IMAGES ON A DIV WITH MOUSE OVER

//code by Sheldon Elias Schiffer

//January 14, 2012

//Called by html page: film_Sheldon-Schiffer.html

function swapDiv(clickedElementById) {
	
	var ele1 = document.getElementById(clickedElementById);
	
	ele1.style.visibility = "hidden";
	
	var ele2 = document.getElementById(clickedElementById + "MausOvr");
	
	ele2.style.visibility = "visible";
	
}

function swapDivBack(clickedElementById) {
	
	var ele1 = document.getElementById(clickedElementById);
	
	ele1.style.visibility = "hidden";
	
	var position = clickedElementById.indexOf("MausOvr");
	
	var eleId = clickedElementById.substring(0,position);
	
	var ele2 = document.getElementById(eleId);
	
	ele2.style.visibility = "visible";
	
}

//SENDING BROWSER TO A NEW PAGE

function gotoNextPage(url) {
	
	window.location = url;

}


