dojo.addOnLoad(function() {
    dojo.require("dojo.NodeList-fx");
    dojo.require("dojo.fx");

    dojo.query("#neem_contact_op")
        .connect("onclick", function() {
            var contact_popup = dojo.query(".contact_popup")[0];
            var height = dojo.style(contact_popup, "height");
            height = height / 2;
        
            var anim1 = dojo.fadeIn({
                node: contact_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: contact_popup,
                properties:{
                    marginTop: "-" + height,
                    marginLeft: -150
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query(".contact_popup .close")
        .connect("onclick", function() {
            var contact_popup = dojo.query(".contact_popup")[0];
            
            var anim1 = dojo.fadeOut({
                node: contact_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: contact_popup,
                properties:{
                    marginTop: -700,
                    marginLeft: -900
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query("#offerte_aanvragen")
        .connect("onclick", function() {
            var offerte_popup = dojo.query(".offerte_popup")[0];
            var height = dojo.style(offerte_popup, "height");
            height = height / 2;
        
            var anim1 = dojo.fadeIn({
                node: offerte_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: offerte_popup,
                properties:{
                    marginTop: "-" + height,
                    marginLeft: -150
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query(".offerte_popup .close")
        .connect("onclick", function() {
            var offerte_popup = dojo.query(".offerte_popup")[0];
            
            var anim1 = dojo.fadeOut({
                node: offerte_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: offerte_popup,
                properties:{
                    marginTop: -700,
                    marginLeft: -900
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query(".menu-zoeken-button")
        .connect("onclick", function() {
            var search_popup = dojo.query(".search_popup")[0];
            var height = dojo.style(search_popup, "height");
            height = height / 2;
        
            var anim1 = dojo.fadeIn({
                node: search_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: search_popup,
                properties:{
                    marginTop: "-" + height,
                    marginLeft: -150
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query(".search_popup .close")
        .connect("onclick", function() {
            var search_popup = dojo.query(".search_popup")[0];
            
            var anim1 = dojo.fadeOut({
                node: search_popup,
                duration: 500
            });
            var anim2 = dojo.animateProperty({
                node: search_popup,
                properties:{
                    marginTop: -700,
                    marginLeft: -900
                }
            });
            var animation = dojo.fx.combine([anim1,anim2]);
            animation.play();
        });
        
    dojo.query('.search_popup #type')
        .connect('onchange', function() {
            var form = dojo.byId('search_popup_form');
            var type = dojo.byId('type');
            var search = dojo.byId('search');
            
            if(type.value == 'website') {
                search.name = 'q';
                form.action = 'http://www.sterc.nl/zoeken';
            }
            
            if(type.value == 'weblog') {
                search.name = 's';
                form.action = 'http://www.sterc.nl/weblog';
                form.method = 'get';
            }
        });
    
    

    
});

function searchSubmit() {
    var form = dojo.byId('search_popup_form');
    var type = dojo.byId('type');
    var search = dojo.byId('search');
    
    if(type.value == 'website') {
        search.name = 'q';
        form.action = 'http://www.sterc.nl/zoeken';
    }
    
    if(type.value == 'weblog') {
        search.name = 's';
        form.action = 'http://www.sterc.nl/weblog';
        form.method = 'get';
    }
    form.submit();
}