window.addEvent('domready', function(){
	
	$$('.topimgbox').setStyles({'opacity':0,'display':'block'});
	$$('#topimg .active').setStyles({'opacity':1});
	var thisonenext,thisonenextinfo;
	var slideRound = 0;
	var goSlide = 1;
	function newSlideshow(){
		if(goSlide == 1){
			if(slideRound < 2){
				thisonenext = $$('#topimg .active').getNext('.topimgbox');
				$$('#topimg .active').fade(0);
				$$('#topimg .active').removeClass('active');
				thisonenext.addClass('active');
				thisonenext.fade(1);

				thisonenextinfo = $$('#startinfo .active').getNext('.startinfoboxes');
				thisid = $$('#startinfo .active').get('id').toString().split('_active');
				$$('#startinfo .active').set('id', thisid[0]);
				$$('#startinfo .active').removeClass('active');
				thisonenextinfo.set('id', thisonenextinfo.get('id')+'_active');
				thisonenextinfo.addClass('active');

				slideRound++;
				newSlideshow.delay(4500);
			}else{
				thisonenext = $$('#topimg').getFirst('.topimgbox');
				$$('#topimg .active').fade(0);
				$$('#topimg .active').removeClass('active');
				thisonenext.addClass('active');
				thisonenext.fade(1);

				thisonenextinfo = $$('#startinfo').getFirst('.startinfoboxes');
				thisid = $$('#startinfo .active').get('id').toString().split('_active');
				$$('#startinfo .active').set('id', thisid[0]);
				$$('#startinfo .active').removeClass('active');
				thisonenextinfo.set('id', thisonenextinfo.get('id')+'_active');
				thisonenextinfo.addClass('active');

				slideRound = 0;
				newSlideshow.delay(4500);
			}
		}
	}
	newSlideshow.delay(4500);
	
	$$('.startinfoboxes').each(function(el,index){
		el.newindex = index+1;
		el.addEvents({
			'click': function(e){
				
				goSlide = 0;
				thisidi = $$('#startinfo .active').get('id').toString().split('_active');
				$$('#startinfo .active').set('id', thisidi[0]);
				$$('#startinfo .active').removeClass('active');
				$(this).set('id', $(this).get('id')+'_active');
				$(this).addClass('active');
				
				$$('#topimg .active').fade(0);
				$$('#topimg .active').removeClass('active');
				$$('#topimage'+el.newindex).fade(1);
				$$('#topimage'+el.newindex).addClass('active');
			}
		});
	});
	
});
