var Terms = new Class(
{
	termsAnimating: {},
	termsOpen: {},
	termsFullHeight: {},
	
	initialize: function() {
		$$('.termsOuter').each(function(el){
			this.termsFullHeight[el.id] = el.getStyle('height');
			el.setStyle('height', '0px'); // force load of background-image to prevent jumpy animation
			el.setStyle('display', 'block');	
		}.bind(this))
	},
	
	openCloseTerms: function(termsToOpen) {
		// only one animation at a time per terms
		if (this.termsAnimating[termsToOpen])
			return;
		
		// open
		if (!this.termsOpen[termsToOpen])
			this.startFadeIn(termsToOpen);
			
		// close
		else
			this.startFadeOut(termsToOpen);
	},
	
	startFadeIn: function(termsToOpen) {
		var fx = new Fx.Tween($(termsToOpen), {
			onComplete: function(termsToOpen) {
				this.termsAnimating[termsToOpen] = null;
				$(termsToOpen+'OpenClose').innerHTML = 'Luk';
			}.bind(this, termsToOpen)
		});
		this.termsOpen[termsToOpen] = true;
		this.termsAnimating[termsToOpen] = fx;
		fx.start('height', this.termsFullHeight[termsToOpen]);
	},
	
	startFadeOut: function(termsToOpen) {
		var fx = new Fx.Tween($(termsToOpen), {
			onComplete: function(termsToOpen) {
				this.termsAnimating[termsToOpen] = null;
				this.termsOpen[termsToOpen] = false;
				$(termsToOpen+'OpenClose').innerHTML = 'Se konkurrencebetingelser';
				
			}.bind(this, termsToOpen)
		});
		this.termsAnimating[termsToOpen] = fx;
		
		fx.start('height', '0px');
	}
});

function addFlashBanner() {
	var container = $('logo').getElement('div.swiff');
	// flash-version of logo
	if (Browser.Plugins.Flash.version) {
		new Swiff(nf.baseUrl+nf.modulePath+'res/gfx/logoanim.swf', {
			id: 'logoAnim',
			width: 1000,
			height: 450,
			container: container,
			params: {
				wmode: 'opaque',
				bgcolor: '#ffffff'
			}
		});
	}
	container.removeClass('hidden');
}

function hideFlashBanner() {
	$('logo').getElement('div.swiff').addClass('hidden');
}

var terms = {};
var luckynumbers = {};
var custombox = {};

window.addEvent('domready', function() {
	addFlashBanner();
	// initialize terms drop down
	terms = new Terms();
	custombox = new CustomBox('customBox', {container:'outerContent'});
	luckynumbers = new LuckyNumbers(custombox);
});