/*----SLIDE VIEWER Script----*/
/*----Copyright 2010. Jeremy Sosnick----*/
var m = 0;
var c = 0;
var id1 = null;
var id2 = null;
var id3 = null;
var id4 = null;
var id5 = null;
var id6 = null;
var id7 = null;
var id8 = null;
var id9 = null;
var p = 0;
var sl = 0;
var sr = 0;
var bs = 0;
var be = 0;
var fo = 10;
var fi = 0;
var moving = false;
var l = 0;
var w = 1;
var t = 0;
var captionText1 = "<span class='caption_title'>Welcome to Timestop Productions</span><br /><p class='caption_small'>We are an independent production company specializing in animation, photography, preproduction, and other multimedia services.</p><p class='caption_small'>Our goal is to provide the means for companies to bring their creative ideas to a reality.</p><p class='caption_small'>Have a great new project idea? Contact us today!</p>"
var captionText2 = "<span class='caption_title'>3D Animation</span> - <span class='smaller_caption'>\"San Francisco Junior Giants\"</span>";
var captionText3 = "<span class='caption_title'>Music Video</span> - \"Save Your Love\"";
var captionText4 = "<span class='caption_title'>Photography</span> - \"Alaska Icescapes\"";
var captionText5 = "<span class='caption_title'>Character Design</span> - \"Hostages\"";
var captionText6 = "<span class='caption_title'>Storyboards</span> - \"Gregorgan\"";

function preloadImages(urls){
 var img = new Array();
 for (var i=0; i<urls.length; i++) {
 img[img.length] = new Image();
 img[img.length - 1].src = urls[i]; 
 }
}

function StartSequences(){
var img = new Array("button_images/about_button_hover.png", "button_images/home_button_hover.png", "button_images/projects_button_hover.png", "button_images/events_button_hover.png", "button_images/shop_button_hover.png", "button_images/contact_button_hover.png", "button_images/leftarrow_red.png", "button_images/leftarrow_green.png", "button_images/rightarrow_red.png", "button_images/rightarrow_green.png", "slider_images/slider_welcome.jpg", "slider_images/slider_giants1.jpg", "slider_images/slider_concept1.jpg", "slider_images/slider_unni1.jpg", "slider_images/slider_uriah1.jpg", "slider_images/slider_soz1");
preloadImages(img);
window.scrollTo(95, 0);
setupCinema();
}

function ChangePic(name, url){
if (document.images[name]){
	document.images[name].src = url;
}
}

function setupFadeInCap(){
id9 = window.setInterval("FadeInCap()",10);
}

function setupFadeOutCap(){
id8 = window.setInterval("FadeOutCap()",10);
}

function setupBackToEnd(){
id7 = window.setInterval("BackToEnd()",10);
}

function setupScootRight(){
id6 = window.setInterval("ScootRight()",10);
}

function setupMoveLeft(){
id5 = window.setInterval("MoveLeft()",10);
}

function setupBackToStart(){
id4 = window.setInterval("BackToStart()",10);
}

function setupScootLeft(){
id3 = window.setInterval("ScootLeft()",10);
}

function setupMove(){
id2 = window.setInterval("Move()",10);
}

function setupCinema(){
id1 = window.setInterval("Cinema()",10);
}

function Cinema(){
	c++;
	if (c == 1)
	{var view = document.getElementById("lrslider");
	view.style.left = "0px";
	id4 = null;
	id3 = null;}
	if (c == 565)
	{setupFadeOutCap();}
	if (c == 600)
	{i = 0;
	setupMove();}
	if (c == 1165)
	{setupFadeOutCap();}
	if (c == 1190)
	{id2 = null;}
	if (c == 1200)
	{i = 0;
	setupMove();}
	if (c == 1765)
	{setupFadeOutCap();}
	if (c == 1790)
	{id2 = null;}
	if (c == 1800)
	{i = 0;
	setupMove();}
	if (c == 2365)
	{setupFadeOutCap();}
	if (c == 2390)
	{id2 = null;}
	if (c == 2400)
	{i = 1;
	setupMove();}
	if (c == 2965)
	{setupFadeOutCap();}
	if (c == 2990)
	{id2 = null;}
	if (c == 3000)
	{i = 0;
	setupMove();}
	if (c == 3565)
	{setupFadeOutCap();}
	if (c == 3590)
	{id2 = null;
	w = w - 1;}
	if (c == 3600)
	{i = 0;
	sl = 0;
	bs = 0;
	setupScootLeft();}
}

