/**
 * MusicMiner Web Server
 * www.soundminer.com
 * Copyright 2006-2008 Soundminer, Inc. All Rights Reserved.
 **/
var Behaviour={list:new Array,register:function(sheet){Behaviour.list.push(sheet);},start:function(){Behaviour.addLoadEvent(function(){Behaviour.apply();});},assign:function(rules,root,_this,skip_root){trace('Behaviour.assign()',1);var start=(new Date()).getTime();if(root==null)root=document;if(_this==null)_this=this;for(key in rules){var start1=(new Date()).getTime();trace('rule['+key+']',1);var func=rules[key];var selectors=key.split(',');var pair,evt,selector;for(var i=0;selectors[i];i++){pair=selectors[i].split(/:/);selector=pair[0];evt=pair[1];if(pair.length==1&&selectors[i].indexOf(':')>=0){selector='';evt=pair[0]}
elements=document.getElementsBySelector(selector,root,skip_root);trace('elements.length; '+elements.length);if(evt){var capture=false;if(func instanceof Array){capture=func[1];func=func[0];}
switch(typeof func){case 'string':if(!_this[func]||typeof _this[func]!='function'){var msg='Event method "'+func+'" does not exist for event selector "'+selector+'"';var err=new Error(msg);if(!err.message)err.message=msg;throw err;}
func=_this[func].bind(_this);break;case 'function':func=func.bind(_this);break;default:alert('Event method "'+func+'" must be of type "function" or "string" for event selector "'+selector+'"');}
for(var j=0;elements[j];j++)Event.observe(elements[j],evt,func,capture);}
else if(typeof(func)!='function')throw 'Event method "'+func+'" must be of type "function" for event selector "'+selector+'"';else for(var j=0;elements[j];j++)func.apply(_this,[elements[j]]);}
trace('rule',-1);trace('time: '+(((new Date()).getTime()-start1))/1000.0);}
trace('Behaviour.assign()',-1);trace('time: '+(((new Date()).getTime()-start))/1000.0);},apply:function(rules,root,_this,skip_root){trace('Behaviour.apply()',1);if(root==null)root=document;if(_this==null){_this=this;trace('_this == null');}
if(rules==null){for(var h=0;sheet=Behaviour.list[h];h++){for(selector in sheet){var list=document.getElementsBySelector(selector,root,skip_root);if(!list)continue;for(i=0;element=list[i];i++)sheet[selector](element);}}}
else this.assign(rules,root,_this,skip_root);trace('Behaviour.apply()',-1);},addLoadEvent:function(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();}}}};function getAllChildren(e){return e.all?e.all:e.getElementsByTagName('*');};function getChildren(element,tag){if(tag=='*')return element.all?element.all:element.getElementsByTagName('*');else return element.getElementsByTagName(tag);};function removeDuplicates(a){var r=new Array();for(var i=0;i<a.length;i++){var dup=false;for(j=i;j<a.length;j++)if(a[i]===a[j])dup=true;if(!dup)r.push(a[i]);}
return r;};document.getElementsBySelector=function(selector,scope,skip_root){trace('getElementBySelector('+selector+')');var start=(new Date()).getTime();function abort(message){throw 'Parse error in selector: '+message;}
if(scope&&!(scope instanceof Array))scope=[scope];else scope=[document];root=scope.slice(0);if(!document.getElementsByTagName)return new Array();var debug=false;var first=true;selector=selector.strip();while(match=selector.match(/^\s*([^a-zA-Z0-9_>-]|(>)\s*)?([a-zA-Z0-9_-]+)(.*)/)){var modifier=match[1],clause=match[3],rest=match[4];if(match[2]&&match[2].length)modifier=match[2];if(debug)alert(modifier+' '+clause);switch(modifier){case '#':var element=document.getElementById(clause);if(!element)return[];scope=[element];break;case '.':if(first)scope=getAllChildren(document);var found=[];for(var i=scope.length-1;i>=0;i--){if(debug)alert(scope[i].className);if(Element.hasClassName(scope[i],clause))found.push(scope[i]);}
scope=found;break;case '>':clause=clause.toUpperCase();var found=[];for(var i=scope.length-1;i>=0;i--){var node;for(var j=scope[i].childNodes.length-1;j>=0;j--){node=scope[i].childNodes[j];if(node.nodeType==1&&node.tagName==clause)found.push(node);}}
scope=found;break;case '':case undefined:clause=clause.toUpperCase();if(clause=='DOCUMENT'){scope=[document];break;}
var found=[];if(root&&root.length&&!skip_root){for(var i=root.length-1;i>=0;i--)
if(root[i].tagName&&root[i].tagName==clause)
found.push(root[i]);root=null;}
for(var i=scope.length-1;i>=0;i--){var elements=getChildren(scope[i],clause);for(var j=elements.length-1;j>=0;j--)found.push(elements[j]);}
scope=found;break;default:abort(selector.inspect());}
selector=rest;first=false;if(scope.length==0)return[];}
trace('time: '+(((new Date()).getTime()-start))/1000.0);return scope;};