


_jsc_package(["com","coremedia","util"]);




(function(){

var $=com.coremedia.util.Logger=com_coremedia_util_Logger=function(name,title){
this._name=name;
this._title=title;
this._window=null;
this._level=com.coremedia.util.Logger.LEVEL_OFF;
this._logElement=null;

this._enableLogDom=true;
this._useConsole=true;
};$.constructorname='com.coremedia.util.Logger';$.superconstructor=Object;$=$.prototype=new Object();$.super$Object=Object;$.constructor=com.coremedia.util.Logger;









com.coremedia.util.Logger.MIN_LOG_TIME_SPAN=5;
com.coremedia.util.Logger.LEVEL_TRACE=0;
com.coremedia.util.Logger.LEVEL_DEBUG=10;
com.coremedia.util.Logger.LEVEL_INFO=20;
com.coremedia.util.Logger.LEVEL_WARN=30;
com.coremedia.util.Logger.LEVEL_ERROR=40;
com.coremedia.util.Logger.LEVEL_FATAL=50;
com.coremedia.util.Logger.LEVEL_OFF=99;
com.coremedia.util.Logger.LEVEL_ALL=0;




com.coremedia.util.Logger.trace=function(message){
this.log(this.LEVEL_TRACE,message);
};




com.coremedia.util.Logger.debug=function(message){
this.log(this.LEVEL_DEBUG,message);
};




com.coremedia.util.Logger.info=function(message){
this.log(this.LEVEL_INFO,message);
};




com.coremedia.util.Logger.warn=function(message){
this.log(this.LEVEL_WARN,message);
};




com.coremedia.util.Logger.error=function(message){
this.log(this.LEVEL_ERROR,message);
};




com.coremedia.util.Logger.fatal=function(message){
this.log(this.LEVEL_FATAL,message);
};

com.coremedia.util.Logger.log=function(level,msg){

if(typeof(level)=="string"){
msg=level;
level=this.LEVEL_DEBUG;
}
var logger=this.getInstance();
if(logger)logger.log(level,msg);
};

com.coremedia.util.Logger.getInstance=function(){
if(!this._instance){
this._instance=top.com_coremedia_util_Logger&&top.com.coremedia.util.Logger._instance
?top.com.coremedia.util.Logger._instance
:new com.coremedia.util.Logger("JSCLogger","JSC Logger");
}
return this._instance;
};




$.isEnabledFor=function(level){
return this._level<=level;
};




com.coremedia.util.Logger.isTraceEnabled=function(){
return this.getInstance().isEnabledFor(this.LEVEL_TRACE);
};




$.isDebugEnabled=function(){
return this.isEnabledFor(com.coremedia.util.Logger.LEVEL_DEBUG);
};




com.coremedia.util.Logger.isDebugEnabled=function(){
return this.getInstance().isDebugEnabled();
};




com.coremedia.util.Logger.isInfoEnabled=function(){
return this.getInstance().isEnabledFor(this.LEVEL_INFO);
};




com.coremedia.util.Logger.isWarnEnabled=function(){
return this.getInstance().isEnabledFor(this.LEVEL_WARN);
};




com.coremedia.util.Logger.isErrorEnabled=function(){
return this.getInstance().isEnabledFor(this.LEVEL_ERROR);
};




com.coremedia.util.Logger.isFatalEnabled=function(){
return this.getInstance().isEnabledFor(this.LEVEL_FATAL);
};

$.getLevel=function(){
return this._level;
};

$.setLevel=function(level){
return this._level=level;
};

com.coremedia.util.Logger._LOGGER_ELEMENT_ID="com.coremedia.util.Logger._LOGGER_ELEMENT_ID";

$._open=function(){
var self=this;


var windowName=this._name;

var win=this._window=window.open("",windowName,
"height=400,width="+(screen.availWidth-20)
+"left=0,top="+(screen.availHeight-470)+",screenX=0,screenY=0,resizable=yes,scrollbars=yes");


win.moveTo(0,screen.availHeight-470);


win.document.title=this._title;
this._logElement=win.document.getElementById(com.coremedia.util.Logger._LOGGER_ELEMENT_ID);
while(!this._logElement){
var newLogElement=win.document.createElement("p");
newLogElement.setAttribute("id",com.coremedia.util.Logger._LOGGER_ELEMENT_ID);
try{
win.document.body.appendChild(newLogElement);
}catch(e){



}

this._logElement=win.document.getElementById(com.coremedia.util.Logger._LOGGER_ELEMENT_ID);
if(this._logElement&&this._logElement!=newLogElement)
try{
win.document.body.removeChild(newLogElement);
}catch(e){

}
}

self._windowHasFocus=false;
self._changedSinceLastScroll=true;
self._intervalId=win.setInterval(function(){self._maybeScrollIntoView();},1000);

win.onfocus=function(){self._windowHasFocus=true;};
win.onblur=function(){self._windowHasFocus=false;};


win.blur();

this.log(0,"Logger initialized");
};

$._close=function(){
if(this._window){
if(!this._window.closed)
this._window.close();
this._window=null;
}
};

$._getTimestamp=function(){
var date=new Date();
return"["+date.toLocaleString()+"] ";
};

$._buildHeading=function(level,msg){
if(this._window==null||this._window.closed)
this._open();

var levelText=com.coremedia.util.Logger._formatLevel(level);
var doc=this._window.document;
var stampNode=doc.createTextNode(this._getTimestamp());
var divElement=doc.createElement("div");
var bElement=doc.createElement("b");
bElement.appendChild(stampNode);
divElement.appendChild(bElement);
var msgNode=doc.createTextNode(msg);
divElement.appendChild(msgNode);
return divElement;
};

com.coremedia.util.Logger._formatLevel=function(level){
switch(level){
case this.LEVEL_TRACE:
return"trace";
case this.LEVEL_DEBUG:
return"debug";
case this.LEVEL_INFO:
return"info";
case this.LEVEL_WARN:
return"warn";
case this.LEVEL_ERROR:
return"error";
case this.LEVEL_FATAL:
return"fatal";
}
};





$._maybeScrollIntoView=function(){
if(this._changedSinceLastScroll&&this._logElement.scrollIntoView){
this._logElement.scrollIntoView(false);
this._changedSinceLastScroll=false;
}
};

$.log=function(level,msg){
if(level<this._level)
return;
if(msg=="undefined"||typeof(msg)=="undefined")
return;
if(this._useConsole&&window.console)
window.console.log(this._getTimestamp()+": "+msg);
else{
var element=this._buildHeading(level,msg);

this._logElement.appendChild(element);
this._changedSinceLastScroll=true;
}
};

$.debug=function(msg){
this.log(com.coremedia.util.Logger.LEVEL_DEBUG,msg);
};

$.logDom=function(level,msg,node){
if(!this._enableLogDom)
return;

if(typeof(level)=="string"){
node=msg;
msg=level;
level=com.coremedia.util.Logger.LEVEL_DEBUG;
}
if(level<this._level)return;
if(msg=="undefined"||typeof(msg)=="undefined")
return;
var element=this._buildHeading(level,msg);
var formatter=new com.coremedia.dom.DomFormatter();
var pp=formatter.format(this._window.document,node);
element.appendChild(pp);

this._logElement.appendChild(element);
this._changedSinceLastScroll=true;
};


})();



