doWhenDomReady(initiateCustomScroll);

var scroll = null;
function initiateCustomScroll() {
	var ftop;
	$$('div.autoadjustbottomtofontsizetable').each(function(el) {
		// Adjust height so bottom reaches the nominal y-coordinate of 539
		var p=el.getCoordinates();
		if (!p || !p.top) return;
		if (!ftop) {
			var el0=$('fontselecttable');
			if (el0) ftop=el0.getCoordinates().top;
		}
		if (!ftop) return;
		el.setStyle('height', (ftop-p.top-15)+'px');
	});
	if (typeof(MooScroll)!='undefined') {
		scroll = new MooScroll({
			selector: 'div.scrollarea'
		});
	}
}

/** Transitions for home-page (invoked from page_show_home.ihtml) */

function startHomeTransition(){
	var home1 = new Fx.Tween('home1', {
		property: 'opacity',
		duration: 5000, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	home1.start(1,0);
	
	$('home2').set('opacity', 0);
	var home2 = new Fx.Tween('home2', {
		property: 'opacity',
		duration: 5000, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	home2.start(0,1);
	
	/*
	$('sitebutton1').set('opacity', 0);
	var orangetext1 = new Fx.Tween('sitebutton1', {
		property: 'opacity',
		duration: 5000, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	orangetext1.start(0,1);
         */
	$('sitebutton2').set('opacity', 0);
   $('sitebutton2').getElement('img').setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+$('sitebutton2').getElement('img').get('src')+',sizingMethod=\'scale\')'); // Without this, IE8 renders partially-transparent pixels in the PNG as if they were fully opaque when the surrounding DIV has a CSS opacity

	var orangetext2 = new Fx.Tween('sitebutton2', {
		property: 'opacity',
		duration: 5000, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	orangetext2.start(0,0.99);
}

/** Slideshow for page (invoked from page_show_1) */

function startSlideshow() {
  // set up animation
	var animation = $$("#slideshowContainer div.image");
	var cImage = 0;
	if (animation.length<=1) return;
	var aniTimer=(function() {
		slideshowFadeOutFx = new Fx.Tween(animation[cImage], {
			property: 'opacity',
			duration: 5000, 
			transition: Fx.Transitions.Quart.easeInOut
		});
		slideshowFadeOutFx.start(1,0);
		// rotate animation to next image
		//animation[cImage].fade('out');

		cImage=(cImage+1)%animation.length;
		var cImageDiv=animation[cImage];
		var cImageImg=cImageDiv.getElement('img');
		cImageDiv.set('opacity', 0);
		if (cImageImg && cImageImg.src && cImageImg.src.match(/\.png/)) {
			cImageImg.setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+cImageImg.get('src')+',sizingMethod=\'scale\')'); // Without this, IE8 renders partially-transparent pixels in the PNG as if they were fully opaque when the surrounding DIV has a CSS opacity
		}
		slideshowFadeInFx = new Fx.Tween(cImageDiv, {
			property: 'opacity',
			duration: 5000, 
			transition: Fx.Transitions.Quart.easeInOut
		});
		slideshowFadeInFx.start(0,1);
		//cImageDiv.fade('hide');
		//cImageDiv.fade('in');
	}).periodical(5000);
	window.addEvent('partialPageLoad', function() {
		// stop old animation and clean up timer and event handlers
		if (!aniTimer) return;
		$clear(aniTimer);
		aniTimer=null;
		window.removeEvent('partialPageLoad', arguments.callee);
	});
}


