/*
Copyright (c) 2007-2008 the OTHER media Limited
Licensed under the BSD license, http://ojay.othermedia.org/license.html
*/
// @require yui
// @require ojay/js-class-min
var Ojay=function(){var a=[],b,c,d;for(c=0,d=arguments.length;c<d;c++){b=arguments[c];if(typeof b=='string')b=Ojay.query(b);if(b.toArray)b=b.toArray();if(!(b instanceof Array))b=[b];a=a.concat(b)}return new Ojay.DomCollection(a.unique())};(function(c){JS.extend(Ojay,{query:function(a,b){return document.querySelectorAll?Array.from((b||document).querySelectorAll(a)):YAHOO.util.Selector.query(a,b)},byId:function(a){var b=document.getElementById(a);return new this.DomCollection(b?[b]:[])},changeAlias:function(a){this.surrenderAlias();this.ALIAS=String(a);this.__alias=(typeof window[this.ALIAS]=='undefined')?null:window[this.ALIAS];window[this.ALIAS]=this},surrenderAlias:function(){if(this.__alias===null){if(this.ALIAS)delete window[this.ALIAS];return false}window[this.ALIAS]=this.__alias;return true},log:function(){Array.from(arguments).forEach(function(a){this[a]=this[a].traced(a+'()')},Ojay.DomCollection.prototype)},getDocumentSize:function(){return{width:c.getDocumentWidth(),height:c.getDocumentHeight()}},getScrollOffsets:function(){return{left:c.getDocumentScrollLeft(),top:c.getDocumentScrollTop()}},getViewportSize:function(){return{width:c.getViewportWidth(),height:c.getViewportHeight()}},getVisibleRegion:function(){var a=this.getViewportSize(),b=this.getScrollOffsets();return new this.Region({top:b.top,bottom:b.top+a.height,left:b.left,right:b.left+a.width})}})})(YAHOO.util.Dom);Ojay.changeAlias('$');Ojay.ARRAY_METHODS={indexOf:function(a){var b=this.length;var c=Number(arguments[1])||0;c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0)c+=b;for(;c<b;c++){if(c in this&&this[c]===a)return c}return-1},lastIndexOf:function(a){var b=this.length;var c=Number(arguments[1]);if(isNaN(c)){c=b-1}else{c=(c<0)?Math.ceil(c):Math.floor(c);if(c<0)c+=b;else if(c>=b)c=b-1}for(;c>-1;c--){if(c in this&&this[c]===a)return c}return-1},filter:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();var c=new Array();var d=arguments[1];for(var e=0;e<b;e++){if(e in this){var f=this[e];if(a.call(d,f,e,this))c.push(f)}}return c},forEach:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();var c=arguments[1];for(var d=0;d<b;d++){if(d in this)a.call(c,this[d],d,this)}},every:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();var c=arguments[1];for(var d=0;d<b;d++){if(d in this&&!a.call(c,this[d],d,this))return false}return true},map:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();var c=new Array(b);var d=arguments[1];for(var e=0;e<b;e++){if(e in this)c[e]=a.call(d,this[e],e,this)}return c},some:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();var c=arguments[1];for(var d=0;d<b;d++){if(d in this&&a.call(c,this[d],d,this))return true}return false},reduce:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();if(b==0&&arguments.length==1)throw new TypeError();var c=0;if(arguments.length>=2){var d=arguments[1]}else{do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError();}while(true)}for(;c<b;c++){if(c in this)d=a.call(null,d,this[c],c,this)}return d},reduceRight:function(a){var b=this.length;if(typeof a!="function")throw new TypeError();if(b==0&&arguments.length==1)throw new TypeError();var c=b-1;if(arguments.length>=2){var d=arguments[1]}else{do{if(c in this){d=this[c--];break}if(--c<0)throw new TypeError();}while(true)}for(;c>=0;c--){if(c in this)d=a.call(null,d,this[c],c,this)}return d},unique:function(){var a=[],b,c,d;for(b=0,c=this.length;b<c;b++){d=this[b];if(a.indexOf(d)==-1)a.push(d)}return a},count:function(a,b){return this.filter(a,b).length}};JS.extend(Array.prototype,Ojay.ARRAY_METHODS);JS.extend(Function.prototype,{_1:function(a){this.valueOf=function(){return a};this.toString=function(){return a.toString()};return this},partial:function(){if(!arguments.length)return this;var a=this,b=Array.from(arguments);return function(){return a.apply(this,b.concat(Array.from(arguments)))}._1(this)},curry:function(a){var b=this,a=a||this.length;return function(){if(arguments.length>=a)return b.apply(this,arguments);return b.partial.apply(arguments.callee,arguments)}._1(this)},wrap:function(a){var b=this;return function(){return a.apply(this,[b.bind(this)].concat(Array.from(arguments)))}._1(this)},methodize:function(){if(this._b)return this._b;var a=this;return this._b=function(){return a.apply(null,[this].concat(Array.from(arguments)))}._1(this)},functionize:function(){if(this._c)return this._c;var b=this;return this._c=function(){var a=Array.from(arguments);return b.apply(a.shift(),a)}._1(this)},traced:function(b,c){var d=this,b=b||this,c=c||'info';return function(){window.console&&console[c](b,' called on ',this,' with ',arguments);var a=d.apply(this,arguments);window.console&&console[c](b,' -> ',a);return a}._1(this)},runs:function(a){var b=this,c=0;return function(){return(c++<a)?b.apply(this,arguments):undefined}._1(this)}});String.SCRIPT_FRAGMENT='<script[^>]*>([\\S\\s]*?)<\/script>';JS.extend(String.prototype,{extractScripts:function(){var b=new RegExp(String.SCRIPT_FRAGMENT,'img');var c=new RegExp(String.SCRIPT_FRAGMENT,'im');return(this.match(b)||[]).map(function(a){return(a.match(c)||['',''])[1]})},evalScripts:function(){return this.extractScripts().map(function(a){return eval(a)})},parseJSON:function(){return YAHOO.lang.JSON.parse(this.valueOf())},stripScripts:function(){return this.replace(new RegExp(String.SCRIPT_FRAGMENT,'img'),'')},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,'').trim()},trim:YAHOO.lang.trim.methodize()});'abs acos asin atan ceil cos exp floor log pow round sin sqrt tan'.split(/\s+/).forEach(function(a){Number.prototype[a]=Math[a].methodize()});Number.prototype.times=function(a,b){if(this<0)return;for(var c=0;c<this;c++)a.call(b||null,c)};Number.prototype.between=function(a,b,c){if(this>a&&this<b)return true;return(this==a||this==b)?(c!==false):false};Function.from=function(b){if(b.toFunction)return b.toFunction();if(typeof b=='function')return b;if(typeof b=='object')return Function.fromObject(b);return function(a){return a}};String.prototype.toFunction=function(){var h=this.split('.');if(!h[0])return function(x){return x};return function(a){var b,c=a,d;for(var e=0,f=h.length;e<f;e++){d=h[e];b=c;c=b[d];if(typeof c=='function')c=c.apply(b)}return c}};Array.prototype.toFunction=function(){var c=this[0],d=this.slice(1);if(!c)return function(x){return x};return function(a){var b=(typeof c=='function')?c:a[c];return(typeof b=='function')?b.apply(a,d):undefined}};Function.fromObject=function(g){var i=[];for(var j in g){if(g.hasOwnProperty(j))i.push(j)}if(i.length===0)return function(x){return x};return function(a){var b=true,c,d,e;for(var f=0,h=i.length;f<h;f++){c=i[f];d=a[c];e=g[c];if(typeof d=='function'&&!(e instanceof Array))e=[e];b=b&&((typeof d=='function')?d.apply(a,e):d==e)}return b}};'filter forEach every map some'.split(/\s+/).forEach(function(d){this[d]=this[d].wrap(function(a,b,c){if(b)b=Function.from(b);return a(b,c)})},Array.prototype);(function(g){JS.extend(Ojay,{stopDefault:function(a,b){g.preventDefault(b)},stopPropagate:function(a,b){g.stopPropagation(b)},stopEvent:function(a,b){Ojay.stopDefault(a,b);Ojay.stopPropagate(a,b)},delegateEvent:function(f,h){return function(a,b){var c=b.getTarget(),d;for(var e in f){if(!c.matches(e)&&!h)continue;d=c;if(h)while(d&&!d.matches(e)){d=Ojay(d.node.parentNode);if(d.node==document.body)d=null}if(d)Function.from(f[e]).call(this,d,b)}}},_g:function(){return Ojay(g.getTarget(this))}});Ojay.stopDefault.method=Ojay.stopDefault.partial(null).methodize();Ojay.stopPropagate.method=Ojay.stopPropagate.partial(null).methodize();Ojay.stopEvent.method=Ojay.stopEvent.partial(null).methodize();['onDOMReady','onContentReady','onAvailable'].forEach(function(a){Ojay[a]=g[a].bind(g)})})(YAHOO.util.Event);Ojay.Observable=new JS.Module({include:JS.Observable,on:function(d,e,f){var h=new JS.MethodChain;if(e&&typeof e!='function')f=e;this.addObserver(function(){var a=Array.from(arguments),b=a.shift();if(b!=d)return;var c=(a[0]||{}).receiver||this;if(typeof e=='function'){if(c!==this)a.shift();e.apply(f||null,[c].concat(a))}h.fire(f||c)},this);return h}});(function(g,i){g.DomCollection=new JS.Class({initialize:function(a){this.length=0;for(var b=0,c=a.length,d,e=[].push;b<c;b++){d=a[b].nodeType;if(d===g.HTML.ELEMENT_NODE||d===g.HTML.DOCUMENT_NODE||a[b]==window)e.call(this,a[b])}this.node=this[0];return this},toArray:function(a){if(a)a=Function.from(a);var b=[],c,d=this.length;for(c=0;c<d;c++)b.push(a?a(this[c]):this[c]);return b},at:function(a){a=Number(a).round();var b=(a>=0&&a<this.length)?[this[a]]:[];return new this.klass(b)},on:function(c,d,e){var f=new JS.MethodChain;if(d&&typeof d!='function')e=d;YAHOO.util.Event.on(this,c,function(a){var b=g(this);a.stopDefault=g.stopDefault.method;a.stopPropagate=g.stopPropagate.method;a.stopEvent=g.stopEvent.method;a.getTarget=g._g;if(typeof d=='function')d.call(e||null,b,a);f.fire(e||b)});return f},animate:function(a,b,c){var d=new g.Animation(this,a,b,c);d.run();return d.chain},addClass:function(a){i.addClass(this,a);return this},removeClass:function(a){i.removeClass(this,a);return this},replaceClass:function(a,b){i.replaceClass(this,a,b);return this},setClass:function(a){for(var b=0,c=this.length;b<c;b++)this[b].className=a;return this},hasClass:function(a){if(!this.node)return undefined;return i.hasClass(this.node,a)},getStyle:function(a){if(!this.node)return undefined;return i.getStyle(this.node,String(a))},setStyle:function(a){var b,c=!!YAHOO.env.ua.ie;for(var d in a){if(c&&d=='opacity'){b=Number(a[d]);if(b===0)a[d]=0.001;if(b===1){i.setStyle(this,'filter','');continue}}i.setStyle(this,d,a[d])}return this},setAttributes:function(a){for(var b=0,c=this.length;b<c;b++){for(var d in a)this[b].setAttribute(d,a[d])}return this},hide:function(){return this.setStyle({display:'none'})},show:function(){return this.setStyle({display:''})},setContent:function(b){if(!this.node)return this;if(b instanceof this.klass)b=b.node;if(b&&b.nodeType===g.HTML.ELEMENT_NODE){this.node.innerHTML='';this.node.appendChild(b)}else{this.forEach(function(a){a.node.innerHTML='';a.insert(b,'bottom')})}return this},insert:function(a,b){if(b=='replace')return this.setContent(a);if(a instanceof this.klass)a=a.node;new g.DomInsertion(this.toArray(),a,b);return this},remove:function(){this.toArray().forEach(function(a){if(a.parentNode)a.parentNode.removeChild(a)});return this},matches:function(a){if(!this.node)return undefined;return YAHOO.util.Selector.test(this.node,a)},query:function(a,b){var c=b?g(b):this;if(!a)return new this.klass(c.toArray());c=c.filter({matches:a});return new this.klass(c.toArray())},parents:function(a){var b=this.toArray('parentNode');return this.query(a,b.unique())},ancestors:function(b){var c=[];this.toArray().forEach(function(a){while((a.tagName.toLowerCase()!='body')&&(a=a.parentNode)){if(c.indexOf(a)==-1)c.push(a)}});return this.query(b,c)},children:function(d){var e=[];this.toArray().forEach(function(a){var b=i.getChildren(a),c;while(c=b.shift()){if(e.indexOf(c)==-1)e.push(c)}});return this.query(d,e)},descendants:function(d){d=d||'*';var e=[];this.toArray().forEach(function(a){var b=g.query(d,a),c;while(c=b.shift()){if(e.indexOf(c)==-1)e.push(c)}});return new this.klass(e)},siblings:function(d){var e=this.toArray(),f=[];e.forEach(function(a){var b=g(a).parents().children(d).toArray(),c;while(c=b.shift()){if((e.indexOf(c)==-1)&&(f.indexOf(c)==-1))f.push(c)}});return new this.klass(f)},getRegion:function(){if(!this.node)return undefined;return new g.Region(i.getRegion(this.node))},fitToRegion:function(e){var f=e.getWidth(),h=e.getHeight();this.forEach(function(a){a.setStyle({width:f+'px',height:h+'px'});var b=a.getRegion(),c=b.getWidth(),d=b.getHeight();a.setStyle({width:(2*f-c)+'px',height:(2*h-d)+'px'})});return this},getWidth:function(){if(!this.node)return undefined;return this.getRegion().getWidth()},getHeight:function(){if(!this.node)return undefined;return this.getRegion().getHeight()},getTop:function(){if(!this.node)return undefined;return this.getRegion().top},getBottom:function(){if(!this.node)return undefined;return this.getRegion().bottom},getLeft:function(){if(!this.node)return undefined;return this.getRegion().left},getRight:function(){if(!this.node)return undefined;return this.getRegion().right},getCenter:function(){if(!this.node)return undefined;return this.getRegion().getCenter()},areaIntersects:function(a){if(!this.node)return undefined;var b=g(a);return this.getRegion().intersects(b.getRegion())},intersection:function(a){if(!this.node)return undefined;var b=g(a);var c=this.getRegion(),d=b.getRegion();return c.intersects(d)?c.intersection(d):null},areaContains:function(a){if(!this.node)return undefined;var b=g(a);return this.getRegion().contains(b.getRegion())}})})(Ojay,YAHOO.util.Dom);(function(){var e={};for(var f in Ojay.ARRAY_METHODS)(function(c){var d=/^(?:indexOf|lastIndexOf|unique)$/.test(c);e[c]=function(){var a=d?this.toArray():this.toArray(Ojay);var b=a[c].apply(a,arguments);if(c=='filter')b=Ojay(b.map(function(el){return el.node}));return b}})(f);Ojay.DomCollection.include(e)})();Ojay.fn=Ojay.DomCollection.prototype;Ojay.DomInsertion=new JS.Class({initialize:function(b,c,d){if(!(b instanceof Array))b=[b];if(!(/^(?:top|bottom|before|after)$/i.test(d)))d='bottom';this._8=b.filter(function(a){return a&&a.nodeType===Ojay.HTML.ELEMENT_NODE});this._2=c;this._3=d.toLowerCase();if(this._8.length===0)return;if(this._2&&this._2.nodeType)this._h();if(typeof this._2=='string')this._i()},_h:function(){var b=this.klass._d[this._3];this._8.forEach(function(a){b(a,this._2)},this)},_i:function(){var d=this.klass._d[this._3];this._8.forEach(function(a){var b=(/^(?:before|after)$/.test(this._3)?a.parentNode:a).tagName.toUpperCase();var c=this._j(b);if(/^(?:top|after)$/.test(this._3))c.reverse();c.forEach(d.partial(a))},this)},_j:function(a){var b=this.klass._k[a];var c=Ojay.HTML.div();if(b){c.innerHTML=b[0]+this._2+b[1];for(var d=0,e=b[2];d<e;d++)c=c.firstChild}else c.innerHTML=this._2;return Array.from(c.childNodes)},extend:{_d:{top:function(a,b){a.insertBefore(b,a.firstChild)},bottom:function(a,b){a.appendChild(b)},before:function(a,b){a.parentNode.insertBefore(b,a)},after:function(a,b){a.parentNode.insertBefore(b,a.nextSibling)}},_k:{TABLE:['<table>','</table>',1],THEAD:['<table><tbody>','</tbody></table>',2],TBODY:['<table><tbody>','</tbody></table>',2],TFOOT:['<table><tbody>','</tbody></table>',2],TR:['<table><tbody><tr>','</tr></tbody></table>',3],TD:['<table><tbody><tr><td>','</td></tr></tbody></table>',4],TH:['<table><tbody><tr><td>','</td></tr></tbody></table>',4],SELECT:['<select>','</select>',1]}}});Ojay.HtmlBuilder=new JS.Class({initialize:function(a){this._4=a||null},concat:function(a){if(this._4)this._4.appendChild(a);return a},extend:{addTagNames:function(){var a=(arguments[0]instanceof Array)?arguments[0]:arguments;for(var b=0,c=a.length;b<c;b++)this.addTagName(a[b])},addTagName:function(i){this.prototype[i]=function(){var a=document.createElement(i),b,c,d,e,f=(arguments[0]||{}).type||'text';if(YAHOO.env.ua.ie&&i=='input')a=document.createElement('<input type="'+f+'">');loop:for(var h=0,g=arguments.length;h<g;h++){b=arguments[h];switch(typeof b){case'object':e=b.node||b;if(e.nodeType===Ojay.HTML.ELEMENT_NODE){a.appendChild(e)}else{for(c in b){if(Number(c)==c)continue;if(c=='style')for(d in b[c])a.style[d]=b[c][d];else a[c]=b[c]}}break;case'function':b(new Ojay.HtmlBuilder(a));break;case'string':a.appendChild(document.createTextNode(b));break}}if(this._4)this._4.appendChild(a);return a}},TAG_NAMES:("a abbr acronym address applet area b base basefont bdo big blockquote body "+"br button caption center cite code col colgroup dd del dfn dir div dl dt em "+"embed fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i "+"iframe img input ins isindex kbd label legend li link map menu meta noframes "+"noscript object ol optgroup option p param pre q s samp script select small "+"span strike strong style sub sup table tbody td textarea tfoot th thead title "+"tr tt u ul var").split(/\s+/)}});Ojay.HtmlBuilder.addTagNames(Ojay.HtmlBuilder.TAG_NAMES);Ojay.HTML=new Ojay.HtmlBuilder();JS.extend(Ojay.HTML,{ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12});Ojay.Animation=new JS.Class({initialize:function(a,b,c,d){this._5=a;this._l=b||{};this._m=c||1.0;this._9=d||{};this._n=YAHOO.util.Easing[this._9.easing||'easeBoth'];var e=this._9.after,f=this._9.before;this._o=e&&Function.from(e);this._p=f&&Function.from(f);this.chain=new JS.MethodChain},_e:function(a,b,c){if(typeof a=='function')a=a(c,b);if(typeof a!='object')return a;var d={};for(var e in a)d[e]=arguments.callee(a[e],b,c);return d}.curry(),run:function(){var f=this._5.map(this._e(this._l));var h=this._5.map(this._e(this._m));var g=h.reduce(function(a,b){return a>b?a:b},-Infinity);var i=false;var j=this._o,k=this._p;this._5.forEach(function(a,b){var c=f[b],d=h[b];var e=new YAHOO.util.ColorAnim(a.node,c,d,this._n);e.onComplete.subscribe(function(){if(YAHOO.env.ua.ie&&(c.opacity||{}).to!==undefined)a.setStyle({opacity:c.opacity.to});if(j)j(a,b);if(d==g&&!i){i=true;this.chain.fire(this._5)}}.bind(this));if(k)k(a,b);e.animate()},this)}});(function(f){Ojay.Region=new JS.Class({contains:f.prototype.contains,getArea:f.prototype.getArea,_q:f.prototype.intersect,_r:f.prototype.union,initialize:function(b){['top','right','bottom','left'].forEach(function(a){this[a]=b[a]||0},this)},getWidth:function(){return this.right-this.left},getHeight:function(){return this.bottom-this.top},getDiagonal:function(){return(this.getWidth().pow(2)+this.getHeight().pow(2)).sqrt()},getCenter:function(){return{left:(this.left+this.right)/2,top:(this.top+this.bottom)/2}},shift:function(a,b){this.left+=a;this.right+=a;this.top+=b;this.bottom+=b;return this},scale:function(a){var b=this.getWidth(),c=this.getHeight();if(b<=0||c<=0)return this;var d=(a-1)*b,e=(a-1)*c;this.left-=d/2;this.right+=d/2;this.top-=e/2;this.bottom+=e/2;return this},intersection:function(a){var b=this._q(a);return new Ojay.Region(b)},intersects:function(a){var b=Math.max(this.top,a.top),c=Math.min(this.bottom,a.bottom),d=Math.max(this.left,a.left),e=Math.min(this.right,a.right);return(b<c)&&(d<e)},union:function(a){var b=this._r(a);return new Ojay.Region(b)},toString:function(){return'('+this.left+','+this.top+') ['+this.getWidth()+'x'+this.getHeight()+']'},extend:{convert:function(a){if(a instanceof f)return new this(a);if(!(a instanceof this))a=Ojay(a).getRegion();if(!a)return undefined;else return a}}})})(YAHOO.util.Region);Ojay.Sequence=new JS.Class({initialize:function(a,b,c){this._f=a;this._6=0;this._s=Function.from(b);this._t=c||null;this._7=null;this._0=false;this._a=false},_u:function(){this._s.call(this._t,this._f[this._6])},stepForward:function(){if(this._0===null){this._0=false;return this}this._u();this._6++;if(this._6>=this._f.length){this._6=0;if(this._a)this._0=this._a=false}if(this._0)setTimeout(this.method('stepForward'),this._7);return this},loop:function(a){this._7=1000*Number(a||0)||this._7;if(!this._7||this._0)return this;this._0=true;return this.stepForward()},pause:function(){if(this._0)this._0=null;return this},finish:function(){if(this._0)this._a=true;return this}});Array.prototype.sequence=function(a){return new Ojay.Sequence(this,a)};Ojay.DomCollection.include({sequence:function(b){return[].map.call(this,function(a){return Ojay(a)}).sequence(b)}});JS.MethodChain.addMethods(Ojay);JS.MethodChain.addMethods(Ojay.HTML);JS.MethodChain.prototype._=JS.MethodChain.prototype._.wrap(function(){var a=Array.from(arguments),b=a.shift();if(typeof a[0]=='string')return b(Ojay,a[0]);else return b.apply(this,a)});Ojay.VERSION='0.2.2';