    var obm_videoPlayer = {
        instance: null, // flash instance of player
        video: null, // file to load when preroll is done loading (the real video)
        link: null, // file to load when preroll is done loading (the real link)
        prerollConfig: {
            active: true, // active preroll campaign
            zoneURL: 'http://ads.doyoulookgood.com/adjson.php?n=a78aea8d&zoneid=132',
            hasCompanion: false, // show companion or not
            companionURL: null,
            type: 'internal', // type of preroll external, internal or both
            link: null, // link for the preroll 
            playing: false, // flag if the preroll is currently playing
            timerId: 0 // flag if the preroll is currently playing
        },
        doPreroll: function(options) {
           /* found preroll play it before current video */
        	    if (options.file && options.link) {
                    this.prerollConfig.link = options.link;
        	        
        	        /* if no video are set we use the one from the config */
        	        if (this.video == null) {
        	            var config = this.instance.getConfig();        	            
                        this.video = config.file;
                        this.link = config.link;
        	        } //if
                
        	        /* load preroll */
                    this.instance.sendEvent('LOAD', {file:options.file, link:options.link});
                
                
                    /* hide controls */
                    $('.obm_videoPlayerWrapper').eq(0).height(240);
                
                    /* set preroll duration and init timer */
                    if (options.duration) {
                        $('div.obm_prerollCounter')
                            .show()
                            .children('span').html(options.duration);
                     
                        this.prerollConfig.timerId = setInterval('obm_videoPlayer.updateTimer()', 1000);
                    } //if
                
                    /* show companion */
                    if (this.prerollConfig.hasCompanion || options.hasCompanion) {
                        $('.obm_adCompanion').html('<iframe class="adCompanion" src="http://www.doyoulookgood.com/js/partners/companion.html" frameborder="0" width="300" height="250" marginheight="0" marginwidth="0" scrolling="no" style="overflow: hidden;"></iframe>');
                    } //if
                    
                    if (this.prerollConfig.viewPixelURL) {
                        $('.obm_playerBox').append('<img src="'+ this.prerollConfig.viewPixelURL +'" border="" style="display:none;" />')
                    } //if
                    
                    this.prerollConfig.active = false;
                    this.prerollConfig.playing = true;
                
        	    } //if
        	    
                setTimeout('obm_videoPlayer.play()', 200);   	    
            
        },
        endPreroll: function() {
            this.prerollConfig.playing = false;
            this.prerollConfig.link = null;
            this.instance.sendEvent('LOAD', this.video);
            
            $('div.obm_prerollCounter').hide();
            $('.obm_videoPlayerWrapper').eq(0).height(260);
            
        },
        
        /* handles xml response that tells us if there is a preroll from BV Media */
        prerollResponse: function(xml) {
            var videoURL;
            var clickURL;
            if (xml) {
         	    var startPos = xml.indexOf('<location>');
         	    if (startPos >= 0) {
         	        startPos += 10;
         	        var endPos = xml.indexOf('</location>');
         	        videoURL = xml.substring(startPos,endPos);
         	    } //if
         	    
         	    var startPos = xml.indexOf('<link>');
         	    if (startPos >= 0) {
         	        startPos += 6;
         	        var endPos = xml.indexOf('</link>');
         	        clickURL = xml.substring(startPos,endPos);
         	    } //if
         	    
         	    this.prerollConfig.hasCompanion = true;
         	    this.prerollConfig.companionURL = 'http://www.doyoulookgood.com/adCompanion.montreal.tv.php?random='+ obm_random;
         	    this.prerollConfig.viewPixelURL = 'http://ads.doyoulookgood.com/adview.php?bannerid=1317';

     	    } //if
     	    
     	    this.doPreroll({
     	        file: videoURL,
     	        link: clickURL
            });
        },
        load: function (file, link) {
            // keep track of current video in case there is a preroll
            this.video = file;
            this.link = file;
            this.instance.sendEvent('LOAD', file);
        },
        play: function () {
            this.instance.sendEvent('PLAY');
        },
        stop: function () {
            this.instance.sendEvent('STOP');
        },
        updateTimer: function() {
            var timeLeft = $('div.obm_prerollCounter span').html() - 1;
            if (timeLeft >= 0) {
                $('div.obm_prerollCounter span').html(timeLeft);
            } else {
                clearInterval(this.prerollConfig.timerId);
            } //if
        },    
        modelListener: function (obj) {
            var player = this.instance;
            switch (obj.newstate) {
                case 'BUFFERING':
                    if (this.prerollConfig.active) {
                        this.prerollConfig.active = false;
                        this.instance.sendEvent('STOP');
                        
                        switch (this.prerollConfig.type) {
                            case 'external':
                                var serviceReader = $('#serviceReader').get(0);             
                                if (serviceReader) {
                         	        serviceReader.get();
                                } //if
                                break;
                            case 'internal':
                            case 'both':
                                $.getScript(this.prerollConfig.zoneURL); 
                                break;
                        } // switch
                    } //if
                    break; 
               case 'PAUSED':
                    if (this.prerollConfig.playing) {
                        this.instance.sendEvent('LINK');
                        this.endPreroll();
                        
                    } else {
                        this.instance.sendEvent('LINK');
                    } //if
                    break; 
               case 'COMPLETED':
                    if (this.prerollConfig.playing ) {
                        this.endPreroll();
                        setTimeout('obm_videoPlayer.play()', 1500);
                    } //if
               
                    break; 
               case 'IDLE':
                    break; 
               case 'PLAYING':
                    break; 
            } //switch
        }  // listener
    };
    
    /* called by js injected */
    function doPrerollBanner(config) {
        obm_videoPlayer.doPreroll(config);
    }
    
    /* called by the ad server js injects some javascript specific for the banner */
    function bannerHandler(data) {
        if (data.html == '') {
            if (obm_videoPlayer.prerollConfig.type == 'both') {
                var serviceReader = $('#serviceReader').get(0);             
                if (serviceReader) {
         	        serviceReader.get();
                } //if
            } else {
                obm_videoPlayer.play();
            } //if
           
        } else {
            $('body').append(data.html);
        } //if
    }
    
    /* called by player when initialisations is complete */
    function playerReady  (readyObj) {
        var playerObj = $('#'+ readyObj.id ).get(0);
        playerObj.addModelListener("STATE","obm_videoPlayer.modelListener");
        obm_videoPlayer.instance = playerObj;
        setTimeout('obm_videoPlayer.play()', '1500');
    } //playerReady