(function(){
	if ( window.ICL ) var ICL = window.ICL;
	
	var ICL = window.ICL = function() {return new ICL.init();};
	
	ICL.apply = function(o, c, defaults){
	    if(defaults){ICL.apply(o, defaults);}
	    if(o && c && typeof c == 'object'){for(var p in c){o[p] = c[p];}}
	    return o;
	};
	
	ICL.CheckData = function(strSearch, data) {
		if (data != null) {
			for(var i=0; i<data.length; ++i) {
				if (data[i].toLowerCase() == strSearch.toLowerCase()) return true;
			}
		}
		return false;
	};
	
	ICL.apply(ICL, {
		
		boxid: 0,
		version: '1.0.0',
		
		limitChars: function(textObj, limit, info) {
			var text = textObj.val();
			var textlength = text.length;
			
			if(textlength > limit) {
				textObj.val(text.substr(0,limit));
				delete textlength;
				delete text;
				return false;
			} else {
				jQuery('#' + info).html((limit - textlength));
				delete textlength;
				delete text;
				return true;
			}
		},
		
		loadingFull: function() {
			var pageSize = ICL.getPageSize();
			jQuery('<div id="id-loading" class="loading" style="width:'+pageSize[0]+'px;height:'+pageSize[1]+'px;"></div').appendTo(jQuery('body'));
			delete pageSize;
		},
		
		loadingFullRemove: function() {
			jQuery('#id-loading').remove();
		},
		
		getPageSize: function(){
			var xScroll, yScroll;
			
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			
			var windowWidth, windowHeight;
			
			if (self.innerHeight) {
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}

			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
			return arrayPageSize;
		},
		
		getPageScroll: function(){
			var xScroll, yScroll;

			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}

			arrayPageScroll = new Array(xScroll,yScroll) 
			return arrayPageScroll;
		},
		
		roundNumber: function (num, dec) {
			var snum=num.toString()+"000000000000000001";
			var sep=snum.indexOf(".");
			var beg=snum.substring(0,snum.indexOf("."));
			snum=snum.substring(eval(snum.indexOf(".")+1),snum.length);
			var dig=snum.substring(0,eval(dec-1));
			snum=snum.substring(eval(dec-1),dec);
			snum=parseInt(snum);
			gohigher=false;
			if (snum>4) {gohigher=true;}
			if (gohigher) {snum=parseInt(snum);snum++;}
			snum=snum.toString();
			num=beg+"."+dig+""+snum;
			return num;
		},
		
		rand32: function (){return Math.floor(Math.random()*4294967295);},
		
		str_repeat: function (i, m) {
			for (var o = []; m > 0; o[--m] = i) {
				return(o.join(''));
			}
		},

		sprintf: function () {
		  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
		  while (f) {
			if (m = /^[^\x25]+/.exec(f)) {
				o.push(m[0]);
			} else if (m = /^\x25{2}/.exec(f)) {
				o.push('%');
			} else if (m = /^\x25(?:(\d+)\jQuery)?(\+)?(0|'[^jQuery])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
				if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
					throw("Too few arguments.");
				}
				if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
					throw("Expecting number but found " + typeof(a));
				}
				switch (m[7]) {
					case 'b': a = a.toString(2); break;
					case 'c': a = String.fromCharCode(a); break;
					case 'd': a = parseInt(a); break;
					case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
					case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
					case 'o': a = a.toString(8); break;
					case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
					case 'u': a = Math.abs(a); break;
					case 'x': a = a.toString(16); break;
					case 'X': a = a.toString(16).toUpperCase(); break;
				}
				a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
				c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
				x = m[5] - String(a).length;
				p = m[5] ? this.str_repeat(c, x) : '';
				o.push(m[4] ? a + p : p + a);
			} else {
				throw ("Huh ?!");
			}
			f = f.substring(m[0].length);
		  }
		  return o.join('');
		},
		
		noop: function() {}
		
	});
	
	ICL.ui = ICL.ui || {};
	ICL.util = ICL.util || {};
})();

ICL.util.JSON = new (function(){
    var useHasOwn = {}.hasOwnProperty ? true : false;
    
    var pad = function(n) {
        return n < 10 ? "0" + n : n;
    };
    
    var m = {
        "\b": '\\b',
        "\t": '\\t',
        "\n": '\\n',
        "\f": '\\f',
        "\r": '\\r',
        '"' : '\\"',
        "\\": '\\\\'
    };

    var encodeString = function(s){
        if (/["\\\x00-\x1f]/.test(s)) {
            return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if(c){
                    return c;
                }
                c = b.charCodeAt();
                return "\\u00" +
                    Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }) + '"';
        }
        return '"' + s + '"';
    };
    
    var encodeArray = function(o){
        var a = ["["], b, i, l = o.length, v;
            for (i = 0; i < l; i += 1) {
                v = o[i];
                switch (typeof v) {
                    case "undefined":
                    case "function":
                    case "unknown":
                        break;
                    default:
                        if (b) {
                            a.push(',');
                        }
                        a.push(v === null ? "null" : ICL.util.JSON.encode(v));
                        b = true;
                }
            }
            a.push("]");
            return a.join("");
    };
    
    var encodeDate = function(o){
        return '"' + o.getFullYear() + "-" +
                pad(o.getMonth() + 1) + "-" +
                pad(o.getDate()) + "T" +
                pad(o.getHours()) + ":" +
                pad(o.getMinutes()) + ":" +
                pad(o.getSeconds()) + '"';
    };
    
    this.encode = function(o){
        if(typeof o == "undefined" || o === null){
            return "null";
        }else if(o instanceof Array){
            return encodeArray(o);
        }else if(o instanceof Date){
            return encodeDate(o);
        }else if(typeof o == "string"){
            return encodeString(o);
        }else if(typeof o == "number"){
            return isFinite(o) ? String(o) : "null";
        }else if(typeof o == "boolean"){
            return String(o);
        }else {
            var a = ["{"], b, i, v;
            for (i in o) {
                if(!useHasOwn || o.hasOwnProperty(i)) {
                    v = o[i];
                    switch (typeof v) {
                    case "undefined":
                    case "function":
                    case "unknown":
                        break;
                    default:
                        if(b){
                            a.push(',');
                        }
                        a.push(this.encode(i), ":",
                                v === null ? "null" : this.encode(v));
                        b = true;
                    }
                }
            }
            a.push("}");
            return a.join("");
        }
    };
    
    this.decode = function(json){
        return eval("(" + json + ')');
    };
})();

ICL.encode = ICL.util.JSON.encode;
ICL.decode = ICL.util.JSON.decode;

Function.prototype.bind = function() {
  var __method = this, args = jQueryA(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat(jQueryA(arguments)));
  }
};

Function.prototype.bindAsEventListener = function(object) {
  var __method = this, args = jQueryA(arguments), object = args.shift();
  return function(event) {
    return __method.apply(object, [( event || window.event)].concat(args).concat(jQueryA(arguments)));
  }
}

var jQueryA = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i]);
    return results;
  }
};