﻿function Technology(_title, _url, _logoUrl)
{
	this.title = _title;
	this.url = _url;
	this.logoUrl = _logoUrl
}

function TechnologySpotlight()
{
	var TRANSITION_TIMER_LABEL = "TechnologySpotlightTransition",
		FADE_SPEED = 1000;

	// define the speed of the transition, the technologies used, and the current index
	var transitionSpeed = 20000,
		technologies = new Array(),
		currentIndex = 0;
		
	var anchor = $('#technologySpotlight a'),
		logo = $('img', anchor);
	
	// sets the transition speed
	this.setTransitionSpeed = function(speed)
	{
		if (isNaN(speed) || speed <= 0 || speed <= FADE_SPEED) return;
		transitionSpeed = speed;
	}
	
	// adds a technology to the list
	this.addTechnology = function(_title, _url, _logoUrl)
	{
		technologies.push(new Technology(_title, _url, _logoUrl));
	}
	
	// inits the control
	function init()
	{
		// if there is only 1 technology or less, do nothing
		if (technologies.length <= 1) return;

		// start the timer
		$(document).everyTime(transitionSpeed, TRANSITION_TIMER_LABEL, gotoNext);
	}
	
	// sets the next technology and fades in
	function gotoNext()
	{
		var currentTechnology = getNextTechnology();

		anchor.fadeOut(FADE_SPEED, function()
		{
			// set the anchor and image attributes
			anchor.attr({
				'href': currentTechnology.url,
				'title': currentTechnology.title
			});
			logo.attr('src', currentTechnology.logoUrl);

			// fade the anchor back in
			$(this).fadeIn(FADE_SPEED);
		});
	}
	
	// selects the next technology
	function getNextTechnology()
	{
		if (currentIndex >= technologies.length) currentIndex = 0;
		return technologies[currentIndex++];
	}
	
	// inits the control when the document is ready
	$(document).ready(init);
}
