﻿window.addEvent('domready', function(){
    if($$('div.explanation-non-js')){
        $$('div.explanation-non-js').each(function(el){
            el.setStyle('display', 'none');
            el.addClass('explanation');
            el.removeClass('explanation-non-js');
        });

		// stop IE6 from thinking the page is longer after hiding the above elements
		if (Browser.Engine.trident4){
			$('page-wrapper').setStyle('height', '100%');
		}
    
        $$('.has-explanation').addEvent('focus', function(){
            this.getParent().getPrevious().setStyle('display', 'block');
        });
    
        $$('.has-explanation').addEvent('blur', function(){
            this.getParent().getPrevious().setStyle('display', 'none');
        });
    }
    
    if($('message-wrapper')){
        var highlight = new Fx.Morph($('message-wrapper'), {
            duration: 3000,
            link: 'wait',
            transition: 'quad:out'
        });
    
        highlight.start({
            backgroundColor: ['#00adef', '#fff']
        });
    }    

	if($('article-comment-wrapper')){
		new SmoothScroll({ duration:500 });

		$('article-comment-wrapper').slide('hide');

		$$('a.article-react-link').addEvent('click', function(){
			$('article-comment-wrapper').slide('toggle');
		});
	}

    if($$('.auto-select')){
		$$('.auto-select').addEvent('focus', function(){
			this.select();
		});
	}

	if($('label-studentnummer')){
		// hide the label initially
		$('label-studentnummer').setStyle('display', 'none');
		$('em-studentnummer').dispose();

		// on change, check if it's 'student' and if so, show the studentnumber field
		$('new-account-usertype').addEvent('change', function(){
			var value = this.getSelected()[0].getProperty('value');
			if (value === '7' || value === '2') {
				$('label-studentnummer').setStyle('display', 'block');
			} else {
				$('label-studentnummer').setStyle('display', 'none');
			}
		});
	}

    if ($('tag-toggle')) {
        // show tag-toggle and hide hidden tags
        $('tag-toggle').setStyle('display', 'inline');
        $$('li.hidden-tag').setStyle('display', 'none');
    
        // on click, reverse the procedure
		$('tag-toggle').addEvent('click', function(e){
            e = new Event(e);
            this.setStyle('display', 'none');
            $$('li.hidden-tag').setStyle('display', 'inline');
            e.stop();
        });
    }

	if($$('.tooltip')){
		// Create tooltips  
		var tooltips = new Tips('.tooltip',{  
			className: 'fancy-tooltip',  
			fixed: false,  
			hideDelay: 50,  
			showDelay: 50,
			offsets: { x: -23, y: 20 }
		});
	}
});