var smartswap = { // quickly hacked together by Y.Tal in 2010
	SMARTWORK: [
///////// Start of artwork list ////////

// Use the following line as a template removing the "//" in front,
// or copy the first "actual" entry and insert the copy above "itself".
// If you do , MIND THE COMA PLACEMENTS! (see comments)

//	{ image:'', url:'', text:''},

	// This is the artwork by XYZ...
	{ // First required line of entry
		image:'http://afrofuturism.net/wp-content/uploads/2010/06/masthead_secondlife.jpg',		 // <- mind the comma
		url:'http://afrofuturism.net/2010/06/02/nettrice-gaskins-afrofuturist-artist/',
		text:'Nettrice Gaskins - banner artwork'										 // <- mind the no-comma before the '}'
	}, // Last required line of entry. Mind the comma!

	// You could write a comment line above each entry. This one is the original "your art goes here."
	{
		image:'http://afrofuturism.net/wp-content/themes/asusena/images/masthead.png ',
		url:'http://afrofuturism.net/',
		text:"Your artwork can go here!" 
	} // <- mind NO comma after last entry!

///////// End of artwork list ////////
],
	show_for: 4.0,   // How long does one image stay on screen?
	transit_for: 1.0, // How many seconds does the transition between two images take? 

	fps: 25,          // animation speed (per second). The lower, the less CPU use.
	opacity: 0,
	// Transition script variables
	at_id: 1,
	// All things that will be initialized later.
	fade_element: 0,
	transiting: null,
	delay: null,
	delta: null,
	idx: 0,
	current_link: null,
	nextLink: function() { with(smartswap) { idx = (idx+1)%2; return SMARTWORK[idx]; } },
	anyLinkExcept: function(image) {
		with(smartswap) {
			var art=smartswap.SMARTWORK;
			idx = Math.floor(Math.random()*art.length);
			if (art[idx].image == image) { // make sure we don't return the image that was given to us.
				idx = (idx+1) % art.length;
			}
			return art[idx];
		}
	},
	swap_link: function(where, forWhat) {
		document.getElementById("smArtLink").href=forWhat.url;
		where.title = forWhat.text;
		where.alt   = forWhat.text;
		if (smartswap.fade_element) {
			smartswap.fade_element.title = forWhat.text;
			smartswap.fade_element.alt   = forWhat.text;
		}
	},
	do_transit: function() {
		with(smartswap) {
			opacity += delta;
			if (opacity >= 1 || opacity <= 0) {
				opacity = opacity >= 1 ? 1 : 0;
				if (transiting) {
					clearInterval(transiting);
					transiting=0.0;
					delta = -delta;
					end_transit();
				}
			}
			fade_element.style.opacity = opacity;
			fade_element.style.filter = "alpha(opacity="+(opacity*100)+")";
		}
	},
	end_transit: function() {
		with(smartswap) {
			at_id = (at_id+1)%2; // 1=>0 and 0=>1
			var whichElement = document.getElementById("smArt"+at_id);
//			swap_link(whichElement, anyLinkExcept(whichElement.src));
			swap_link(fade_element, current_link); // exchange the text and link on the appeared element
			current_link = nextLink();
			whichElement.src   = current_link.image; // prepare next transition, so that image gets to load in the background
			setTimeout(start_transit, show_for*1000);
		}
	},
	start_transit: function() {
		with(smartswap) {
			smartswap.transiting = setInterval(do_transit, delay*1000);
		}
	},
	init: function() {
		with (smartswap) {
			delay = 1.0 / fps;
			delta = 1.0 / (fps*transit_for);
			current_link = nextLink();
			var linkElement = document.getElementById("smArtLink");
			if (linkElement) {
				var img = document.createElement("img");
				img.id = "smArt1";
				img.src = current_link.image;
				img.className = "smArtSwapImg";
				img.zIndex="2";
				img.border="0";
				swap_link(img, current_link);
				linkElement.appendChild(img);
				fade_element=img;
			} else {
				fade_element = document.getElementById("smArt1");
				fade_element.src = current_link.image;
			}
			setTimeout(start_transit, show_for*1000);
		}
	}
};
if (typeof window.onload == "function") {
	window.onload = function(chain){
		return function() { smartswap.init(); chain.call(window); }
	}(window.onload);
} else {
	window.onload = smartswap.init;
}


