// start the homepage slideshow

window.addEvent('domready', function() {

if ($chk($('main-portraits-container'))) {

$('main-portraits-container').setStyle('opacity', 0);
$('main-portraits-container').getElements('img').setStyle('position', 'absolute');

}

});


window.addEvent('load', function() {

if ($chk($('main-portraits-container'))) {

$('main-portraits-container').tween('opacity', 1);

sshow = new slideShow( $$('div#main-portraits-container img') );  
// It will fade to the next frame every 3 seconds  
sshow.next.periodical( 5000, sshow ); 

}

});


// even out the homepage intro and recent news boxes
window.addEvent('domready',function() {
	if ($chk($('recent-news'))) {
	
	var introHeight = $('page-content').offsetHeight;
	var newsHeight = $('recent-news').offsetHeight;

	if (introHeight < newsHeight) {
	$('page-content').setStyle('height', newsHeight);
	}
			
	}
});



// replace section headers with custom font
window.addEvent('domready',function() {
	if ($chk($('section-header'))) {
			Cufon.replace($('section-header'));
	}
	
	if ($chk($('news-head'))) {
			Cufon.replace($('news-head'));
			Cufon.replace($$('.widgettitle'));
	}			
});





// add the onchange functionality to the video clips navigation
window.addEvent('domready',function() {

	if($chk($('video-clips-nav'))) {
	
		$$('.section-header').setStyle('paddingRight', 164); // add extra padding to headline to make rooom
	
		$('clips-pulldown').setStyle('display', 'block');
		
		$('video-clips-pulldown').addEvent('change', function(){
		window.location = (this.options[this.selectedIndex].value);
		});
		
	}
});


// make the contact jenn accordion

window.addEvent('domready', function() {
if($chk($('accordion'))) {
$('page-content').setStyle('opacity', 0);
}
});

window.addEvent('load', function() {

if($chk($('accordion'))) {
	setTimeout(function(){});
	var accordion = new Accordion($$('.toggler'),$$('.element'), {
		opacity: 0,
		onActive: function(toggler) { toggler.getParent().addClass('toggle-container-selected'); },
		onBackground: function(toggler) { toggler.getParent().removeClass('toggle-container-selected'); }
	});
	
	setTimeout(function(){ $('page-content').tween('opacity', 1); }, 600);
}
	
});


// start the about us slideshow

window.addEvent('domready', function() {

if ($chk($('about-portraits-container'))) {

$('about-portraits-container').setStyle('opacity', 0);
$('about-portraits-container').getElements('img').setStyle('position', 'absolute');

}

});


window.addEvent('load', function() {

if ($chk($('about-portraits-container'))) {

$('about-portraits-container').tween('opacity', 1);

sshow = new slideShow( $$('div#about-portraits-container img') );  
// It will fade to the next frame every 8 seconds  
sshow.next.periodical( 5000, sshow ); 

}

});


// get rid of the bottom page nav spacing if there are no bottom page nav buttons
window.addEvent('domready', function() {
var thePageNav = $$('.navigation');
if (thePageNav.length > 0) {

thePageNav = thePageNav[0];
thePrev = thePageNav.getElement('.nav-next');
theNext = thePageNav.getElement('.nav-prev');

if ((thePrev.innerHTML == "") && (theNext.innerHTML == "")) {
thePageNav.setStyle('padding', 0);
}

}
});


// on contest forms, check the first radio button

window.addEvent('domready', function() {


if ($$('.mmf-form').length != 0) {

var theForms = $$('.mmf-form'); // get all the forms on the page

theForms.each(function(el){ // for all the forms on the page do below

	if (el.getElements('.mmf-radio').length != 0) { // if a radio button span exists....
		el.getElements('.mmf-radio').each(function(el){
		theRadios=el.getElements('input[type=radio]');
		theRadios[0].checked=true;
		});
	}

});

}


});



// slideshow function

function slideShow( Obj ){
	// Version 0.2; Created by Kow, 2008; http://skyweb.hu/kow
	var pass = this;
	// initializing
	this.curImg = 0;
	this.slides = Obj;
	this.slides.each( function( img, index ){ 
		if( index > 0 ) img.fade(); 
		img.set('morph', { duration: 5000 });
	}, this);
	this.next = function(){
		pass.curImg++;
		this.slides.each( function( img, index ){ 
			img.morph({ opacity: 0 });
		}, this);
		if( pass.curImg == this.slides.length ) pass.curImg = 0;
		this.slides[ pass.curImg ].morph({ opacity: 1 });
	}
	this.prev = function(){
		pass.curImg--;
		this.slides.each( function( img, index ){ 
			img.morph({ opacity: 0 });
		}, this);
		if( pass.curImg < 0 ) pass.curImg = this.slides.length - 1;
		this.slides[ pass.curImg ].morph({ opacity: 1 });
	}
}

// add white padding to images with class ".whitebox"

window.addEvent('domready', function() {

var theWhites = $$('.whitebox');
if (theWhites.length > 0) {
addWhiteBox();
} 
});

function addWhiteBox() {
	var theWhites = $$('.whitebox');
	theWhites.each(function(el){
		
		// create wrapper div
		var theDiv = new Element('div', {'class':'whiteBox'});
		theDiv.injectBefore(el);
		el.inject(theDiv);
		
	});
}