/*
 * Commons
 * Copyright(c), CBC Radio 3 - Phil Rabin.
 */


if(typeof CBCR3=="undefined"||!CBCR3){var CBCR3={};}
CBCR3.namespace=function()
{var a=arguments,o=null,i,j,d;for(i=0;i<a.length;i=i+1){d=(""+a[i]).split(".");o=CBCR3;for(j=(d[0]=="CBCR3")?1:0;j<d.length;j=j+1){o[d[j]]=o[d[j]]||{};o=o[d[j]];}}
return o;}
var Trace={log:function(obj){this._outputToConsole(obj);},write:function(obj){this._outputToConsole(obj);},_outputToConsole:function(obj){if(!window.top.location.href.toQueryParams().debug)
return;if(typeof window.opera!="undefined")
window.opera.postError(obj);if(typeof console!="undefined")
console.log(obj);}};if(!Array.prototype.filter)
{Array.prototype.filter=function(fun)
{var len=this.length>>>0;if(typeof fun!="function")
throw new TypeError();var res=new Array();var thisp=arguments[1];for(var i=0;i<len;i++)
{if(i in this)
{var val=this[i];if(fun.call(thisp,val,i,this))
res.push(val);}}
return res;};}

CBCR3.namespace("CBCR3.Commons");CBCR3.Commons.Event=Class.create({initialize:function(type,data,target)
{this.type=type;this.data=data;this.target=target;}});

CBCR3.namespace("CBCR3.Commons");CBCR3.Commons.EventDispatcher=Class.create({initialize:function()
{},buildListenerChain:function()
{if(!this.listenerChain)
this.listenerChain={};},addEventListener:function(type,listener){if(!listener instanceof Function)
alert("Listener isn't a function");this.buildListenerChain();if(!this.listenerChain[type])
this.listenerChain[type]=[listener];else
this.listenerChain[type].push(listener);},hasEventListener:function(type)
{return(typeof this.listenerChain[type]!="undefined");},removeEventListener:function(type,listener)
{if(!this.hasEventListener(type))
return false;for(var i=0;i<this.listenerChain[type].length;i++)
if(this.listenerChain[type][i]==listener)
this.listenerChain.splice(i,1);},clearEventListeners:function()
{this.listenerChain={};},dispatchEvent:function(type,data,target)
{var event=new CBCR3.Commons.Event(type,data,target||this);this.buildListenerChain();if(!this.hasEventListener(type))
return false;this.listenerChain[type].any(function(funct){return(funct(event)==false?true:false);});}});

Object.extend(String.prototype,{trimText:function(textToFind)
{var length=this.length;if(this.toLowerCase().indexOf(textToFind)==0)
return this.substring(4,this.length-1);return this;}});

CBCR3.Commons.Lists={createCheckerStripes:function(itemCollection)
{var i=0;itemCollection.each(function(item){if((i%4==1)||(i%4==2))
item.addClassName("odd");i++;});}};

CBCR3.namespace("CBCR3.Commons");CBCR3.Commons.Cookies={create:function(name,value,days)
{if(days)
{var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else
var expires="";document.cookie=name+"="+value+expires+"; path=/";},getValue:function(name)
{var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++)
{var c=ca[i];while(c.charAt(0)==' ')
c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)
return c.substring(nameEQ.length,c.length);}
return null;}};
