App = {
    boot: function(){
        this.cufon();
        
        window.addEvent( "domready", function(){
            this.searchForm();
            this.printButton();
			this.formFeatures();
			this.homePage();
        }.bind(this));      
        
        
    },
	homePage: function(){
		if($chk($('backgrounds'))){
			var backgrounds = $$('ul#backgrounds li img');
			if(backgrounds){
				var current = 0;
				var total = backgrounds.length;
				$each(backgrounds, function(obj,index){
					if(index == 0)
						obj.setStyle('opacity', 1)
					else
						obj.setStyle('opacity', 0)
				})
				
				var fnToRepeat = function () {
					backgrounds[current].tween('opacity', 0);
					if(current == total-1) current = 0;
					else current++;
					backgrounds[current].tween('opacity', 1);
				}
				var periodicalID = fnToRepeat.periodical(5000);
			}
		
		}
	},

    searchForm: function(){
        if($chk($('search-button'))){
            $('search-button').addEvent('click', function(e){
                e.preventDefault();
               this.doSearch();
            }.bind(this))
        }
        
        if($chk($('search-query'))){
            $('search-query').addEvent('click', function(){
                if($('search-query').value == 'Zoeken'){
                    $('search-query').value = '';
                }
                $('search-query').setStyle('color', '#000');
            });
            $('search-query').addEvent('blur', function(){
                if($('search-query').value == ''){
                    $('search-query').value = 'Zoeken';
                }
                $('search-query').setStyle('color', '#c9d0e0');
            });
            
        }
    },
    doSearch: function(){
		if($('search-query').value != 'Zoeken'){
			$('search-form').submit();
		}
    },
    printButton: function(){
        if($chk($('print-button'))){
            $('print-button').addEvent('click', function(e){
                e.preventDefault();
               this.doPrint();
            }.bind(this))
        }
    },
    doPrint: function(){
        window.print();
    },    
    cufon: function() {
        this.setFonts();
        Cufon.now();  
    },
    setFonts: function(){
        Cufon.set('fontFamily', 'Helvetica-Neue');
        Cufon.replace('div#content h1, div#content h2, div#content h3, div#container div#right ul#banners li h2', {hover: false});
    },
	formFeatures: function(){
		$each($$('div.linkPrevious'), function(linkedItem, index){
			var checkbox = linkedItem.getSiblings('ul[class!=errorlist]')[0].getChildren('li:last-child')[0].getChildren('label')[0].getChildren('input')[0];
			
			
			if(checkbox.checked == true || checkbox.selected == true) linkedItem.setStyle('display','block');

			checkbox.addEvent('click', function(e){
				if(checkbox.checked || checkbox.selected){
					linkedItem.setStyle('display','block');
					
				} else {
					linkedItem.setStyle('display','none');
				}
			});
			$each(checkbox.getParent().getParent().getSiblings(), function(checkboxSibling, ind){
				var checkboxSibling = checkboxSibling.getChildren('label')[0].getChildren('input')[0];
				if(checkboxSibling.get('type') == 'radio'){
					checkboxSibling.addEvent('click', function(e){
						if(checkboxSibling.checked || checkboxSibling.selected){
							linkedItem.setStyle('display','none');

						} else {
							linkedItem.setStyle('display','block');
						}
					})
				}
				else{
					checkboxSibling.addEvent('click', function(){
						if(['id_required_standard_0', 'id_required_standard_1'].indexOf(checkboxSibling.get('id')) != -1){
							//vca
							$$('div.vca').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
						}
						if(checkboxSibling.get('id') == 'id_required_standard_4'){
							//iso9000
							$$('div.iso9001').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
						}
						if(checkboxSibling.get('id') == 'id_required_standard_6'){
							//ckb
							$$('div.ckb').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
						}
						if(checkboxSibling.get('id') == 'id_required_standard_8'){
							//mqm
							$$('div.mqm').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
						}
					})
					if(['id_required_standard_0', 'id_required_standard_1'].indexOf(checkboxSibling.get('id')) != -1){
						//vca
						$$('div.vca').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
					}
					if(checkboxSibling.get('id') == 'id_required_standard_3'){
						//iso9000
						$$('div.iso9001').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
					}
					if(checkboxSibling.get('id') == 'id_required_standard_4'){
						//ckb
						$$('div.ckb').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
					}
					if(checkboxSibling.get('id') == 'id_required_standard_6'){
						//mqm
						$$('div.mqm').setStyle('display', checkboxSibling.checked ? 'block' : 'none')
					}
				}
			});
		});
	}
}
