// define clips outside!!!

function PlayerObject(playerInsertMethod, playerID, height, width, containerDIV) {
    // constructor
    this.type = playerInsertMethod;   // page or inline
    this.playerID = playerID;
    this.height = height;
    this.width = width;
    this.containerDIV = containerDIV;
    this.clipIndex = '0';

    if (document.getElementById) {
       this.player = document.getElementById(playerID);

    	if (this.type == 'page') { 
    		this.configure(); 
    	}
    }
}

PlayerObject.prototype.configure=function() {
    var conf, currentPlayList;

    if (this.player) {
       if (this.type == 'page') {
	  var conf = { playList: clips, loop: true, showPlayList: false, autoPlay: true, hideControls: false, autoBuffering: false, videoHeight: this.height, bufferLength: 4, startingBufferLength: 4, showFullScreenButton: false, showMenu: false, controlBarGloss: 'low' };
       } else if (this.type == 'inline') { 
          var conf = { playList: [ clips[this.clipIndex] ], loop: true, showPlayList: false, autoPlay: true, autoBuffering: false,  hideControls: false, videoHeight: this.height, bufferLength: 4, startingBufferLength: 4, showFullScreenButton: false, showMenu: false, controlBarGloss: 'low' };
       }
       // this fails in Firefox 2.0.0.12!
       	this.player.setConfig(conf); 
    } else {
       alert("PlayerObjectError: trying to configure non-initialized player instance.");
    }
}

PlayerObject.prototype.play=function(clipIndex) {
    this.clipIndex = clipIndex;

    if (this.type == 'page') {
       this.player.ToClip(clipIndex);

    } else if (this.type == 'inline') {
       this.configure();
       this.player.ToClip(2);
       this.player.DoPlay();
       OpenInlineBox(Number(this.width)+2, Number(this.height)+50, this.containerDIV);    
    }

}

PlayerObject.prototype.close=function() {
    CloseInlineBox(this.containerDIV);
    this.player.Reset();
}

function OpenInlineBox(WIDTH, HEIGHT, PANELDIV) {

    if (!document.getElementById('page_screen') && !document.getElementById(PANELDIV)) {
      	return;
    }

    var page_screen = document.getElementById('page_screen');
    page_screen.style.height = document.body.parentNode.scrollHeight + 'px';
    page_screen.style.display = 'block';

    var panel = document.getElementById(PANELDIV);
    panel.style.width = WIDTH + "px";
    panel.style.height = HEIGHT + "px";
 
    var xc = 0; var yc = 0; var scrollY = 0;
    
    if( typeof( window.innerWidth ) == 'number' ) {
    	// most decent browsers should hit this
	xc = Math.round((window.innerWidth/2) - (WIDTH/2));
	yc = Math.round((window.innerHeight/2)-(HEIGHT/2));
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
	xc = Math.round((document.documentElement.clientWidth/2) - (WIDTH/2));
	yc = Math.round((document.documentElement.clientHeight/2) - (HEIGHT/2));
    } else {
   	xc = Math.round((document.body.clientWidth/2)-(WIDTH/2));
	// play it safe with height since clientHeight in some browsers = whole document, not screen!
	yc = "100";
    }
    	
    if ( document.documentElement && document.documentElement.scrollTop ) {
    	scrollY = document.documentElement.scrollTop; 
    } else if ( document.body && document.body.scrollTop ) { 
    	scrollY = document.body.scrollTop; 
    } else if ( window.pageYOffset ) { 
        scrollY = window.pageYOffset; 
    } else if ( window.scrollY ) { 
        scrollY = window.scrollY; 
    }

    panel.style.left = xc+'px';
    panel.style.top  = (yc+scrollY)+'px';
    panel.style.display = 'block';
}

function CloseInlineBox(PANELDIV)
{
    var panel = document.getElementById(PANELDIV);
    panel.style.left = '-9999px';
    var page_screen = document.getElementById('page_screen');
    page_screen.style.display = 'none';
}
