/* 	Filename: fade.js
	Author: Brian Teryek
*/


function initFade()
{
	Fade.items = totalScreenShots();
	Fade.images = getImagesArray();
	addIdsToImages();
	setInterval('swapImage()', Fade.speed);
	Fade.list = "site-screen-shots";
	//getPageName();
}

var Fade = 
{
	//properties
	speed: 3000, //in milliseconds
	animationSpeed: 800,
	list: 'site-screen-shots', //id where images are located
	title: 'site-title', //id of where title is placed
	description: 'site-description', //id of where description is placed
	items: 0, //default
	count: 0,
	images: null //default
	
	//methods
	
} //end Fade object

function addIdsToImages()
{	
	for(i = 0; i < Fade.images.length; i++)
	{
		Fade.images.item(i).setAttribute('id', ''+Fade.list+i+'');
		Fade.images.item(i).setAttribute('onclick', 'window.location = \'portfolio\'');
		$(''+Fade.list+i).css({opacity: 0 });
	}
	
	$('#'+Fade.list+i+'').css({ opacity: 1 });
}

function getImagesArray()
{
	return document.getElementById(Fade.list).getElementsByTagName('img');
}

function totalScreenShots()
{
	return document.getElementById(Fade.list).getElementsByTagName('img').length;
}

function swapSiteText(image, count)
{
	document.getElementById(RecentWork.title).innerHTML = Sites.titles[count];
	document.getElementById(RecentWork.description).innerHTML = Sites.descriptions[count];
	
	
	$('#'+Fade.title).css({ opacity: .2 });
	$('#'+Fade.description).css({ opacity: .2 });
	
	$('#'+Fade.list+count).css({ opacity: 0, display:'block'});
	$('#'+Fade.list+(count - 1)).css({ opacity: 1 });
	
	$('#'+Fade.title).animate({ opacity: 1 }, Fade.animationSpeed, function() { });
	$('#'+Fade.description).animate({ opacity: 1 }, Fade.animationSpeed, function() { });
	
	$('#'+Fade.list+count).animate({ opacity: 1 }, Fade.animationSpeed, function() { });
	$('#'+Fade.list+(count - 1)).animate({ opacity: 0 }, Fade.animationSpeed, function() { });

}


function swapImage()
{
	var i;
	var image = document.getElementById(Fade.list).getElementsByTagName('img');
	
	Fade.count+= 1;
	
	if(Fade.count == Fade.items)
	{
		swapSiteText(image, Fade.count);
		Fade.count = 0;
	}
	
	swapSiteText(image, Fade.count);
}
