//Array functions
/*
------------------------
E_DOM
------------------------
*/
function $A(obj){
var arr = [];
for(var i = 0; i < obj.length; i++){
arr.push(obj[i]);
}
return arr;
}
var $break = new Object();
var $continue = new Object();
Array.prototype.each = function(iterator){
try{
for(var i = 0; i < this.length; i++){
try{
var ret = iterator(this[i], i);
if(ret != null){
this[i] = ret;
}
}catch(e){
if(e != $continue)
throw e;
}
}
}catch(e){
if(e != $break)
throw e;
}
return this;
}
Array.prototype.random = function(){
return this[Math.round(Math.random() * (this.length - 1))];
}
Array.prototype.last = function(){
return this[this.length - 1];
}
Array.prototype.invert = function(){
var new_arr = [];
for(var i = this.length - 1; i >= 0; i --){
new_arr.push(this[i])
}
return new_arr;
}
Array.prototype.remove = function(num){
if(num >= this.length || num < 0)
return;
for(var i = num; i < this.length - 1; i++){
this[i] = this[i+1];
}
this.pop();
}
Array.prototype.insert = function(value, position){
position = position ? position : 0;
if(position >= this.length){
this.push(value);
return;
}
for(var i = this.length - 1; i >= position; i--){
this[i+1] = this[i];
}
this[position] = value;
}
if(typeof Array.prototype.indexOf == "undefined"){
Array.prototype.indexOf = function(item){
var index = -1;
this.each(function(it, ind){
if(it == item){
index = ind;
throw $break;
}
});
return index;
}
}
Array.prototype.toStart = function(item){
var ind = this.indexOf(item);
if(ind == -1){
return false;
}
var itm = this[ind];
var buff1 = this[0];
var buff2 = this[0];
for(var i = 1; i <= ind; i++){
buff1 = this[i];
this[i] = buff2;
buff2 = buff1;
}
this[0] = itm;
}
Array.prototype.toEnd = function(item){
var ind = this.indexOf(item);
if(ind == -1){
return false;
}
var itm = this[ind];
for(var i = ind; i < this.length - 1; i++){
this[i] = this[i + 1];
}
this[this.length - 1] = itm;
}

Array.prototype.previous = function(item){
var ind = this.indexOf(item);
if(ind <= 0){
return false;
}
return this[ind - 1];
}
Array.prototype.next = function(item){
var ind = this.indexOf(item);
if(ind < 0 || ind == this.length - 1){
return false;
}
return this[ind + 1];
}

//Number functions
Number.prototype.signOf = function(){
if(this == 0){
return 1;
}else{
return Math.abs(this) / this;
}
}
Number.prototype.sq = function(){
return this * this;
}


//String functions
String.prototype.camelize = function(){
var arrThis = this.split('-');
if(arrThis.length == 1){
return this;
}else{
var wordCamelized = arrThis[0];
var firstSymbol;
for(var i = 1; i < arrThis.length; i++){
firstSymbol = arrThis[i].substr(0, 1);
arrThis[i] = arrThis[i].substr(1);
arrThis[i] = firstSymbol.toUpperCase() + arrThis[i];
wordCamelized+=arrThis[i];
}
return wordCamelized;
}
}
String.prototype.s_each = function(iterator){
var arr = this.split('');
arr.each(iterator)
}
String.prototype.no_print_characters_only = function(){
var ret = true;
this.s_each(function(chr){
if(chr.charCodeAt(0) >= 30){
ret = false;
throw $break;
}
});
return ret;
}
String.prototype.splitBy = function(num){
if(num <= 1){
return this.split('')
}
var splitted = [];
var start = 0;
for(var i = 0; i < this.length; i+=num){
splitted.push(this.substr(i, num))
}
return splitted;
}
//Object functions
function MergeObjects(obj1, obj2){
for(var i in obj1){
obj2[i] = obj1[i];
}
return obj2;
}


//DOM functions
function $(){
if(arguments.length == 0){
return false;
}else if(arguments.length == 1){
return _$(arguments[0]);
}else{
var arr = [];
for(var i = 0; i < arguments.length; i++){
var node = _$(arguments[i]);
if(node){
arr.push(node);
}
}
if(arr.length){
return arr;
}else{
return false;	
}
}
}
function _$(arg){
if(typeof arg == "string"){
return document.getElementById(arg);
}else if(typeof arg == "object" && typeof arg.nodeType != "undefined"){
return arg;
}else{
return false;
}
}
function $T(tName, parent){
parent = parent ? parent : document;
return $A(parent.getElementsByTagName(tName));
}

function $F(ipt){
ipt = $(ipt);
var node_names = ["SELECT", "INPUT", "TEXTAREA"];
var node_name = "";
var types = [];
var ret = true;
for(var i = 0; i < node_names.length; i++){
if(ipt.nodeName == node_names[i]){
node_name = node_names[i];
}
}
if(!node_name)
return;

return $F[node_name.toLowerCase()](ipt);
}
$F.select = function(objSel){
if(!!objSel.value){
return objSel.value;
}else{
var ops = $T("OPTION", objSel);
return ops[objSel.selectedIndex].innerText;
}
};
$F.textarea = function(objTArea){
return objTArea.value;
};
$F.input = function(objIpt){
return objIpt.value;
};
function $C(className, parent, tagName){
parent = (parent) ? parent : document;
tagName = tagName ? tagName : "*";
var arr = [];
var collection = $T(tagName, parent);
for(var i = 0; i < collection.length; i++){
if(hasClassName(collection[i], className)){
arr.push(collection[i]);
}
}
if(arr.length != 0){
return arr;
}else{
return false;
}
}
function $S(cssSelector){
var arr = cssSelector.split(" ");
for(var i = 0; i < arr.length; i++){
var type = "_tag";
if(arr[i].charAt(0) == "."){
type = "_class";
}else if(arr[i].charAt(0) == "#"){
type = "_id";
}
$S[type](arr[i]);
}
}
$S._tag = function(){};
$S._class = function(){};
$S._id = function(){};


