/**
 *******************************************
 * $Id: revver.js 231 2007-07-02 21:50:50Z gregbrown $
 * REVVER
 * Copyright 2006 REVVER, Inc.
 * Author: Greg Brown, greg@onfocus.net
 * Description:
 *  This is the root js api file.
 *******************************************
 */

var REVVER = {
    Version: '1.0',
    showDebug: false,
    wsApiURL: 'http://api.revver.com/json/1.0/',
    jsApiURL:  'http://widget.revver.com/js/1.0.6/', // js api files root url
    flashApiURL:  'http://flash.revver.com/player/1.0/', // flash api files root url,
    require: function(libraryName) {
        // inserting via DOM fails in Safari 2.0, so brute force approach
        document.write('<script type="text/javascript" src="'+REVVER.jsApiURL+libraryName+'"></script>');
    },
    requireCss: function(styleName) {
        // inserting via DOM fails in Safari 2.0, so brute force approach
        document.write('<link rel="stylesheet" type="text/css" media="screen" href="'+REVVER.jsApiURL+styleName+'" />');
    }
}

/**
 * The REVVER global namespace
 * @constructor
 */
var REVVER = window.REVVER || {};

/**
 * Returns the namespace specified and creates it if it doesn't exist
 *
 * REVVER.namespace("property.package");
 * REVVER.namespace("REVVER.property.package");
 *
 * Either of the above would create REVVER.property, then
 * REVVER.property.package
 *
 * @param  {String} sNameSpace String representation of the desired 
 *                             namespace
 * @return {Object}            A reference to the namespace object
 */
REVVER.namespace = function( sNameSpace ) {
    if (!sNameSpace || !sNameSpace.length) {
        return null;
    }
    var levels = sNameSpace.split(".");
    var currentNS = REVVER;
    // REVVER is implied, so it is ignored if it is included
    for (var i=(levels[0] == "REVVER") ? 1 : 0; i<levels.length; ++i) {
        currentNS[levels[i]] = currentNS[levels[i]] || {};
        currentNS = currentNS[levels[i]];
    }
    return currentNS;
};

/**
 * Global log method.
 */
REVVER.log = function(sMsg,sType) {
    if(REVVER.showDebug) {
        switch (sType) {
            case "debug":
                jslog.debug(sMsg);
                break;
            case "error":
                jslog.error(sMsg);
            case "text":
                jslog.text(sMsg);
                break;
            case "warning":
                jslog.warning(sMsg);
                break;
            default:
                jslog.info(sMsg);
                break;
        }
    } else {
        return false;
    }
};

// set the namespaces for revver components
REVVER.namespace("util");
REVVER.namespace("widget");

// load prototype and other required js files.
REVVER.require('util/json.js'); // needed for json parsing and encoding

// do not include prototype if it's already loaded on the user's site.
if (
    (typeof Prototype=='undefined') || 
    (typeof Element == 'undefined') || 
    (typeof Element.Methods=='undefined') || 
    parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]) < 1.5)
REVVER.require('prototype/prototype.js');

//REVVER.require('prototype/scriptaculous/scriptaculous.js'); // base lib for effects (requires prototype)
//REVVER.require('jslog.js'); // used for debugging.  comment out on production
REVVER.require('lightbox/lightbox.js'); // use for showing the video with a greyed out background
REVVER.requireCss('lightbox/lightbox.css'); // a css file that lightbox needs
//REVVER.require('util/ufo.js'); // needed for appending flash files (note: ufo means unobtrusive flash object)

// revver specific files
REVVER.require('lang/en-us.js'); // lang file for revver
REVVER.require('util/jsonRequest.js'); // handles communication with remote server on a different domain
REVVER.require('util/styleManager.js'); // manages styles for revver objects
REVVER.require('widget/videoCollection.js'); // the video collection classes

// force the inclusion of the revver flash player js
document.write('<script type="text/javascript" src="'+REVVER.flashApiURL+'player.js"></script>');