var rainbow, health;
// set the height of the iframe
function setDivHeight() {
	h = $(document.body).getSize().y
	$('container').setStyle('height', h+'px');
	$('myiframe').setStyle('height', h+'px');
}

function rotateImages(rainbow,health,injected)
{
	var link = $('healthy-link');
	if(injected)
	{
		link.setStyle('display','none');
		health.fade('out');
		rainbow.fade('in');
		setTimeout("rotateImages(rainbow,health,false)",5000);
	} else
	{
		link.setStyle('display','');
		rainbow.fade('out');
		health.fade('in');
		setTimeout("rotateImages(rainbow,health,true)",5000);
	}
}

window.addEvent('domready', function(){
	// set the height of the iframe
	setDivHeight();

	// set up the iframe switcher
	$('widget').getElements('a').addEvent('click', function(e){
		new Event(e).stop();
		var url = this.get('href');
		$('myiframe').set('src',url);
	});

	// grow/expand functionality
	var compact = new Fx.Slide('content',{
		'duration':500,
		'start':function(){
			if($('toggler').hasClass('active'))
			{
				$('content-frame').morph({'padding-bottom':'0px'});
				$('swoosh').setStyle('display','none');
			}
		},
		'onComplete':function(){
			if($('toggler').hasClass('active'))
			{
				$('content-frame').morph({'padding-bottom':'10px'});
				$('swoosh').setStyle('display','');
			}
		}
	});
	var shrink = new Element('div',{
		'id':'toggler',
		'events':{
			'click':function(){
				this.toggleClass('active');
				compact.toggle();
			}
		},
		'alt':'minimize widget'
	}).inject('widget');
	var swoosh = new Element('img',{
		'id':'swoosh',
		'src':'img/skittles-swoosh.png',
		'styles':{
			'display':'none'
		}
	//}).inject('content-frame','after');
	});

	// fancy slide for copyright info
	var gobbledygook = new Fx.Slide('copyright').hide();
	$('gobbledygook').addEvent('click',function(){
			gobbledygook.toggle();
	});

	// image rotation
	var imgs = new Asset.images(['img/taste-the-rainbow.png','img/get-more-healthy.png'],{
		onComplete: function(){
			imgs.each(function(img,i){
				img.set({
					'id': 'rotate-img'+i,
					'styles':{
						'left':0,
						'opacity':0,
						'position':'absolute',
						'top':0
					}
				});
				if(i==0)
				{
					rainbow = img;
					rainbow.set('alt','Taste the Rainbow');
				}
				else if(i==1)
				{
					health = img;
					health.set('alt','Don\'t forget to have three balanced meals a day. And no, you can\'t count that bag of SKITTLES as breakfast if that\'s what you\'re thinking.');
				}
			});
			rainbow.inject('healthy-link','before');
			health.inject('healthy-link','before');
			rotateImages(rainbow,health,true);
		}
	});

});
window.addEvent('resize', function(){
	setDivHeight();
});
