/**
 * @author:		tfuhlroth
 * @copyright	Maxomedia - Agentur für Crossmedia-Kommunikation BSW
 */

// debug
if (window['console'] === undefined) window.console = { log: $empty };

// $E
$E = document.getElement.bind(document);


/*##################################################|*/
/* #SITE# */

var Site = {
	
	initialize: function (lang) {
		// home teaser: round corner
		if ($('home-teaser-small')) {
			$('home-teaser-small').getElement('.teaser-small').addClass('teaser-small-first');
		}
		
		// home flash teaser
		if ($('home-flash-teaser')) {
			new Swiff('/_swf/banner-home_' + lang + '.swf', {
				width: 496,
				height: 328,
				params: {
					wMode: 'window'	
				},
				container: 'home-flash-teaser'
			});
		}
		
		// print
		if ($('btn-print')) {
			$('btn-print').addEvent('click', function () {
				window.print();	
			}).setStyle('display', 'inline-block');
		}
		
		// accordion
		if ($('accordion-container')) {
			var container = $('accordion-container');
			var accordion = new Fx.Accordion(container.getElements('.accordion-toggle'), container.getElements('.accordion-content'), {
				opacity: false, show : -1, alwaysHide: true
			});
		}
		
		// lokale service-bueros
		if ($('country_btn')) {
			$('country_btn').setStyle('display', 'none');
		}
	}
	
};

//window.addEvent('domready', function () {
//	Site.initialize();
//});




/*##################################################|*/
/* #AVATAR# */

Site.avatar = {
	
	initialize: function (options) {
		this.container = $('avatar-container');
		if (!this.container) return false;
		this.options = options;
		this.load();
	},
	
	load: function () {
		this.swiff = new Swiff('/_swf/avatar.swf', {
			width: 279,
			height: 550,
			params: {
				wMode: 'window'	
			},
			vars: this.options.vars,
			container: this.container
		});
	}
		
};




/*##################################################|*/
/* #LANGUAGE# */

Site.language = {
	
	init: function () {
		this.isOpen = false;
		this.container = $('language-container').removeClass('language-fallback').addClass('language-dropdown');
		this.element = $('lang');
		this.build();
	},
	
	build: function () {
		this.container.addEvents({
			'mouseenter': function () {
				if (this.closeTimer) this.closeTimer = $clear(this.closeTimer);
			}.bind(this),
			'mouseleave': function () {
				this.closeTimer = this.close.delay(300, this);
			}.bind(this),
			'click': this.toggle.bind(this)
		});
		
		this.label = new Element('div', {'class': 'label'});
		this.button = new Element('a', {'class': 'lang-button'});
		
		this.items = new Element('ul');
		this.container.getElements('a').forEach(function (item, index) {
			if (item.hasClass('active')) {
				this.label.set('html', item.get('html'));
				this.label.setStyle('background-image', item.getStyle('background-image'));
			}
			new Element('li').adopt(item).inject(this.items);			
		}, this);
		
		
		this.element.adopt(this.button);
		this.button.inject(this.container);
		this.label.inject(this.element);
		this.items.inject(this.element);
	},
	
	toggle: function () {
		(this.isOpen) ? this.close() : this.open();
	},
	
	open: function () {
		this.isOpen = true;
		this.items.setStyle('display', 'block');
	},
	
	close: function () {
		this.isOpen = false;
		this.items.setStyle('display', 'none');
	}
		
};










/*##################################################|*/
/* #MAINNAV# 

Site.mainnavPreview = {
	
	init: function () {
		this.container = new Element('div', {id: 'mainnav-preview-container'}).inject($('header-container'));
		this.element = $('mainnav');
		this.buttons = this.element.getElements('a');
		this.getHTML();
	},
	
	getHTML: function () {
		new Request.JSON({
			url: '/_service/mainnav.asp',
			onSuccess: function (responseJSON, responseText) {
				this.items = new Hash();
				Hash.forEach(responseJSON, function (item, key) {
					var element = new Element('div', {
						'class': 'item',
						'html': item.content
					});
					if (item.backgroundimage) element.setStyle('background-image', 'url(' + item.backgroundimage + ')');
					this.items.set(key, element.inject(this.container));
				}, this);
				this.attachEvents();
			}.bind(this)
		}).send();
	},
	
	attachEvents: function () {
		this.buttons.forEach(function (button) {
			if (this.items.has(button.get('class'))) {
				button.addEvent('mouseenter', this.showPreview.pass(button.get('class'), this));
				button.addEvent('mouseleave', this.hidePreview.pass(button.get('class'), this));
			}
		}, this);
	},
	
	showPreview: function (key) {
		this.items.get(key).addClass('active');
	},
	
	hidePreview: function (key) {
		this.items.get(key).removeClass('active');
	}
	
};*/
