if(!window.TwoRoads) {
	alert('You must include TwoRoads.js!');
}
var Home = Class.create(TwoRoads,{
	Name : 'Home',
	Version : '1.0',
	Author : 'Matt Balogh <matt.balogh@seraphimllc.com>',
	Creation : 'Sun Jan 4 04:38:00 2009',
	initialize: function($super){
		this.portfolio = new Array();
		this.portfolioImages = new Array();
		this.intervalId = 0;
		this.imageElement;
		this.currentImage = 0;
		this.cycleCount = 0;
		this.maxCycles = 10;
		$super();
	},
	init: function($super){
		this.loadImages();
		this.startSlideShow();
		$super();
	},
	setPortfolio: function(portfolio){
		this.portfolio = portfolio;
	},
	getPortfolio: function(){
		return this.portfolio;
	},
	setPortfolioImages: function(portfolioImages){
		this.portfolioImages = portfolioImages;
	},
	getPortfolioImages: function(){
		return this.portfolioImages;
	},
	addPortfolioImage: function(portfolioImage){
		this.portfolioImages.push(portfolioImage);
	},
	setIntervalId: function(intervalId){
		this.intervalId = intervalId;
	},
	getIntervalId: function(){
		return this.intervalId;
	},
	setImageElement: function(imageElement){
		this.imageElement = imageElement;
	},
	getImageElement: function(){
		return this.imageElement;
	},
	setCurrentImage: function(currentImage){
		this.currentImage = currentImage;
	},
	getCurrentImage: function(){
		return this.currentImage;
	},
	setCycleCount: function(cycleCount){
		this.cycleCount = cycleCount;
	},
	getCycleCount: function(){
		return this.cycleCount;
	},
	setMaxCycles: function(maxCycles){
		this.maxCycles = maxCycles;
	},
	getMaxCycles: function(){
		return this.maxCycles;
	},
	loadImages: function(){
		$A(this.getPortfolio()).each(function(iHash,index){
			var tmpImg = new Image();
			tmpImg.src = iHash.url;
			tmpImg.alt = iHash.title;
			tmpImg.name = iHash.id;
			this.addPortfolioImage(tmpImg);
		}.bind(this));
	},
	startSlideShow: function(){
		this.setIntervalId(setInterval(function(){
			this.nextImage();
		}.bind(this),6000,"JavaScript"));
	},
	nextImage: function(){
		this.setCurrentImage(this.getCurrentImage()+1);
		if(this.getCurrentImage() >= this.getPortfolioImages().length){
			this.setCurrentImage(0);
			this.setCycleCount(this.getCycleCount()+1);
			if(this.getCycleCount() >= this.getMaxCycles()) {
				clearInterval(this.getIntervalId());
				this.getImageElement().border = 0;
				this.getImageElement().title = "TwoRoads Studios";
				this.getImageElement().name = "TwoRoads Studios";
				this.getImageElement().src = "/images/logo-500x461.jpg";
				$('image_title').innerHTML = '';
				return;
			}
		}
		Effect.Fade('images', {
			duration: 1.0,
			afterFinish: function(){
				this.getImageElement().border = 1;
				this.getImageElement().style.borderColor = '#DABA6A';
				this.getImageElement().title = this.getPortfolioImages()[this.getCurrentImage()].alt;
				this.getImageElement().name = this.getPortfolioImages()[this.getCurrentImage()].name;
				this.getImageElement().src = this.getPortfolioImages()[this.getCurrentImage()].src;
				$('image_title').innerHTML = this.getPortfolioImages()[this.getCurrentImage()].alt;
				Effect.Appear('images', {
					duration: 1.0
				});
			}.bind(this)
		});
	}
});