function $TEXT(elem, no_text){
if(!elem){
return;
}
var arr = [];
var children = $A(elem.childNodes);
children.each(function(child){
if(child.nodeType == 3){
if(no_text){
arr.push(child);
}else{
if(!child.nodeValue.no_print_characters_only()){
arr.push(child);
}
}
}
});
return arr;
}

//Function functions
Function.prototype.bind = function(){
var _args = [];
var _method = this;
var _object = arguments[0];
for(var i = 1; i < arguments.length; i++){
_args.push(arguments[i]);
}
var retfunc = function(){
return _method.apply(_object, $A(arguments).concat(_args));
}
retfunc.bound = $A(arguments);
return retfunc;
}
Function.prototype.bindAvoidingEvent = function(){
var _args = [];
var _method = this;
var _object = arguments[0];
for(var i = 1; i < arguments.length; i++){
_args.push(arguments[i]);
}
var retfunc = function(){
return _method.apply(_object, $A(_args).concat(arguments));
}	
retfunc.bound = $A(arguments);
return retfunc;
}
Function.prototype.bindArray = function(arr){
var _args = [];
var _method = this;
var _object = arr[0];
for(var i = 1; i < arr.length; i++){
_args.push(arr[i]);
}
var retfunc = function(){
return _method.apply(_object, $A(arguments).concat(_args));
}
retfunc.bound = arr;
return retfunc;
}
Function.prototype.bindMore = function(){
if(!this.bound){
return;
}
return this.bindArray(this.bound.concat(arguments));

}

//Else functions
function _isChild(elem, parent){
if(!elem)
return false;
var par = elem.parentNode;
while(par && par != parent && par.tagName.toUpperCase() != "HTML"){
par = par.parentNode;
}
return !par ? false : (par == parent);
}
function hasClassName(elem, className){
var ret = false;
var reg_className = new RegExp('^' + className + '$');
var classes = elem.className.split(' ');
classes.each(
function(classN){
if(classN.match(reg_className)){
ret = true;
throw $break;
}
}	
)
return ret;
}

//Debug functions
function toConsole(what, console){
console = console ? console : typeof document.body != "undefined" ? document.body : null;
if(!console){
document.write(what);
}
var oDiv = document.createElement('DIV');
oDiv.appendChild(document.createTextNode(what));
console.appendChild(oDiv);
}
var print = toConsole;
function printObject(obj, console){
for(var i in obj){
print(i + " => " + obj[i], console);
}
}
function clearElem(elem){
while(elem.firstChild){
elem.removeChild(elem.firstChild);
}
}
function Line(width, color, weight, parent){
if(!width){
width = 100;
}
if(!color){
color = "#000";
}	
if(!weight){
weight = 1;
}
if(!parent){
parent = document.body;
}
var line = document.createElement("DIV");
line.style.width = width + "px";
line.style.border = "solid " + weight + "px " + color;
line.style.margin = "5px 10px";
line.style.fontSize = "0";
parent.appendChild(line);
}
/*
------------------------
e_dom end
------------------------
*/

