var functions = {
	init: function(){
		functions.hide_all();
		Event.observe(document, 'click', functions.click_handler.bindAsEventListener());
		if ($('share_this')) { Event.observe($('share_this'), 'mouseover', functions.share_this.bindAsEventListener()); };
	},
	hide_all: function(){
		$$('.dropdown_wrapper').each(function(s){ s.setStyle({display:'none'}); });
	},
	share_this: function(e){
		var tag = Event.element(e);
		
		if (tag.tagName == 'IMG'){
			tag.up('p').down('strong').update(tag.up('a').title);
		}
	},
	click_handler: function(e){
		var tag = Event.element(e);
		
		if (tag.className == 'dropdown'){ functions.dropdown(tag); }
	},
	dropdown: function(obj){
		obj.next(0).appear({duration:'0.5'});
		
		obj.next(0).select('a').each(function(s){
			Event.observe(s,'click',function(){
				s.up('.dropdown_wrapper').previous(0).update(s.innerHTML);
			});
		});
		Event.observe(document,'click',function(){obj.next(0).hide()});
	}
}

document.observe("dom:loaded", function() {
		functions.init();
		Event.observe($('form_navn'),'focus',function(){if(this.value == 'Navn'){this.value = ''}});
		Event.observe($('form_epost'),'focus',function(){if(this.value == 'E-post'){this.value = ''}});
		Event.observe($('form_mobil'),'focus',function(){if(this.value == 'Mobil'){this.value = ''}});
		Event.observe($('form_postnr'),'focus',function(){if(this.value == 'Postnr'){this.value = ''}});
		
		Event.observe($('form_navn'),'blur',function(){if(this.value == ''){this.value = 'Navn'}});
		Event.observe($('form_epost'),'blur',function(){if(this.value == ''){this.value = 'E-post'}});
		Event.observe($('form_mobil'),'blur',function(){if(this.value == ''){this.value = 'Mobil'}});
		Event.observe($('form_postnr'),'blur',function(){if(this.value == ''){this.value = 'Postnr'}});
		
		Event.observe($('small_form_navn'),'focus',function(){if(this.value == 'Navn'){this.value = ''}});
		Event.observe($('small_form_epost'),'focus',function(){if(this.value == 'E-post'){this.value = ''}});
		Event.observe($('small_form_mobil'),'focus',function(){if(this.value == 'Mobil'){this.value = ''}});
		Event.observe($('small_form_postnr'),'focus',function(){if(this.value == 'Postnr'){this.value = ''}});
		
		Event.observe($('small_form_navn'),'blur',function(){if(this.value == ''){this.value = 'Navn'}});
		Event.observe($('small_form_epost'),'blur',function(){if(this.value == ''){this.value = 'E-post'}});
		Event.observe($('small_form_mobil'),'blur',function(){if(this.value == ''){this.value = 'Mobil'}});
		Event.observe($('small_form_postnr'),'blur',function(){if(this.value == ''){this.value = 'Postnr'}});
});