/*
fim.js instantiates the main fim object 
to be used by all sub objects in the hirarchy.
*/

/**
 * The fim global namespace
 * @constructor
 */
window.fim = window.fim || {};
//var fim = new Object();


/**
 * Returns the namespace specified and creates it if it doesn't exist
 *
 * fim.namespace("property.package");
 * fim.namespace("fim.property.package");
 *
 * Either of the above would create fim.property, then
 * fim.property.package
 *
 * Be careful when naming packages. Reserved words may work in some browsers
 * and not others. For instance, the following will fail in Safari:
 *
 * fim.namespace("really.long.nested.namespace");
 *
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * @param  {String} ns The name of the namespace
 * @return {Object}    A reference to the namespace object
 */
fim.namespace = function(ns) {
    if (!ns || !ns.length) {
        return null;
    }
    var levels = ns.split(".");
    var nsobj = fim;

    // fim is implied, so it is ignored if it is included
    for (var i=(levels[0] == "fim") ? 1 : 0; i<levels.length; ++i) {
        nsobj[levels[i]] = nsobj[levels[i]] || {};
        nsobj = nsobj[levels[i]];
    }
    return nsobj;
};


/**
 * Utility to set up the prototype, constructor and superclass properties to
 * support an inheritance strategy that can chain constructors and methods.
 *
 * @param {function} subclass   the object to modify
 * @param {function} superclass the object to inherit
 */
fim.extend = function(subclass, superclass) {
    var f = function() {};
    f.prototype = superclass.prototype;
    subclass.prototype = new f();
    subclass.prototype.constructor = subclass;
    subclass.superclass = superclass.prototype;
    if (superclass.prototype.constructor == Object.prototype.constructor) {
        superclass.prototype.constructor = superclass;
    }
};

// Broswer detection - these must be consistent on every page.  
fim.IE5 = ((document.all) && (!document.fireEvent) && (!window.opera)) ? 1 : 0;
fim.IE55 = ((document.all) && (!document.fireEvent) && (!document.createComment)) ? 1 : 0;
fim.IE55andUp = ((document.all) && (document.fireEvent)) ? 1 : 0;
fim.DOM = (document.getElementById) ? 1 : 0;  // ns6+ and ie5+ and mozilla
fim.NS6 = ((!document.all) && (document.getElementById)) ? 1 : 0;  // ns6+ and mozilla, not ie6
fim.IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
fim.PC = (navigator.platform == "Win32") ? 1 : 0;
fim.MAC = ((navigator.appVersion.indexOf("PPC") >0) || (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
// ie7 check.  only do it if the browser is IE
if (fim.IE) {
	fim.IE7 = (navigator.appVersion.indexOf("MSIE 7") > 0) ? 1 : 0; 
}

fim.setCookie= function(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

fim.getCookie = function(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {end = dc.length;}
	return unescape(dc.substring(begin + prefix.length, end));
}

fim.namespace("ajax");
fim.namespace("debug");
fim.namespace("dom");
fim.namespace("events");
fim.namespace("ff");
fim.namespace("flash");
fim.namespace("time");

/*
 another entry would be effects
 - wipe on 
 - wipe off
 - fade in
 - fade out
 
*/