function RightArr(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	if (moving == false && c>1 && c<599)
	{i = 0;
	setupFadeOutCap();
	setupMove();
	c = 600;}
	else if (moving == false && c>602 && c<1199)
	{i = 0;
	setupFadeOutCap();
	setupMove();
	c = 1200;}
	else if (moving == false && c>1202 && c<1799)
	{i = 0;
	setupFadeOutCap();
	setupMove();
	c = 1800;}
	else if (moving == false && c>1802 && c<2399)
	{i = 0;
	setupFadeOutCap();
	setupMove();
	c = 2400;}
	else if (moving == false && c>2402 && c<2999)
	{i = 0;
	setupFadeOutCap();
	setupMove();
	c = 3000;}
	else if (moving == false && c>3002 && c<3499)
	{i = 0;
	sl = 0;
	bs = 0;
	setupScootLeft();}
}

function LeftArr(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	if (moving == false && c>0 && c<599)
	{l = 0;
	sr = 0;
	be = 0;
	setupScootRight();}
	else if (moving == false && c>602 && c<1199)
	{l = 0;
	setupFadeOutCap();
	setupMoveLeft();
	c = 1;}
	else if (moving == false && c>1202 && c<1799)
	{l = 0;
	setupFadeOutCap();
	setupMoveLeft();
	c = 600;}
	else if (moving == false && c>1802 && c<2399)
	{l = 0;
	setupFadeOutCap();
	setupMoveLeft();
	c = 1200;}
	else if (moving == false && c>2402 && c<2999)
	{l = 0;
	setupFadeOutCap();
	setupMoveLeft();
	c = 1800;}
	else if (moving == false && c>3002 && c<3599)
	{l = 0;
	setupFadeOutCap();
	setupMoveLeft();
	c = 2400;}
}


function setPosition(value){
	document.getElementById("lrslider").style.left = value + "px";
}

function setOpacity(value) {
	document.getElementById("caption_box").style.opacity = value/10;
	document.getElementById("caption_box").style.filter = 'alpha(opacity=' + value*10 + ')';
}

function ChangeText(){
	if (w == 0)
	{w = 6;
	ChangeText();}
	if (w == 1)
	{document.getElementById("caption_box").innerHTML = captionText1;}
	if (w == 2)
	{document.getElementById("caption_box").innerHTML = captionText2;}
	if (w == 3)
	{document.getElementById("caption_box").innerHTML = captionText3;}
	if (w == 4)
	{document.getElementById("caption_box").innerHTML = captionText4;}
	if (w == 5)
	{document.getElementById("caption_box").innerHTML = captionText5;}
	if (w == 6)
	{document.getElementById("caption_box").innerHTML = captionText6;}
	if (w == 7)
	{w = 1;
	ChangeText();}
}

function FadeOutCap(){
	fo = fo - 1.75;
	setOpacity(fo);
	moving = true;
	if (fo < 0)
	{clearInterval(id8);
	moving = false;
	fi = 0;
	w++;
	ChangeText();}
}

function FadeInCap(){
	fi = fi + .5;
	setOpacity(fi);
	moving = true;
	if (fi > 10)
	{clearInterval(id9);
	moving = false;
	fo = 10;}
}

function fadeF(){
fo = fo - .15;
setOpacityF(fo);
if (fo < 0)
{clearInterval(id2);}
}

function Move(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	i++;
	moving = true;
	p = pos - 5;
	setPosition(p);
	if (i == 87)
	{clearInterval(id2);
	setupFadeInCap();
	moving = false;
	return p;}
}

function MoveLeft(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	l++;
	moving = true;
	p = pos + 5;
	setPosition(p);
	if (l == 2)
	{w = w - 2;}
	if (l == 87)
	{clearInterval(id5);
	setupFadeInCap();
	moving = false;
	return p;}
}

function ScootRight(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	sr++;
	moving = true;
	p = pos + 1;
	setPosition(p);
	if (sr == 20)
	{clearInterval(id6);
	setupFadeOutCap();
	moving = false;
	setupBackToEnd();}
}

function ScootLeft(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	sl++;
	moving = true;
	p = pos - 1;
	setPosition(p);
	if (sl == 20)
	{clearInterval(id3);
	setupFadeOutCap();
	moving = false;
	setupBackToStart();}
}

function BackToStart(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	bs++;
	moving = true;
	p = pos + 20;
	setPosition(p);
	if (bs == 109)
	{clearInterval(id4);
	clearInterval(id1);
	moving = false;
	setupFadeInCap();
	id1 = null;
	c = 0;
	setupCinema();
	return p;}
}

function BackToEnd(){
	var view = document.getElementById("lrslider");
	var pos = parseInt(view.style.left);
	be++;
	moving = true;
	p = pos - 20;
	setPosition(p);
	if (be == 2)
	{w = w - 2;}
	if (be == 110)
	{clearInterval(id7);
	clearInterval(id1);
	moving = false;
	setupFadeInCap();
	id1 = null;
	c = 3001;
	setupCinema();
	return p;}
}

function ChangePage(page){
	location.href = page;
}