window.addEvent('domready', function() {
	
	var imageCounter = 0;
	var linkCounter = 0;
	
	var welcomeimages = $('aboutUPSWidget');
	var welcomeLinks = $('aboutLinks');	
	var imagefader = new Fx.Tween(welcomeimages);	
	var linkfader = new Fx.Tween(welcomeLinks);
	var smalllinkfader = new Fx.Tween($('swapLinks'));
	
	$('widgetLink').style.fontWeight='bold';
	
	var makenewimage = function(){		

		welcomeimages.innerHTML = images[imageCounter];
		imagefader.start('opacity','1');			
		
		if(imageCounter % images.length == 0)
			imageCounter = 1;
		else
			imageCounter = 0;	
	}
	
	var fadesmalllink = function(){		
		smalllinkfader.start('opacity','1');			
	}
	
	var makenewlink = function(){		
		welcomeLinks.empty();
		
		new Element('span', {html: urls[linkCounter]}).inject(welcomeLinks);	
		linkfader.start('opacity','1');	
		
		if(linkCounter % urls.length == 0) {
			linkCounter = 1;
			$('upsLink').style.fontWeight='bold';
			$('widgetLink').style.fontWeight='normal';
		} else {
			linkCounter = 0;
			$('upsLink').style.fontWeight='normal';
			$('widgetLink').style.fontWeight='bold';
		}

	}
	
	var fadeImage = function(){ 
		imagefader.start('opacity','0').chain(makenewimage);
		smalllinkfader.start('opacity','0').chain(fadesmalllink);
		linkfader.start('opacity','0').chain(makenewlink);
	}
		
	periodical = fadeImage.periodical(14000);
	
	$('upsLink').addEvent('click', function(e) {
		
		//$clear(periodical);
		
		welcomeimages.empty();			
		welcomeimages.innerHTML = images[0];		
		imagefader.start('opacity','1');			
		
		welcomeLinks.empty();		
		new Element('span', {html: urls[0]}).inject(welcomeLinks);	
		linkfader.start('opacity','1');		

		$('upsLink').style.fontWeight='bold';
		$('widgetLink').style.fontWeight='normal';
		
		linkCounter = 1;
		imageCounter = 1;
	});
	
	$('widgetLink').addEvent('click', function() {
		
		
		//$clear(periodical);
		
		welcomeimages.empty();			
		welcomeimages.innerHTML = images[1];		
		imagefader.start('opacity','1');			
	
		welcomeLinks.empty();		
		new Element('span', {html: urls[1]}).inject(welcomeLinks);	
		linkfader.start('opacity','1');		
	
		$('upsLink').style.fontWeight='normal';
		$('widgetLink').style.fontWeight='bold';
		
		linkCounter = 0;
		imageCounter = 0;
	});
});