_jsc_package(["com","coremedia","util"]);




(function(){

var $=com.coremedia.util.StopWatch=com_coremedia_util_StopWatch=function(){
this._startTime=null;
this._stopTime=null;
};$.constructorname='com.coremedia.util.StopWatch';$.superconstructor=Object;$=$.prototype=new Object();$.super$Object=Object;$.constructor=com.coremedia.util.StopWatch;




$.start=function(){
this._stopTime=null;
this._startTime=new Date();
};




$.stop=function(){
if(this._startTime&&!this._stopTime){
this._stopTime=new Date();
}
};





$.elapsed=function(){
if(!this._startTime)
return 0;
var stopTime=this._stopTime?this._stopTime:new Date();
return stopTime.getTime()-this._startTime.getTime();
};





$.elapsedAsString=function(){
var millis=this.elapsed();
var seconds=Math.floor(millis/1000);
var minutes=Math.floor(seconds/60);
var hours=Math.floor(minutes/60);
millis%=1000;
seconds%=60;
minutes%=60;
hours%=60;
var result="";
if(hours>0){
if(hours<10)result+="0";
result+=hours+":";
}
if(hours>0||minutes>0){
if(minutes<10)result+="0";
result+=minutes+":";
}
if(seconds<10)result+="0";
result+=seconds+".";
if(millis<100)result+="0";
if(millis<10)result+="0";
result+=millis;
return result;
};

})();