/*
------------------------
DOMEvent
------------------------
*/
function DOMEvent(){
this.listeners = [];
}
DOMEvent.prototype.register = function(name, lnr, callslimit){
if(this.hasNamedListener(name)){
return;
}
var ev = {
name: name,
func: lnr,
calls: 0,
callslimit: callslimit ? callslimit : -1
};
this.listeners.push(ev);
}
DOMEvent.prototype.remove = function(name){
this.listeners.each(
function(lnr, index){
if(lnr.name == name){
this.listeners.remove(index);
throw $break;
}
}.bind(this)
);	
}
DOMEvent.prototype.fire = function(){
var args = arguments;
this.listeners.each(
function(lnr){
var obj = lnr.func.bound ? lnr.func.bound[0] : this.defaultThis || lnr;
lnr.func.apply(obj, args);
lnr.calls++;
if(lnr.calls == lnr.callslimit){
this.remove(lnr.name)
}
}.bind(this)
)
}
DOMEvent.prototype.length = function(){
return this.listeners.length;
}
DOMEvent.prototype.hasNamedListener = function(name, no_bool){
var ret = false;
this.listeners.each(
function(lnr){
if(lnr.name == name){
ret = lnr;
throw $break;
}
}
);
return !no_bool ? !!(ret) : ret;
}
DOMEvent.prototype.get = function(name){
return this.hasNamedListener(name, true);
};
DOMEvent.prototype.toString = function(){
var str = "object DOMEvent\n";
str += "\n";
str += "Listeners: ";
this.listeners.each(function(lnr){
str += lnr.name + ", ";
});
var reg = new RegExp(", $");
str = str.replace(reg, "");
str += "\nListeners length: " + this.listeners.length;
return str;
}
DOMEvent.cloneEvent = function(d_event, obj){
var ret = obj ? false : true;
obj = obj ? obj : {};
obj.register = function(name, lnr, callslimit){
d_event.register(name, lnr, callslimit);
}
obj.remove = function(name){
d_event.remove(name)
}
obj.length = function(){
return d_event.length();
}
obj.hasNamedListener = function(name){
return d_event.hasNamedListener(name);
}
obj.get = function(name){
return d_event.get(name);
}
obj.eachLnr = function(iterator){
d_event.eachLnr(iterator);
}
obj.toString = function(){
return d_event.toString();
}
if(ret){
return obj;
}
}
DOMEvent.createEventLink = function(obj, name){
obj["_" + name] = new DOMEvent();
obj[name] = function(){
this["_" + name].fire();
}
DOMEvent.cloneEvent(obj["_" + name], obj[name]);
obj[name].register = function(n, func, callslimit){
func = func.bound ? func : func.bind(obj);
obj["_" + name].register(n, func, callslimit);
}
}
DOMEvent.linkObjects = function(elem, d_event, name){
elem.d_event = d_event;
elem[name] = function(){
this.d_event.fire.apply(this.d_event, arguments);
}
}
DOMEvent.createLinkedEvent = function(elem, name){
var d_event = new DOMEvent();
DOMEvent.linkObjects(elem, d_event, name);
return d_event;
}
function MajorDOMEvent(){
this.name = name ? name : "major_dom_event";
this.listeners = [];
}
MajorDOMEvent.prototype.register = DOMEvent.prototype.register;
MajorDOMEvent.prototype.remove = DOMEvent.prototype.remove;
MajorDOMEvent.prototype.hasNamedListener = DOMEvent.prototype.hasNamedListener;
MajorDOMEvent.prototype.length = DOMEvent.prototype.length;
MajorDOMEvent.prototype._link = function(d_event, arg){
d_event.register(this.name, function(){
this.listeners.each(function(lnr){
lnr.func(arg);
}.bind(this))
}.bind(this))
}
MajorDOMEvent.cloneEvent = function(m_d_event){
var obj = {};
obj.register = function(name, lnr, callslimit){
m_d_event.register(name, lnr, callslimit)
}
obj.remove = function(name){
m_d_event.remove(name)
}
obj.length = function(){
return m_d_event.length();
}
obj.hasNamedListener = function(name){
return m_d_event.hasNamedListener(name);
}
obj._link = function(d_event, arg){
m_d_event._link(d_event, arg);
}
return obj;
}
/*
------------------------
dom_event end
------------------------
*/
/*
------------------------
STYLE
------------------------
*/
String.prototype.camelize = function(){
var arrThis = this.split('-');
if(arrThis.length == 1){
return this;
}else{
var wordCamelized = arrThis[0];
var firstSymbol;
for(var i = 1; i < arrThis.length; i++){
firstSymbol = arrThis[i].substr(0, 1);
arrThis[i] = arrThis[i].substr(1);
arrThis[i] = firstSymbol.toUpperCase() + arrThis[i];
wordCamelized+=arrThis[i];
}
return wordCamelized;
}
}
var Style = {
_check_browser: function(){
if(window.getComputedStyle){
if(window.opera)	{
return "Opera";
}else{
return "Gecko";
}
}else{
return "IE";
}
},
_browser_version: function(){
return this["_" + this._browser + "_version"]();
},
_IE_version: function(){
var i = navigator.appVersion.indexOf("MSIE") + 5;
var version = "";
while(navigator.appVersion.charAt(i) != ";"){
version += navigator.appVersion.charAt(i);
i++;
}
return version;
},
_Gecko_version: function(){
if(navigator.userAgent.indexOf("Firefox") == -1){
return "unknown";
}
var i = navigator.userAgent.indexOf("Firefox\/") + 8;
return navigator.userAgent.substr(navigator.userAgent.indexOf("Firefox\/") + 8);

},
_Opera_version: function(){
return navigator.appVersion.substring(0, navigator.appVersion.indexOf(" "));
},
getElementStyle: function(elem, property){
var ME = arguments.callee;
var value = null;
if(window.getComputedStyle)		{
var compStyle = window.getComputedStyle(elem, '');
value = compStyle.getPropertyValue(property);
}else if(elem.currentStyle){
if(property == "float")
property = "style-float";
value  = elem.currentStyle[property.camelize()]; //!!String.camelize()
}
if(typeof value != "undefined")
return value;
},
getBorder: function(elem){
var bLeft = parseInt(Style.getElementStyle(elem, 'border-left-width'));
var bRight = parseInt(Style.getElementStyle(elem, 'border-right-width'));
var bTop = parseInt(Style.getElementStyle(elem, 'border-top-width'));
var bBottom = parseInt(Style.getElementStyle(elem, 'border-bottom-width'));
var bX = bRight + bLeft;
var bY = bTop + bBottom;
return {
left: isNaN(bLeft) ? 0 : bLeft,
top: isNaN(bTop) ? 0 : bTop,
right: isNaN(bRight) ? 0 : bRight,
left: isNaN(bLeft) ? 0 : bLeft,
x: isNaN(bX) ? 0 : bX,
y: isNaN(bY) ? 0 : bY
};
},
getMargin: function(elem){
var mLeft, mRight, mTop, mBottom;
mLeft = parseInt(Style.getElementStyle(elem, 'margin-left'));
mRight = parseInt(Style.getElementStyle(elem, 'margin-right'));
mTop = parseInt(Style.getElementStyle(elem, 'margin-top'));
mBottom = parseInt(Style.getElementStyle(elem, 'margin-bottom'));
return {
left: isNaN(mLeft) ? 0 : mLeft,
right: isNaN(mRight) ? 0 : mRight,
top: isNaN(mTop) ? 0 : mTop,
bottom: isNaN(mBottom) ? 0 : mBottom
}
},
getPadding: function(elem){
var pLeft, pRight, pTop, pBottom;
pLeft = parseInt(Style.getElementStyle(elem, 'padding-left'));
pRight = parseInt(Style.getElementStyle(elem, 'padding-right'));
pTop = parseInt(Style.getElementStyle(elem, 'padding-top'));
pBottom = parseInt(Style.getElementStyle(elem, 'padding-bottom'));
return {
left: pLeft,
right: pRight,
top: pTop,
bottom: pBottom
}
},
getOffset: function(elem){
return {left: elem.offsetLeft, top: elem.offsetTop};
},
getRelativeOffset: function(elem){
var oOffset = this.getOffset(elem);
var parents = this._getParents(elem);
var eachFunc = this["correct" + this._browser];
var no_go = false;
parents.each(
function(item, index){
no_go = eachFunc(item, oOffset, no_go);

}
);//each
return oOffset;
},
correctOpera: function(item, oOffset, no_go){
if(no_go)
return true;
var pos = Style.getElementStyle(item, "position");
if(pos == "relative" || pos == "absolute"){
var oBorder = Style.getBorder(item);
oOffset.left -= oBorder.left;
oOffset.top -= oBorder.top;
return true;
}
return false;
},
correctIE: function(item, oOffset){
var pos = Style.getElementStyle(item, "position");
var hght = Style.getElementStyle(item, "height");
var flt = Style.getElementStyle(item, "float");
if(pos == "relative"){
if(hght == "auto" && flt == "none"){
var oBorder = Style.getBorder(item);
oOffset.left -= oBorder.left;
oOffset.top -= oBorder.top;
var oMargin = Style.getMargin(item);
if(oMargin.left != 0){
var iOffset = Style.getOffset(item);
oOffset.left -= iOffset.left;
}

}
}else if(pos == "absolute"){
}else{
if(hght != "auto" || flt != "none"){
var iOffset = Style.getOffset(item);
var oBorder = Style.getBorder(item);
oOffset.left += iOffset.left;
oOffset.top += iOffset.top;
oOffset.left += oBorder.left;
oOffset.top += oBorder.top;
}
}
return false;
},
correctGecko: function(){
return false;
},
getAbsoluteOffset: function(elem){
var oOffset = this.getRelativeOffset(elem);
var parents = this._getParents(elem);
parents.each(
function(item, index){
var pos = Style.getElementStyle(item, 'position');
if(pos == 'relative' || pos == 'absolute'){
var iOffset = Style.getRelativeOffset(item);
var iBorder = Style.getBorder(item);
oOffset.left += iOffset.left;
oOffset.top += iOffset.top;
oOffset.left += iBorder.left;
oOffset.top += iBorder.top;
}
}
);
return oOffset;
},
getDimensions: function(elem){
var width, height;
width = parseInt(this.getElementStyle(elem, "width"));
if(isNaN(width))
width = elem.offsetWidth;
height = parseInt(this.getElementStyle(elem, "height"));
if(isNaN(height))
height = elem.offsetHeight;
return {width: width, height: height};
},
setElementStyle: function(objElem, propName, propVal, usePx){
var elem = (typeof objElem == "string") ? document.getElementById(objElem) : objElem;
if(typeof propName == "string"){
if(usePx && (typeof propVal == "number")){
propVal += "px";
}
elem.style[propName] = propVal;
}else if(typeof propName == "object"){
for(var i in propName){
var val = propName[i];
if(typeof val == "number" && usePx){
val += "px";
}//if
elem.style[i] = val;
}//for
}//if-else-if
//End of FUCNTION
},
getCoords: function(elem){
var left = parseInt(this.getElementStyle(elem, 'left'));
var top = parseInt(this.getElementStyle(elem, 'top'));
var right = parseInt(this.getElementStyle(elem, 'right'));
var bottom = parseInt(this.getElementStyle(elem, 'bottom'));
left = isNaN(left) ? 0 : left;
top = isNaN(top) ? 0 : top;
right = isNaN(right) ? 0 : right;
bottom = isNaN(bottom) ? 0 : bottom;
return {
left: left,
top: top,
right: right,
bottom: bottom
}

}
}
Style._getParents = function(elem){
var pars = [];
elem = elem.parentNode;
while(elem.tagName.toUpperCase() != "BODY"){
pars.push(elem);
elem = elem.parentNode;
}
return pars;
}
Style._getRelativeParent = function(elem){
var pars = this._getParents(elem);
var relItem;
for(var i = 0; i < pars.length; i++){
var item = pars[i];
if(Style.getElementStyle(item, "position") == "relative"){
return item;
}
}
}
Style._browser = Style._check_browser();
Style._br_version = Style._browser_version();
/*
------------------------
style end
------------------------
*/
/*
------------------------
LIMIT
------------------------
*/
function Limit(from, to){
this.from = from;
this.to = to;
this.value = this.from;
this.onmore = new DOMEvent();
this.onless = new DOMEvent();
this.onchange = new DOMEvent();
this.TO_REACHED = false;
this.FROM_REACHED = true;
this.MORE_VALUE = 0;
this.LESS_VALUE = 0;
}
Limit.prototype.change = function(val){
if(val == 0)
return;
var value = val;
this.TO_REACHED = false;
this.FROM_REACHED = false;
value = this.checkFrom(value);
value = this.checkTo(value);
this.value += value;
this.onchange.fire();
if(this.TO_REACHED){
this.onmore.fire();
}
if(this.FROM_REACHED){
this.onless.fire();
}
}
Limit.prototype.setValue = function(val){
var value = this.val - this.from;
this.change(value);
}
Limit.prototype.checkTo = function(val){
var value = val;
if(this.value + value >= this.to){
value = this.to - this.value;
this.MORE_VALUE = value;
this.TO_REACHED = true;
}
return value;
}
Limit.prototype.checkFrom = function(val){
var value = val;
if(this.value + value <= this.from){
//toConsole(this.value);
value = -this.value + this.from;
this.LESS_VALUE = value;
this.FROM_REACHED = true;
}
return value;
}
/*
------------------------
limit end
------------------------
*/
/*
------------------------
TIMER
------------------------
*/
function Timer(intervalValue){
this.intervalValue = intervalValue ? intervalValue : 500;
this.interval = null;
this.events = [];
this.listeners = [];
this.onstart = new DOMEvent();
this.onstop = new DOMEvent();
this.isTicking = false;
}
Timer.prototype.start = function(){
this.calls = 0;
this.timeElapsed = 0;
this.interval = setInterval(
this.intervalFunction.bind(this),
this.intervalValue
);
this.isTicking = true;
this.onstart.fire();
}
Timer.prototype.intervalFunction = function(){
this.calls ++;
this.timeElapsed += this.intervalValue;
this.events.each(function(ev, index){
if(this.calls % ev.freq == 0){
var ret = ev.func.apply(ev.oThis, ev.args);
if(typeof ret != 'undefined' && ret !== false){
this.listeners.each(function(lnr, index){
if(lnr.name == ev.name){
lnr.func.apply(lnr.oThis, [ret])
}
})
}
}
}.bind(this))
}
Timer.prototype.registerEvent = function(obj){
if(!obj.freq){
obj.freq = 1;
}
this.events.push(obj);
}
Timer.prototype.registerEventListener = function(obj){
this.listeners.push(obj);
}
Timer.prototype.clear = function(){
clearInterval(this.interval);
this.isTicking = false;
this.onstop.fire();
}
Timer.prototype.toggle = function(){
if(this.isTicking){
this.clear();
}else{
this.start();
}
}
Timer.prototype.restart = function(){
this.clear();
this.start();
}
/*
------------------------
timer end
------------------------
*/
/*
------------------------
NUMS
------------------------
*/
var Nums = {};//Namespace for function working with numbers
Nums.SaveFloatPoint = function(){
this.errVal = 0;
}
Nums.SaveFloatPoint.prototype.add = function(value){
var err = (Math.abs(value) - Math.floor(Math.abs(value))) * value.signOf();
var val = Math.floor(Math.abs(value)) * value.signOf();
this.errVal += err;
if(Math.abs(this.errVal) >= 1){
val += value.signOf();
this.errVal -= value.signOf();
}
return val;
}
Nums.SaveFloatPoint.prototype.refresh = function(){
this.errVal = 0;
}
Nums.Slide = function(from, to, step_num){
var value = 0;
var arr = [from + value];
var len = to - from;
var step = len / step_num;
var saveFloat = new this.SaveFloatPoint();
while(Math.abs(value) < Math.abs(len)){
value += saveFloat.add(step);
arr.push(from + value);
}
if(arr.length > step_num + 1){
arr.pop();
arr[arr.length - 1] = to;
}
return arr;
}
Nums.__hex_nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
Nums.Hex2Dec = function(hex){
var num = 0;
var splitted = hex.split('').invert();
splitted.each(function(n, index){
num += this.__hex_nums.indexOf(n) * (16).power(index);
}.bind(this));
return Number(num);
}
Nums.Dec2Hex = function(dec){

}
Nums.toString = function(){
var str = " object Nums: "
for(var i in this){
if(i != "toString"){
str += "\n";
str += typeof this[i] + " " + i + "  :: ";
}
}
return str;
}
Nums.Positive = function(val){
this.val = 0;
this.onzero = new DOMEvent();
this.add(val);
}
Nums.Positive.prototype.add = function(val){
this.val = Nums.Positive._check(this.val + val);
if(this.val <= 0){
this.onzero.fire();
}
return this.val;
}
Nums.Positive.prototype.toString = function(){
return this.val;
}
Nums.Positive._check = function(val){
if(!val){
return 0;
}
return val >= 0 ? val : 0;
}
/*
------------------------
nums end
------------------------
*/
/*
------------------------
MOVEABLE
------------------------
*/
function moveable(elem, relative){
this.elem = elem;
this.type = relative ? 'relative' : 'absolute';
this.onmove = new DOMEvent();
this.onaftermove = new DOMEvent();
this.STOP_X = false;
this.STOP_Y = false;
this.STOP = false;
this.movedX = 0;
this.movedY = 0;
this.moveX = 0;
this.moveY = 0;
this.errX = 0;
this.errY = 0;
this.limits = {};
this.PREVENT_DOUBLE_FIRE = true;
this.init();
}
moveable.prototype.init = function(){
this.elem.style.position = this.type;
var coords = Style.getCoords(this.elem);
this.left = coords.left; 
this.top = coords.top;
this.startX = this.left;
this.startY = this.top;
}
moveable.prototype.move = function(){
this.elem.style.left = this.left + 'px';
this.elem.style.top = this.top + 'px';
this.onaftermove.fire();
}
moveable.prototype.moveTo = function(x, y){
this.moveBy(x - this.left, y - this.top);
}
moveable.prototype.moveBy = function(x, y){
this.moveX = Math.floor(Math.abs(x)) * x.signOf();
this.moveY = Math.floor(Math.abs(y)) * y.signOf();
this.errX += (Math.abs(x) - Math.floor(Math.abs(x))) * x.signOf();
this.errY += (Math.abs(y) - Math.floor(Math.abs(y))) * y.signOf();
if(Math.abs(this.errX) > 1){
this.moveX += 1 * x.signOf();
this.errX -= 1 * x.signOf();
}
if(Math.abs(this.errY) > 1){
this.moveY += 1 * y.signOf();
this.errY -= 1 * y.signOf();
}
this.onmove.fire();
this.movedX += this.moveX;
this.movedY += this.moveY;
this.distanceX += Math.abs(this.moveX);
this.distanceY += Math.abs(this.moveY);
this.left += this.moveX;
this.top += this.moveY;
if(!this.STOP){
this.move();
}else{
this.STOP = false;
}
}
moveable.prototype.setLimits = function(type, value, startValue){
type = type.toUpperCase();
if(this.limits[type]){
return;
}
var PRESETS = moveable.LIMITS[type]
this.limits[type] = new Limit(0, value);
if(startValue){
this.limits[type].value = startValue;
}
this.limits[type].type = type;
this.limits[type].MINUS_REACHED = false
this.limits[type].PLUS_REACHED = false;
this.limits[type]._REACHED = false;
this.limits[type].onmore.register(
'limit-more',
function(objLim){
this['move' + objLim.type] = objLim.MORE_VALUE;
objLim._REACHED = true;
objLim.MORE_REACHED = true;
}.bind(this, this.limits[type])
);
this.limits[type].onless.register(
'limit-less',
function(objLim){
this['move' + objLim.type] = objLim.LESS_VALUE;
objLim._REACHED = true;
objLim.LESS_REACHED = true;
}.bind(this, this.limits[type])
);
this[PRESETS.onmore] = DOMEvent.cloneEvent(this.limits[type].onmore);
this[PRESETS.onless] = DOMEvent.cloneEvent(this.limits[type].onless);
this[PRESETS.onmore].register = function(name, func, times){
this.limits[type].onmore.register(name, function(){
this.onaftermove.register(name, func, 1);
}.bind(this), times);
}.bind(this);
this[PRESETS.onless].register = function(name, func, times){
this.limits[type].onless.register(name, function(){
this.onaftermove.register(name, func, 1);
}.bind(this), times);
}.bind(this);
this.onmove.register(
'limit' + type, 
function(objLim){
objLim.change(this['move' + objLim.type]);
}.bind(this, this.limits[type])
);
}	
moveable.prototype.unsetLimits = function(type){
type = type.toUpperCase();
if(!this.limits[type]){
return;
}
this.onmove.remove('limit' + type);
var PRESETS = moveable.LIMITS[type];
this[PRESETS.onmore] = null;
this[PRESETS.onless] = null;
this.limits[type] = null;
}
moveable.prototype.resetLimits = function(type, value, startValue){
this.unsetLimits(type);
this.setLimits(type, value);
}
moveable.prototype.resetLimLBound = function(type, value){
this.limits[type.toUpperCase()].from = value;
}
moveable.prototype.resetLimUBound = function(type, value){
this.limits[type.toUpperCase()].to = value;	
}
moveable.prototype.setMoveSpace = function(X, Y){
this.moveSpace = {X: X, Y: Y};
this.setLimits('X', X);
this.setLimits('Y', Y);
this.onboundreach = {};
this.onboundreach.register = function(name, func){
}
return this.moveSpace;


}
moveable.LIMITS = {
X: {
onless: 'onleftlimitreach',
onmore: 'onrightlimitreach',
less: 'left',
more: 'right'
},
Y: {
onless: 'ontoplimitreach',
onmore: 'onbottomlimitreach',
less: 'top',
more: 'bottom'		
}
}
/*
------------------------
moveable end
------------------------
*/
/*
------------------------
MOVEMENT
------------------------
*/
function Movement(elem, timer){
this.elem = elem;
this.stepX = 0;
this.stepY = 0;
if(typeof timer == "number"){
this.hasOwnTimer = true;
this.Timer = new Timer(timer)

}else if(typeof timer == "object" && timer instanceof Timer){
this.hasOwnTimer = false;
this.Timer = timer;
}else{
throw "No timer specified";
}
this.distance = false;
this.moveSpace = false;
this.STOP_ON_FIRST = true;
this.onstart = new DOMEvent();
this.onstop = new DOMEvent();
this.refreshCount = 0;
this.isMoving = false;
this.onreach = new DOMEvent();
this.onreach.register(
Movement.defaultOnReach.name,
Movement.defaultOnReach.func.bind(this)
);
this.init();
}
Movement.prototype.init = function(){
this.Moveable = new moveable(this.elem, false);
this.onmove = {};
this.onmove = DOMEvent.cloneEvent(this.Moveable.onmove);
if(this.hasOwnTimer){
this.Timer.registerEvent(
{
name: "Movement",
func: function(objMoveable){
objMoveable.moveBy(this.stepX, this.stepY);
},
oThis: this,
args: [this.Moveable]
}
);
}else{
if(this.Timer.MOVEMENT_INITIALIZED){
this.Timer.registerMovement(this);
}else{	
Movement.handleMutualTimer(this.Timer);
this.Timer.registerMovement(this);
}
}
}
Movement.prototype.start = function(){
this.onstart.fire();
this.isMoving = true;
if(this.Timer){
this.Timer.start();
}
}
Movement.prototype.stop = function(){
this.onstop.fire();
this.isMoving = false;
if(this.Timer){
this.Timer.clear();
}
}
Movement.prototype.toggle = function(){
if(this.isMoving){
this.stop();
}else{
this.start();
}
}
Movement.prototype.setSteps = function(x, y){
this.stepX = x ? x : 0;
this.stepY = y ? y : 0;
}
Movement.prototype.setLimits = function(type, value, startValue){
this.Moveable.setLimits(type, value, startValue);
var PRESETS = moveable.LIMITS[type];
this[PRESETS.onless] = DOMEvent.cloneEvent(this.Moveable[PRESETS.onless]);
this[PRESETS.onmore] = DOMEvent.cloneEvent(this.Moveable[PRESETS.onmore]);
}
Movement.prototype.unsetLimits = function(type){
this.Moveable.unsetLimits(type);
}
Movement.prototype.resetLimits = function(type, value, startValue){
this.Moveable.resetLimits(type, value, startValue);
}
Movement.prototype.setMoveSpace = function(X, Y){
this.moveSpace = this.Moveable.setMoveSpace(X, Y);
if(!this.onmovespacereach){
this.onmovespacereach = DOMEvent.cloneEvent(this.Moveable.onmovespacereach);
}
}
Movement.prototype.moveTo = function(x, y, speed){
speed = speed ? speed : 3;
var curLeft = this.Moveable.left;
var curTop = this.Moveable.top;
var nextLeft = x;
var nextTop = y;
var distX = nextLeft - curLeft;
var distY = nextTop - curTop;
var biggerDist = Math.abs(distX) > Math.abs(distY) ? distX : distY;
var numOfSteps = Math.abs(Math.round(biggerDist / speed));
if(numOfSteps == 0){
return;
}
var stepX = distX / numOfSteps;
var stepY = distY / numOfSteps;
this.mt_stepCount = 0;
this.mt_numOfSteps = numOfSteps;
this.distY = distY;
this.distX = distX;
this.moveToX = nextLeft;
this.moveToY = nextTop;
this.setSteps(stepX, stepY);
this.Moveable.movedToX = 0;
this.Moveable.movedToY = 0;
this.Moveable.onmove.remove('move-to');
this.Moveable.onmove.register(
'move-to',
function(objMovement){
var STOP_X = false, STOP_Y = false;
if(Math.abs(this.movedToX + this.moveX ) >= Math.abs(objMovement.distX)){
this.moveX = (Math.abs(objMovement.distX) - Math.abs(this.movedToX)) * this.moveX.signOf();
STOP_X = true;
}
if(Math.abs(this.movedToY + this.moveY ) >= Math.abs(objMovement.distY)){
this.moveY = (Math.abs(objMovement.distY) - Math.abs(this.movedToY)) * this.moveY.signOf();
STOP_Y = true;
}
this.movedToX += this.moveX;
this.movedToY += this.moveY;
objMovement.mt_stepCount++;
if(STOP_X && STOP_Y){
//objMovement.stopMoveTo();
this.onaftermove.register(
'move-to-stop',
function(){
this.onreach.fire();
}.bind(objMovement),
1
);
}
}.bind(this.Moveable, this)
);
if(!this.isMoving){
this.start();
}
}
Movement.prototype.stopMoveTo = function(){
this.Moveable.onmove.remove('move-to');
this.stop();
}
Movement.prototype.moveDistance = function(distance, direction, numOfSteps){
this.distanceMoved = 0;
this.Distance = distance;
this.DistanceStep = this.Distance / numOfSteps;
this.stepType = (direction == "left" || direction == "right" ) ? "X" : "Y";
if(direction == 'left'){
this.setSteps(-this.DistanceStep, 0);
}else if(direction == 'right'){
this.setSteps(this.DistanceStep, 0);
}else if(direction == 'top'){
this.setSteps(0, -this.DistanceStep);
}else if(direction == 'bottom'){
this.setSteps(0, this.DistanceStep);
}
this.onmove.register("distance-check", function(oM){
var step_sign = oM["move" + this.stepType].signOf();
var step = Math.abs(oM["move" + this.stepType]);
if(this.distanceMoved + step >= this.Distance){
var new_step = this.Distance - this.distanceMoved;
//			toConsole(new_step);
oM["move" + this.stepType] = new_step * step_sign;
oM.onaftermove.register("stop", function(){
this.stop();
this.onmove.remove("distance-check");
}.bind(this), 1);
step = new_step;
}
this.distanceMoved += step;

}.bind(this, this.Moveable));
this.start();
}
Movement.defaultOnReach = {
name: 'onreach',
func: function(){
this.stopMoveTo();
}
}
Movement.mutualTimer = null;
Movement.handleMutualTimer = function(oTimer){
oTimer.movements = [];
oTimer.registerMovement = function(objMovement){
this.movements.push(objMovement)
}
oTimer.registerEvent(
{
name: "Movement",
func: function(){
this.movements.each(function(mov){
if(mov.isMoving){
mov.Moveable.moveBy(mov.stepX, mov.stepY);
}
});
},
oThis: oTimer,
args: []
}
);	
oTimer.MOVEMENT_INITIALIZED = true;
}
/*
------------------------
movement end
------------------------
*/
/*
------------------------
OPACITY
------------------------
*/
function Opacity(elem, oTimer){
this.elem = elem;
this.timer = typeof oTimer == "undefined" ? new Timer(50) : new Timer(oTimer);
this.currentProcess = "fade";
this.onafterfade = new DOMEvent();
this.onafterappear = new DOMEvent();
this.onchange = new DOMEvent();
this.saveFloat = new Nums.SaveFloatPoint();
this.step = 5;
this.IS_DOING = false;
this.init();

}
Opacity.prototype.init = function(){
this.initTimer();
if(Style._browser == "IE"){
this.elem.style.zoom  = 1;
}
this.currentOpacity = Opacity.getOpacity(this.elem);
this.currentVisibility = Opacity.getVisibility(this.elem);
}
Opacity.prototype.initTimer = function(){
if(this.timer._MUTUAL){
if(this.timer.registerOpacity){
this.timer.registerOpacity(this);
}else{
Opacity.handleMutualTimer(this.timer);
this.timer.registerOpacity(this);
}
}else{
this.timer.registerEvent({
name: "changer",
func: this.change,
oThis: this,
args: []
});
}
}
Opacity.prototype.setOpacity = function(value){
if(typeof value == "undefined" || value > 100 || value < 0)
return false;
value = this.saveFloat.add(value);
var styleValue = Opacity.styleStartText + (value / Opacity.styleCoeff) + Opacity.styleEndText;
Style.setElementStyle(this.elem, Opacity.styleProperty, styleValue);
this.currentOpacity = value;
}
Opacity.prototype.setVisible = function(){
Style.setElementStyle(this.elem, "visibility", "visible");
this.currentVisibility = "visible";
}
Opacity.prototype.setHidden = function(){
Style.setElementStyle(this.elem, "visibility", "hidden");
this.currentVisibility = "hidden";
}
Opacity.prototype.fade = function(value, sVal){
this.toValue = value ? value  : 0;
this.currentProcess = "fade";
this.step = sVal ? -Math.abs(sVal) : -Math.abs(this.step);
this.IS_DOING = true;
this.start();
}
Opacity.prototype.appear = function(value, sVal){
this.toValue = value ? value : 100;
this.currentProcess = "appear";
this.step = sVal ? Math.abs(sVal) : Math.abs(this.step);
this.start();
}
Opacity.prototype.change = function(){
var stop = false;
var nextVal = this.currentOpacity + this.step;
if(this.currentProcess == "fade"){
if(nextVal < this.toValue){
nextVal = this.toValue;
stop = true;
}
}else if(this.currentProcess == "appear"){
if(nextVal > this.toValue){
nextVal = this.toValue;
stop = true;
}
}
this.setOpacity(nextVal);
this.onchange.fire();
if(stop){
this.stop();
this["onafter" + this.currentProcess].fire();	
}
}
Opacity.prototype.start = function(){
this.IS_DOING = true;
if(!this.timer._MUTUAL){
this.timer.start();
}
}
Opacity.prototype.stop = function(){
this.IS_DOING = false;
if(!this.timer._MUTUAL){
this.timer.clear();
}
}


