

(function () {

    var $ = jQuery,
		esf = window.esf || (window.esf = {}),
		undefined;

	esf.site = {};
	
    /*
    Page Specific Functionality 
    */

    // The base Page class. Common functions for pages should go in its prototype.
    esf.site.Page = function (customMembers) {
        this.$I = $(this);

        $.extend(this, customMembers);
    };

    esf.site.Page.prototype = esf.site.Page.fn = {
        $I: null,
        pageForm: null,
		
		test:function(){return false;},
		
        init: null,
        load: null,

        submit: function () {
            return this.pageForm.submit();
        },

        bind: function () {
            this.$I.bind.apply(this.$I, arguments);
            return this;
        },

        trigger: function () {
            this.$I.trigger.apply(this.$I, arguments);
            return this;
        }		
		
    };


	esf.site.pages = {};
	
	esf.site.pages.__init = function (collection) {
		if(!collection) collection = esf.site.pages;
		if(!collection) return;
		
		var run = function(func){
			for(var pageName in collection){
				var page = collection[pageName];
				if($.isFunction(page[func]) && (($.isFunction(page.test) && page.test()) || page.test === true)){
					page[func]();
				}
			}
		}
        // Initialize any pages with the same name as any of the class names on the <body/> tag.
        $(document).ready(function () {
			run("init");
        });
        $(window).load(function () {
            run("load");
        });

    };


	window.popup = function (url, id, options) {
        var opts = $.extend({
            height: null,
            width: null,
            location: null,
            fullscreen: 0
        }, (typeof id === "object") ? id : options),
            win = window.open(url, id || window.location.host, (function () { var str = ""; for (var optName in opts) { str += optName + "=" + opts[optName] + ","; } return str; })());
        return win;
    };

    window.printHtml = function (htmlStr, opts) {
        var win = window.popup(null, "print", $.extend({ height: 500, width: 800 }, opts));
        win.document.writeln(htmlStr);
        win.print();
        return win;
    };


})();



