﻿/*
 * JavaScript Library
 * Copyright (c) 2008, TH_NK
 * Author: Michael Ord
 * Version: 1.0
 */

var core={};core.stylesheet={load:function(filename)
{var tmp_links=document.getElementsByTagName('link');var tmp_regEx=/\/([a-zA-Z0-9-_]+).css$/;for(var i=0;i<tmp_links.length;i++)
{var tmp_ref=tmp_links[i];if(tmp_ref.getAttribute('rel'))
{if(tmp_ref.getAttribute('rel').toLowerCase()=='stylesheet')
{var tmp_src=tmp_ref.getAttribute('href');var tmp_matches=tmp_src.match(tmp_regEx);if(tmp_matches){var tmp_href=tmp_ref.getAttribute('href').replace(tmp_matches[1],filename);var tmp_el=YAHOO.util.Dom.create('link',{rel:'stylesheet',href:tmp_href,type:'text/css'});var tmp_head=document.getElementsByTagName('head')[0];tmp_head.appendChild(tmp_el);return true;};}}}
return false;},unload:function(filename)
{var tmp_links=document.getElementsByTagName('link');var tmp_regEx=/\/([a-zA-Z0-9-_]+)\.css/;for(var i=0;i<tmp_links.length;i++)
{var tmp_ref=tmp_links[i];if(tmp_ref.getAttribute('rel'))
{if(tmp_ref.getAttribute('rel').toLowerCase()=='stylesheet')
{var tmp_src=tmp_ref.getAttribute('href');var tmp_matches=tmp_src.match(tmp_regEx);if(tmp_matches){if(tmp_matches[1]==filename){var tmp_head=document.getElementsByTagName('head')[0];tmp_head.removeChild(tmp_ref);return true;}};}}}
return false;}}
YAHOO.util.Dom.create=function(tagName){_util={_makeTxtObject:function(txt)
{return document.createTextNode(txt);},_makeChildren:function(arr,elm)
{for(var i in arr){_val=arr[i];if(typeof _val=='string'){_val=this._makeTxtObject(_val);};if(typeof(_val)=='function'){continue;}
elm.appendChild(_val);};},_makeStyleObject:function(attrsObj,elm)
{for(var i in attrsObj){switch(i.toLowerCase())
{case'listener':if(attrsObj[i]instanceof Array){var ev=attrsObj[i][0];var func=attrsObj[i][1];var base=attrsObj[i][2];var scope=attrsObj[i][3];YAHOO.util.Event.addListener(elm,ev,func,base,scope);};break;case'classname':case'class':elm.className=attrsObj[i];break;case'style':var _tmp=attrsObj[i].replace(' ','');_tmp=_tmp.split(';');for(x in _tmp)
{if(x){var __tmp=_tmp[x].replace(' ','');__tmp=_tmp[x].split(':');if(__tmp[0]&&__tmp[1]){var _attr=__tmp[0].replace(' ','');var _val=_util._trim(__tmp[1]);if(_attr&&_val){if(_attr.indexOf('-')!=-1){_attr=_util._fixStyle(_attr);};eval('elm.style.'+_attr+' = "'+_val+'";');};};};};break;default:elm.setAttribute(i,attrsObj[i]);break;}}},_fixStyle:function(str){var _tmp=str.split('-');var _new_style=_tmp[0];for(var i=1;i<_tmp.length;i++){_new_style+=_tmp[i].substring(0,1).toUpperCase()+_tmp[i].substring(1,_tmp[i].length);};return _new_style;},_trim:function(str){return str.replace(/^\s+/g,'').replace(/\s+$/g,'');}};tagName=tagName.toLowerCase();elm=document.createElement(tagName);var txt=false;var attrsObj=false;if(!elm){return false;};for(var i=1;i<arguments.length;i++){txt=arguments[i];if(typeof txt=='string'){_txt=_util._makeTxtObject(txt);elm.appendChild(_txt);}else if(txt instanceof Array){_util._makeChildren(txt,elm);}else if(typeof txt=='object'){_util._makeStyleObject(txt,elm);};};return elm;}
if(!String.prototype.trim)
{String.prototype.trim=function()
{return this.replace(/^\s*/,'').replace(/\s*$/,'');};};String.prototype.reverse=function()
{var s='';for(var i=this.length-1;i>=0;i--)
{s+=this.charAt(i);};return s;};String.prototype.normalize=function()
{return this.replace(/\s+/g," ");};YAHOO.util.Dom.toggleClass=function(el,className)
{if(YAHOO.util.Dom.hasClass(el,className))
{YAHOO.util.Dom.removeClass(el,className);}else
{YAHOO.util.Dom.addClass(el,className);};};YAHOO.util.Dom.getAncestorsByClass=function(obj,className,tag,iterations,findFirst)
{className=className||false;tag=tag||false;obj=YAHOO.util.Dom.get(obj);if(!obj){return false;};var ancestors=new Array;var parent=obj.parentNode;var iteration=iterations||20;while(parent&&iteration--){if(YAHOO.util.Dom.hasClass(parent,className)||!className){if(!tag||(tag&&parent.nodeName.toLowerCase()==tag)){ancestors.push(parent);if(findFirst){return parent;};};};parent=parent.parentNode;};return ancestors.length?ancestors:false;};YAHOO.util.Dom.getElementsBySelector=function(selector)
{if(!document.getElementsByTagName){return new Array;};var getAllChildren=function(e){return e.all?e.all:e.getElementsByTagName('*');};var tokens=selector.split(' ');var currentContext=new Array(document);for(var i=0;i<tokens.length;i++)
{token=tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');if(token.indexOf('#')>-1){var bits=token.split('#');var tagName=bits[0];var id=bits[1];var element=YAHOO.util.Dom.get(id);if(!element){return new Array;}
if(tagName&&element.nodeName.toLowerCase()!=tagName){return new Array;};currentContext=new Array(element);continue;};if(token.indexOf('.')>-1){var bits=token.split('.');var tagName=bits[0];var className=bits[1];if(!tagName){tagName='*';};var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++)
{var elements=tagName=='*'?getAllChildren(currentContext[h]):currentContext[h].getElementsByTagName(tagName);for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j];};};currentContext=new Array;var currentContextIndex=0;for(var k=0;k<found.length;k++)
{if(found[k].className&&found[k].className.match(new RegExp('\\b'+className+'\\b'))){currentContext[currentContextIndex++]=found[k];};};continue;};if(token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)){var tagName=RegExp.$1;var attrName=RegExp.$2;var attrOperator=RegExp.$3;var attrValue=RegExp.$4;if(!tagName){tagName='*';};var found=new Array;var foundCount=0;var elements;for(var h=0;h<currentContext.length;h++)
{if(tagName=='*'){elements=getAllChildren(currentContext[h]);}else{elements=currentContext[h].getElementsByTagName(tagName);};for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j];};};currentContext=new Array;var currentContextIndex=0;var checkFunction;switch(attrOperator){case'=':checkFunction=function(e){return(e.getAttribute(attrName)==attrValue);};break;case'~':checkFunction=function(e){return(e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b')));};break;case'|':checkFunction=function(e){return(e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?')));};break;case'^':checkFunction=function(e){return(e.getAttribute(attrName).indexOf(attrValue)==0);};break;case'$':checkFunction=function(e){return(e.getAttribute(attrName).lastIndexOf(attrValue)==e.getAttribute(attrName).length-attrValue.length);};break;case'*':checkFunction=function(e){return(e.getAttribute(attrName).indexOf(attrValue)>-1);};break;default:checkFunction=function(e){return e.getAttribute(attrName);};};currentContext=new Array;var currentContextIndex=0;for(var k=0;k<found.length;k++)
{if(checkFunction(found[k])){currentontext[currentContextIndex++]=found[k];};};continue;};if(!currentContext[0]){return;};tagName=token;var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++)
{var elements=currentContext[h].getElementsByTagName(tagName);for(var j=0;j<elements.length;j++){found[foundCount++]=elements[j];};};currentContext=found;};return currentContext;};