Opacity.getOpacity = function(elem){
var currentOpacity = Style.getElementStyle(elem, Opacity.styleProperty);
if(currentOpacity == ''){
currentOpacity = "100";
}
var re = new RegExp(" ", "ig");
return Number(currentOpacity.replace(re, '').replace(Opacity.styleStartText, '').replace(Opacity.styleEndText, '')) * Opacity.styleCoeff;
}
Opacity.setDimensions = function(elem){
with(Style){
setElementStyle(elem, getDimensions(elem), null, true);
}
}
Opacity.getVisibility = function(elem){
return Style.getElementStyle(elem, 'visibility') == 'inherit' ? 'visible' : Style.getElementStyle(elem, 'visibility');
}
Opacity.NoGo = false;
Opacity.styleStartText = "";
Opacity.styleEndText = "";
Opacity.styleCoeff = 100;
Opacity.styleProperty = "opacity";
Opacity.slow = 3;
if(Style._browser == "IE"){
Opacity.styleProperty = "filter";
Opacity.styleCoeff = 1;
Opacity.styleStartText = "alpha(opacity=";
Opacity.styleEndText = ")";
Opacity.slow = 1;
}else if(Style._browser == "Gecko" || Style._browser == "Opera"){
//OK
}else{
Opacity.NoGo = true;
}
Opacity.handleMutualTimer = function(oTimer){
oTimer.opacities = [];
oTimer.registerOpacity = function(op){
this.opacities.push(op);
}
oTimer.registerEvent({
name: "opacity",
func: function(){
this.opacities.each(function(op){
if(op.IS_DOING){
op.change();
}
})
},
oThis: oTimer,
args: []
})
}
Opacity.handleOwnTimer = function(oTimer){
}
/*
------------------------
opacity end
------------------------
*/
//DA END