    var hasActiveX = false;

    function videoSidebar() {}
    videoSidebar.url = '';
    videoSidebar.videoMode = 'java';


    videoSidebar.init = function(){
        this.videoClient = document.getElementById('CCVideoClient');
        this.soundState = 0;
        this.data = {
            camtocam: 'camtocam',
            detach: 'detach',
            sound: 'sound',
            endsession: 'endsession'
        };
        
        var imgID;
        var img;
        for(imgID in this.data){
            img = document.getElementById(imgID);
            img.onmouseover = videoSidebar.toolbarOnOver;
            img.onmouseout = videoSidebar.toolbarOnOut;
            if (img.captureEvents){
                img.captureEvents(Event.MOUSEOVER);
                img.captureEvents(Event.MOUSEOUT);
            }
            this.updatePic(img, false);

            img = new Image();
            img.src = this.url + this.data[imgID] + '.gif';
        }
        var link;
        if (this.videoMode == 'activex' &&
            this.videoClient != null){
            
            link = document.getElementById('soundLink');
            link.onclick = function(){
                if (videoSidebar.soundState == 0){
                    videoSidebar.soundState = -1;
                    videoSidebar.videoClient.mute = false;
                } else {
                    videoSidebar.soundState = 0;
                    videoSidebar.videoClient.mute = true;
                }
                videoSidebar.updatePic(document.getElementById('sound'), true);
                return false;
            }
            if (link.captureEvents)
                link.captureEvents(Event.CLICK);
            
            link = document.getElementById('camtocamLink');
            link.onclick = function(e){
                if (!e) var e = window.event;
                videoSidebar.videoClient.ShowPopupMenu(e.clientX, e.clientY);
                return false;
            }
            if (link.captureEvents)
                link.captureEvents(Event.CLICK);

            link = document.getElementById('detachLink');
            link.onclick = function(){
                videoSidebar.videoClient.ToggleDetach();
                return false;
            }
            if (link.captureEvents)
                link.captureEvents(Event.CLICK);
            setTimeout('videoSidebar.videoConnect()', 2000);
        } else if (this.videoMode == 'javascript' &&
                   this.videoClient != null){
            this.videoCache = document.getElementById('CCVideoCache');
            this.videoClient.onload = this.jsOnLoad;
            this.videoClient.onerror = this.jsOnError;
            this.videoCache.onload = this.jsOnLoad;
            this.videoCache.onerror = this.jsOnError;
            this.jsLoadPic(this.videoCache);
        }
        link = document.getElementById('endsessionLink');
        link.onclick = function(){
            redirect(window.top, this.href);
            return false;
        }
        if (link.captureEvents)
            link.captureEvents(Event.CLICK);
    }

    videoSidebar.jsOnLoad = function(e){
        if (!e) var e = window.event;
        var src;
        if (e.target) src = e.target; 
        else if (e.srcElement) src = e.srcElement;
        if (src == videoSidebar.videoCache){
            videoSidebar.videoCache.style.visibility = 'hidden';
            videoSidebar.jsLoadPic(videoSidebar.videoClient);
        } else {
            videoSidebar.videoCache.style.visibility = 'visible';
            videoSidebar.jsLoadPic(videoSidebar.videoCache);
        }
    }

    videoSidebar.jsOnError = function(e){
        if (!e) var e = window.event;
        var src;
        if (e.target) src = e.target; 
        else if (e.srcElement) src = e.srcElement;
        videoSidebar.jsLoadPic(src);
    }

    videoSidebar.jsLoadPic = function(src){
        var procStarted = new Date();
        src.src = 'http://' + this.remoteIP + ':' + this.remotePort + '/' + 
            procStarted.getTime() + '/Snapshot.jpg?uid=' + this.vidAuth;
    }

    videoSidebar.videoFPSUpdate = function(value){
        if (window.status)
            window.status = Math.round(value / 10) / 10 + ' ' + videoSidebar.translation['fps'];
    }

    videoSidebar.videoSoundReceived = function(value){
        videoSidebar.soundState = (value ? 1 : 0);
        videoSidebar.updatePic(document.getElementById('sound'), false);
    }

    videoSidebar.videoConnect = function(){
        this.videoClient.screenName = this.screenname;
        this.videoClient.auth = this.vidAuth;
        this.videoClient.remoteIP = this.remoteIP;
        this.videoClient.remotePort = this.remotePort;
        this.videoClient.mute = false;
        CCVideoClient.mute = false;
        this.videoClient.Connect();
        videoSidebar.soundState = (this.videoClient.mute ? 0 : -1);
        videoSidebar.updatePic(document.getElementById('sound'), false);
    }

    videoSidebar.updatePic = function(button, state){
        var name = button.id + (state ? '' : 'up');
        if (button.id == 'sound'){
            switch(videoSidebar.soundState){
                case 0:
                    name = 'soundoff' + (state ? '' : 'up');
                    break;
                case -1:
                    name = 'soundquery';
                    break;
                case 1:
                    name = 'soundon' + (state ? '' : 'up');
                    break;
            }
        }
        button.src = this.url + name + '.gif';
    }

    videoSidebar.toolbarOnOver = function(e){
        if (!e) var e = window.event;
        var src;
        if (e.target) src = e.target;
        else if (e.srcElement) src = e.srcElement;
        videoSidebar.updatePic(src, true);
    }

    videoSidebar.toolbarOnOut = function(e){
        if (!e) var e = window.event;
        var src;
        if (e.target) src = e.target;
        else if (e.srcElement) src = e.srcElement;
        videoSidebar.updatePic(src, false);
    }

    
    //old version
    var imgcamtocam;
    var imgcamtocamup;
    var imgdetach;
    var imgdetachup;
    var imgendsession;
    var imgendsessionup;
    var imgsoundon;
    var imgsoundonup;
    var imgsoundoff;
    var imgsoundoffup;
    var imgsoundquery;
    var imgsoundqueryup;

    function assignButtons (imageURLs){
        var aObj = new Array('camtocam','camtocamup','detach','detachup','endsession', 'endsessionup','soundon', 'soundonup', 'soundoff', 'soundoffup', 'soundquery', 'soundqueryup');
        for (i = 0; i < 12; i++){
            eval('img' + aObj[i] + ' = new Image();');
            eval('img' + aObj[i] + '.src = "' + imageURLs[i] + '";');
        }
    }

    function actMenuItem(el){
        if (document.images)
            el.src = eval('img' + el.alt + "up.src");
    }

    function inactMenuItem(el){
        if (document.images)
            el.src = eval('img' + el.alt + ".src");
    }

    function detach(){
        if (CCVideoClient)
            CCVideoClient.ToggleDetach();
    }

    function sound(){
        if (CCVideoClient){
            switch(imgsound.alt){
                case 'soundoff':
                    changeSoundState('query');
                    CCVideoClient.mute = false;
                    break;
                case 'soundon':
                    changeSoundState('off');
                    CCVideoClient.mute = true;
                    break;
                default:
                    return;
                    break;
            }
        }
    }

    function changeSoundState(newState){
        imgsound.alt = "sound" + newState;
        inactMenuItem(imgsound);
    }

    function getInitSoundState(){
        if (CCVideoClient){
            if (CCVideoClient.mute)
                changeSoundState('off');
            else
                changeSoundState('on');
        } else setTimeout('getInitSoundState()', 500);
    }


