/**
 * Pager
 *
 * @extends nl.code.pager.Pager
 */
SitePager = new Class({
    Extends: nl.code.pager.Pager,

    /**
     * Constructor
     *
     * @param string, the base url of this project
     */
    initialize: function(base_url) {
        // call parent constructor
        this.parent(base_url);

        // site wide objects
        //this.addListener('update_page', new Menu());

        // settings
        nl.code.pager.PageData.show_loading = false

        this.scanContent($(document.body));
    },

    /**
     * Set the content of the page
     *
     * @param JSON
     * @param string
     * @return void
     */
    setContent: function(data, text) {
        this.parent(data, text);
    },

    /**
     * Scan the inner html of an element
     *
     * @param Element, the element to scan
     */
    scanContent: function(root) {
        // make sure that links to an external website open up in a new window
        nl.code.pager.PageData.parseExternalLinks(root, ['http://www.4en5mei.nl']);

        // make all internal links ajax calls
        //nl.code.pager.PageData.parseAjaxElements(this, root);

        // make all links with rel="lightbox" lightbox links
        nl.code.lightbox.Lightboxer.fit_screen = false;
        nl.code.lightbox.Lightboxer.parseLightboxLinks(this, root);

        // make nice forms
        //nl.code.form.Form.parseForm(root);

        // create page specific objects
        this.page_object_arr.push(new CitySelector());
    }
});

/**
 * CitySelector Class
 */
CitySelector = new Class({
    /**
     * Constructor
     */
    initialize: function() {
        this.select = $('city-selector');
        var input = $(document.body).getElement('.submit-btn')

        // guard
        if (! this.select || ! input) {
            return;
        }

        var thisObject = this;
        input.addEvent('click', function(event) {
            event.stop();

            thisObject.openWindow();
        });
    },

    /**
     * @return void
     */
    openWindow: function() {
        var selected_arr = this.select.getSelected();

        // guard
        if (! selected_arr.length) {
            return;
        }

        var height = 500;
        var top = (window.getSize().y / 2) - (height / 2);
        var width = 800;
        var left = (window.getSize().x / 2) - (width / 2);
        var options = 'location=yes,status=yes,resizable=yes,scrollbars=yes,width='+ width +',height='+ height +',top='+ top +',left='+ left;
        var address = selected_arr[0].get('value');

        var mywindow = window.open(address, 'city', options);
    }
});