// ============ PanoModulesGroup ===============================

PanoModulesGroup = function( key, groupName, color ){
    this.pageID = generateRandomID();
    this.groupID = groupName || generateRandomID();
    this.key = key;
    this.color = color;
}
PanoModulesGroup.prototype.addModule = function( fileSWF, containerID, color ){
    var container = document.getElementById( containerID );
    color = color || this.color || "#FFFFFF";
    var so = new SWFObject( fileSWF, createSwfID(containerID), "100%", "100%", "8", color);
    so.addParam('allowScriptAccess', 'always');
    so.addVariable( "key", this.key );
    so.addVariable( "pageID", this.pageID );
    so.addVariable( "groupID", this.groupID );
    so.addVariable( "moduleID", containerID );
    so.write( containerID );
}


// ============ Utilities ===============================

function generateRandomID (){
    return Math.round(Math.random()*1000000).toString(36);
}
function createSwfID ( containerID ){
    return containerID + "_swf";
}
function getModule( containerID ) {
    if (navigator.appName.indexOf("Microsoft") != -1) return window[this.createSwfID(containerID)]
    else return document[this.createSwfID(containerID)]
}


// ============ Controls ===============================

function setContentData(containerID, obj) {
    getModule(containerID).setContentData(obj);
}
function loadContentData(containerID, dataLocation) {
    getModule(containerID).loadContentData(dataLocation);
}
function loadHotspotsData(containerID, dataLocation) {
    getModule(containerID).loadHotspotsData(dataLocation);
}
function setPreferences(containerID, obj) {
    getModule(containerID).setPreferences(obj);
}


// ============ Callbacks ===============================

function setCaption( moduleID, headText ) {
    var captionContainer = document.getElementById( moduleID + "_caption" );
    if( captionContainer != null ) captionContainer.innerHTML = headText;
}
