if(!String.prototype.trim){String.prototype.trim=function(){var str=this.replace(/^\s+/g,'');str=str.replace(/\s+$/g,'');return(str);};}
Function.prototype.inherit=function(parent){var pc=parent.toString();var m=pc.match(/\s*function ([^(]+)\(/);if(m!=null){this.prototype[m[1]]=parent;}
for(var k in parent.prototype){this.prototype[k]=parent.prototype[k];}
};function add_listener(elem,type,callback){if(elem.addEventListener){elem.addEventListener(type,callback,false);}
else if(elem.attachEvent){elem.attachEvent('on'+type,function(){window.event.target=window.event.srcElement;callback(window.event);});}
}
function HTTP(){this.client=null;this.timeout=arguments[0]?arguments[0]:30000;this.timer=null;this.source='';this.query='';this.callback=null;this.callbackTimeout=null;try{this.client=new XMLHttpRequest();}
catch(e){this.client=new ActiveXObject('Microsoft.XMLHTTP');}
if(this.client==null){throw('Error: Your browser does not support'
+' features required by this page.');}
}
HTTP.prototype.get=function(uri){if(this.callback){this.source=uri;return(this.request('GET',uri));}
return(false);};HTTP.prototype.post=function(uri,query){if(this.callback){this.query=query;this.source=uri;return(this.request('POST',uri));}
return(false);};HTTP.prototype.request=function(request,uri){if(this.isBusy()){throw('Error: The page is currently busy.');}
var context=this;this.client.onreadystatechange=(function(){if(this.readyState==4){if(context.timer!=null){window.clearTimeout(context.timer);context.timer=null;}
if(this.status==200){if(this.getResponseHeader('Content-Type')=='text/xml'){context.callback(this.responseXML);}
else{context.callback(this.responseText);}
}
else if(this.status==404){throw('Error: Requested information could not be found ('
+context.source+').'
);}
else{throw('Error: Request failed.');}
}
});if(request=='POST'){this.client.open(request,uri,true);this.setContentType(this.query);this.client.setRequestHeader('Content-Length',this.query.length);this.client.setRequestHeader('Connection','close');this.client.send(this.query);}
else{this.client.open('GET',uri,true);this.client.send(null);}
if(this.callbackTimeout){this.timer=window.setTimeout((function(){window.clearTimeout(context.timer);if(context.isBusy()){context.client.onreadystatechange=null;context.client.abort();context.callbackTimeout();}
}),this.timeout
);}
return(true);};HTTP.prototype.setContentType=function(query){if(query.charAt(0)=='{'){this.client.setRequestHeader('Content-Type','text/json; charset=iso-8859-1');}
else if(query.substring(0,4)=='<xml'){this.client.setRequestHeader('Content-Type','text/xml; charset=iso-8859-1');}
else{this.client.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-1');}
};HTTP.prototype.isBusy=function(){switch(this.client.readyState){case 1:case 2:case 3:return(true);break;}
return(false);};var JSON={};JSON.getObject=function(json){return(eval('('+json+')'));};JSON.getURI=function(obj){return(JSON.getString(obj,JSON.uriSafe));};JSON.getString=function(obj){var buffer=[];var k,i;var treat=arguments[1]?arguments[1]:JSON.addQuotes;switch(JSON.getType(obj)){case 'object':for(k in obj){buffer.push(treat(k)+':'+JSON.getString(obj[k],treat));}
return('{'+buffer.join(',')+'}');break;case 'array':for(i=0;i<obj.length;++i){buffer.push(JSON.getString(obj[i],treat));}
return('['+buffer.join(',')+']');break;case 'string':return(treat(JSON.quoteString(obj)));break;case 'number':return(obj);break;case 'boolean':return(obj?'true':'false');break;case 'null':return('null');break;}
return('');};JSON.getType=function(obj){var type=typeof(obj);if((type==='object')&&(obj instanceof Array)){return('array');}
if((type==='object')&&(!obj)){return('null');}
return(type);};JSON.quoteString=function(str){var esc=/(["\t\n\r\\])/g;var subs={'"':'\\"',"\t":'\\t',"\n":'\\n',"\r":'\\r','\\':'\\\\'};if(esc.test(str)){str=str.replace(esc,function(m){return(subs[m])});}
return(str);};JSON.addQuotes=function(str){return('"'+str+'"');};JSON.uriSafe=function(str){return(escape(str));};function Messenger(){this.source=arguments[0]?arguments[0]:null;this.params=arguments[1]?arguments[1]:null;this.message=null;this.callback=null;this.callbackError=null;this.id='mid'+((new Date()).getTime());}
Messenger.prototype.setSource=function(s){this.source=s;};Messenger.prototype.setParam=function(k,v){this.params[k]=v;};Messenger.prototype.send=function(callback){this.callback=callback;var q=JSON.getURI({'id':this.id,'parameters':this.params});var c=new HTTP();c.callback=this.setResponseHandler();c.get(this.source+'?'+q);};Messenger.prototype.setResponseHandler=function(){var context=this;return(function(response){if(response.length&&response.charAt(0)=='{'){context.message=JSON.getObject(response);if(context.message.error>1&&context.callbackError){if(context.message.head.details){context.callbackError(context.message.head.details);}
else{context.callbackError('Error retrieving data.');}
}
else{context.callback(context.message);}
}
else if(context.callbackError){context.callbackError('Invalid response from server.');}
});};Messenger.prototype.setJSON=function(json){this.message=JSON.getObject(json);return(this.message);};function SetMessenger(){this.Messenger(arguments[0],arguments[1]);}
SetMessenger.inherit(Messenger);SetMessenger.prototype.setResponseHandler=function(){var context=this;return(function(response){if(response.length&&response.charAt(0)=='{'){context.message=JSON.getObject(response);context.buildIndexes();if(context.message.error>1&&context.callbackError){if(context.message.head.details){context.callbackError(context.message.head.details);}
else{context.callbackError('Error retrieving data.');}
}
else{context.callback(context.message);}
}
else if(context.callbackError){context.callbackError('Invalid response from server.');}
});};SetMessenger.prototype.buildIndexes=function(){var keys=this.message.head.set.hash.keys;if(keys&&keys.length){var index;var set=this.message.body;var nrecords=set.length;for(var ki in keys){index={};for(var i=0;i<nrecords;++i){index[set[i][keys[ki][1]]]=i;}
this.message.head.set.hash[keys[ki][0]]=index;}
}
var cs=this.message.head.set.columns;if(cs&&cs.length&&cs[0].key){var cmap={};for(var ci in cs){cmap[cs[ci].key]=ci;}
this.message.head.set.cmap=cmap;}
}
SetMessenger.prototype.setMessage=function(obj){this.message=obj;this.buildIndexes();};function Animation(target,style,dur,ini,fin){this.target=target;this.fps=20;this.frame_delay=Math.round(1000/this.fps);this.frame_total=Math.round(dur/1000)*this.fps;this.frame_index=0;this.is_playing=false;this.is_looping=false;this.interval=null;this.callback=null;this.debug=null;this.style=style;this.ini=ini;this.fin=fin;this.prepend='';this.append='px';this.calc=this.calcLength;this.delta=this.deltaLinear;switch(style){case 'opacity':this.append='';this.calc=this.calcFraction;break;case 'zIndex':this.append='';this.calc=this.calcInteger;break;case 'color':case 'backgroundColor':case 'borderColor':this.prepend='rgb(';this.append=')';this.calc=this.calcColor;break;}
}
Animation.prototype.setDelta=function(callback){this.delta=callback;};Animation.prototype.setCallback=function(callback){this.callback=callback;};Animation.prototype.setDebug=function(callback){this.debug=callback;};Animation.prototype.play=function(){if(!this.is_playing){if(this.frame_index>=(this.frame_total-1)){this.frame_index=0;}
this.interval=setInterval(this.setFrameHandler(),this.frame_delay
);this.is_playing=true;}
};Animation.prototype.stop=function(){clearInterval(this.interval);this.interval=null;this.is_playing=false;this.is_looping=false;if(this.callback){this.callback();}
};Animation.prototype.reset=function(){var c=null;if(this.callback){c=this.callback;this.callback=null;}
this.stop();this.frame_index=0;this.renderFrame(0);if(c){this.callback=c;this.callback();}
};Animation.prototype.loop=function(){this.is_looping=true;this.play();};Animation.prototype.deltaLinear=function(x){return(x);};Animation.prototype.deltaAcceleration=function(x){return(Math.pow(x,3));};Animation.prototype.deltaDeceleration=function(x){return(Math.pow((x-1),3)+1);};Animation.prototype.deltaAccelDecel=function(x){return((-Math.sin((x+0.5)*Math.PI)/2)+0.5);};Animation.prototype.calcLength=function(ini,fin,step){return(((fin-ini)*step)+ini);};Animation.prototype.calcFraction=function(ini,fin,step){return(((fin-ini)*step)+ini);};Animation.prototype.calcInteger=function(ini,fin,step){return(Math.round(((fin-ini)*step)+ini));};Animation.prototype.calcColor=function(ini,fin,step){var ri=ini>>16;var gi=(ini&0x00FF00)>>8;var bi=ini&0x0000FF;var rf=fin>>16;var gf=(fin&0x00FF00)>>8;var bf=fin&0x0000FF;var rn=Math.round(((rf-ri)*step)+ri);var gn=Math.round(((gf-gi)*step)+gi);var bn=Math.round(((bf-bi)*step)+bi);return(rn.toString()+','+gn.toString()+','+bn.toString());};Animation.prototype.renderFrame=function(frame){var d=this.delta(frame/this.frame_total);var v=this.calc(this.ini,this.fin,d);this.target.style[this.style]=this.prepend+v+this.append;if(this.style=='opacity'){this.target.style.filter="alpha(opacity='"+Math.round(v*100)+"')";}
if(this.debug){this.debug(frame,d,this.prepend+v+this.append);}
};Animation.prototype.setFrameHandler=function(){var ctx=this;return(function(){ctx.renderFrame(ctx.frame_index);if(ctx.frame_index<ctx.frame_total){++ctx.frame_index;}
else if(ctx.is_looping){ctx.frame_index=0;}
else{ctx.stop();}
});};function ImagePlayer(canvas){this.transDuration=2000;	this.transWait=8000;this.canvas=canvas;	this.id=canvas.id?canvas.id:'xipidx';	this.els={};	this.seq=null;	this.c={};	this.bp='';	this.l_state=true;	this.p_state=false;	this.index=0;	this.n_ims=0;this.sm=new SetMessenger();	this.s_int=null;}
ImagePlayer.prototype.requestSequence=function(source){this.sm.setSource(source);if(arguments[1]){this.sm.params=arguments[1];}
this.sm.send(this.setSequenceHandler());};ImagePlayer.prototype.loadSequence=function(json){this.setSequence(this.sm.setJSON(json));};ImagePlayer.prototype.setSequence=function(obj){this.seq=obj;this.c=obj.head.set.cmap;this.bp=obj.head.player.base_path;this.n_ims=obj.body.length;for(var i=0;i<this.n_ims;++i){if(!this.seq.body[i][this.c.uri]){this.seq.body[i][this.c.uri]='#';}
}
var p=this.seq.head.player;if(p.background){this.canvas.style.background=p.background;}
this.p_state=p.auto_play;this.buildCanvas();};ImagePlayer.prototype.play=function(){};ImagePlayer.prototype.pause=function(){};ImagePlayer.prototype.stop=function(){};ImagePlayer.prototype.next=function(){};ImagePlayer.prototype.prev=function(){};ImagePlayer.prototype.buildCanvas=function(){this.els.d=document.createElement('div');this.els.d.id=this.id+'_display';this.els.d.className='display';this.els.d.style.width=this.seq.head.player.width+'px';this.els.d.style.height=this.seq.head.player.height+'px';this.els.da=document.createElement('a');this.els.di=document.createElement('img');this.els.da.appendChild(this.els.di);this.els.d.appendChild(this.els.da);this.canvas.appendChild(this.els.d);this.els.t=document.createElement('div');this.els.t.id=this.id+'_trans';this.els.t.className='trans';this.els.t.style.width=this.seq.head.player.width+'px';this.els.t.style.height=this.seq.head.player.height+'px';this.els.ta=document.createElement('a');this.els.ti=document.createElement('img');this.els.ta.appendChild(this.els.ti);this.els.t.appendChild(this.els.ta);this.els.t.style.opacity=0;this.canvas.appendChild(this.els.t);this.displayImage(0);};ImagePlayer.prototype.displayImage=function(index){if(!this.l_state){this.els.ta.setAttribute('href',this.seq.body[this.index][this.c.uri]);this.els.ta.setAttribute('title',this.seq.body[this.index][this.c.title]);this.els.ti.setAttribute('alt',this.seq.body[this.index][this.c.title]);this.els.ti.setAttribute('src',this.bp+'/'+this.seq.body[this.index][this.c.source]);}
else{add_listener(this.els.di,'load',this.setTransImage());}
this.setOpacity(this.els.d,0);this.els.da.setAttribute('href',this.seq.body[index][this.c.uri]);this.els.da.setAttribute('title',this.seq.body[index][this.c.title]);this.els.di.setAttribute('alt',this.seq.body[index][this.c.title]);this.els.di.setAttribute('src',this.bp+'/'+this.seq.body[index][this.c.source]);if(!this.l_state){this.els.t.style.visibility='visible';this.setOpacity(this.els.t,1);}
else{this.l_state=false;}
this.index=index;};ImagePlayer.prototype.setTransImage=function(){var ctx=this;return(function(){var an_in=new Animation(ctx.els.d,'opacity',ctx.transDuration,0,1);an_in.setCallback(ctx.setFinishImage());var an_out=new Animation(ctx.els.t,'opacity',ctx.transDuration,1,0);an_in.play();an_out.play();});};ImagePlayer.prototype.setFinishImage=function(){var ctx=this;return(function(){if(ctx.p_state){var n=ctx.index>=(ctx.n_ims-1)?0:(ctx.index+1);ctx.s_int=setTimeout(function(){ctx.displayImage(n);},ctx.transWait
);}
});};ImagePlayer.prototype.setSequenceHandler=function(){var context=this;return(function(message){context.setSequence(message);});};ImagePlayer.prototype.setOpacity=function(elem,opac){elem.style.opacity=opac;elem.style.filter="alpha(opacity='"+Math.round(opac*100)+"')";};