	
	var timer = 0;
	var canvas;
	var crossfade;
	var transition_duration = 2000;

	var path = 'http://www.designclassics.co.uk/skin1/images/new/promos/';
	var url_path = 'http://www.designclassics.co.uk/search.php?mode=search&by_title=Y&by_shortdescr=Y&including=all&substring=';
	// Paths contains the full url to the rotator images
	var paths = [
		path + '1_arne_jacobsen.jpg',
		path + '2_isamu_noguchi.jpg',
        path + '3_marcel_breuer.jpg',
		path + '4_eileen_gray.jpg',
        path + '5_charles_eames_living.jpg',
		path + '6_mies_van_der_rohe.jpg',
        path + '7_charles_eames_office.jpg',
		path + '8_florence_knoll.jpg',
        path + '9_le_corbusier.jpg',
		path + '10_mies_van_der_rohe_2.jpg',
		path + '11_charles_eames_dining.jpg'
	];
	// urls contains the link for each image (to the search page)
var urls = [
		url_path + 'arne jacobsen',
		url_path + 'isamu noguchi',
        url_path + 'marcel breuer',
		url_path + 'eileen gray',
        url_path + 'charles eames',
		url_path + 'mies van der rohe',
        url_path + 'charles eames',
		url_path + 'florence knoll',
        url_path + 'le corbusier',
		url_path + 'mies van der rohe',
        url_path + 'charles eames'
	];

	window.addEvent('load', function(){
		
		var loadedImages = [];
		var links = [];
		
		canvas = $('crossfade_canvas');
		// Start preloading all images

		new Asset.images(paths,{
			
			onProgress: function() {
				if (!loadedImages.contains(this)) {		
					// Store the image inside the loadedImages array
					loadedImages[loadedImages.length] = this;
					// Create a new link
					var a = new Element('a',{
						href	:	urls[loadedImages.length - 1],
						styles	:	{
							'position'	:	'absolute',
							'display'	:	'block',
							'width'		:	'567px',
							'height'	:	'529px',
							'z-index'	:	1000 - loadedImages.length
						}
					});
					this.injectInside(a);
					// ...and inject the final link + img to the crossdade_canvas
					a.injectInside(canvas);
					// Keep a note of the newly injected link
					links[links.length] = a;
				}
			},
			
			onComplete: function(){
				//console.log(loadedImages);
				//console.log(loadedImages.length);
				crossfade = function() {
					// Reset all opacities to 100
					$$('#crossfade_canvas a').setStyles({'opacity':1});
					timer = 0;
					links.each(function(current_link, i) {
												
						timer += transition_duration;
						
						fx = function() {
							if (i == links.length - 1) {
								links[0].effect('opacity',{duration:transition_duration}).start(0,1).chain(function(){
									crossfade();
								});
							} else {
								current_link.effect('opacity',{duration:transition_duration}).start(1,0);
							}
						}.delay(timer * 3);

					});			
				}
				crossfade.delay(500);
			}
			
		});

	});
