function isArray(obj) {
    	return (obj) ? obj.constructor == Array : false;
}

function range(start,end,between){
	var alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
	var alpha2 = {'a': 0,'b' : 1,'c': 2,'d': 3,'e' : 4,'f' : 5,'g' : 6,'h' : 7,'i' : 8,'j' : 9,'k' : 10,'l' : 11,'m' : 12,'n' : 13,'o' : 14,'p' : 15,'q' : 16,'r' : 17,'s' : 18,'t' : 19,'u' : 20,'v' : 21,'w' : 22,'x' : 23,'y' : 24,'z' : 25};
	var temp = [];
	if(isNaN(between)){
		between = 1;	
	}
	if(between < 0){
		between *= -1;
	}
	if(start.toString().match(/^[a-z]{1,1}$/i) && end.toString().match(/^[a-z]{1,1}$/i)){
		var start2 = alpha2[start.toString().toLowerCase()];
		var end2 = alpha2[end.toString().toLowerCase()];
		if(isNaN(start2)){
			start = 0;
		}
		if(isNaN(end2)){
			end2 = 26;
		}
		if(start <= end){
			for(var i=start2;i<=end2;i+=between){
				if(start.toString().match(/^[A-Z]{1,1}$/)){
					temp.push(alpha[i].toUpperCase());
				}else{
					temp.push(alpha[i]);
				}
			}
		}else{
			for(var i=start2;i>=end2;i-=between){
				if(start.toString().match(/^[A-Z]{1,1}$/)){
					temp.push(alpha[i].toUpperCase());
				}else{
					temp.push(alpha[i]);
				}
			}
	
		}
	}else{
		if(isNaN(start)){
			start = 0;
		}
		if(isNaN(end)){
			end = start + 100;
		}
		if(start <= end){
			for(var i=start;i<=end;i+=between){
				temp.push(i);
			}
		}else{
			for(var i=start;i>=end;i-=between){
				temp.push(i);
			}
		}
	}
	return temp;
}

Array.prototype.clone = function(obj,subobj){
	var temp = [];
	if(isArray(obj)){
		this.empty();
		for(var i=0;i<obj.length;i++){
			if(subobj != undefined){
				this.push(obj[i][subobj.toString()]);
			}else{
				this.push(obj[i]);
			}
		}
	}
	return this;
}

Array.prototype.empty = function(){
	var len = this.length;
	for(var i=0;i<len;i++){
		this.pop();
	}
}

Array.prototype.rand = function(){
	return this[Math.floor(Math.random()*this.length)];
}

Array.prototype.shuffle = function(clone){
	var temp = [];
	var temp2 = [];
	var num = [];
	for(var i=0;i<this.length;i++){
		temp.push({'num' : Math.random(), 'value' : this[i]});
	}
	temp.sort(function(a,b){ return a.num > b.num ? 1 : -1;});
	if(!clone){
		this.clone(temp,'value');
	}
	return temp2.clone(temp,'value');
}

Array.prototype.pop2 = function(num,clone){
	var temp = [];
	if(typeof(num) == "string"){
		var tempnum = [];
		for(var i=0;i<this.length;i++){
			if(this[i] == num){
				tempnum.push(i);
			}
		}
		num = tempnum;
	}
	if(num == undefined){
		temp = this.clone();
		temp.pop();
	}else{
		var test = [];
		if(isArray(num)){
			test = num;
		}else{
			test.push(num);
		}
		for(var i=0;i<this.length;i++){
			var exist = false;
			for(var j=0;j<test.length;j++){
				if(i == test[j]){
					exist = true;
					break;
				}
			}
			if(exist == false){
				temp.push(this[i]);
			}
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.push2 = function(obj,num,clone){
	var temp = [];
	if(isArray(obj) && isArray(num)==false){
		num = [];
		for(var i=0;i<obj.length;i++){
			num.push(obj.length+i);
		}
	}
	if(isArray(obj) && isArray(num)){
		var add = 0;
		for(var i=0;i<this.length;i++){
			for(var j=0;j<num.length;j++){
				if(i == num[j]){
					temp.push(obj[j]);
					add++;
				}
			}
			temp.push(this[i]);
		}
		var temp2 = [];
		var temp3 = [];
		for(var j=0;j<num.length;j++){
			if(num[j] >= this.length){
				temp2.push({'num' : num[j], 'value' : obj[j]});
			}else if(num[j] < 0){
				temp3.push({'num' : num[j], 'value' : obj[j]});
			}
		}
		temp2.sort(function(a,b){ return a.num > b.num ? 1 : -1;});
		temp3.sort(function(a,b){ return a.num <= b.num ? 1 : -1;});
		var add = 0;
		for(var j=0;j<temp2.length;j++){
				temp.push(temp2[j]['value']);
		}
		for(var j=0;j<temp3.length;j++){
				temp.unshift(temp3[j]['value']);
		}
	}else{
		if(isArray(obj)){
			obj = obj[0];
		}
		if(isArray(num)){
			num = num[0];
		}
		if(num == undefined || num >= this.length){
			temp.clone(this);
			temp.push(obj);
		}else{
			var within = false;
			for(var i=0;i<this.length;i++){
				if(i == num){
					temp.push(obj);
					within = true;
				}
				temp.push(this[i]);
			}
			if(within == false){
				if(num < 0){
					temp.unshift(obj);
				}else{
					temp.push(obj);
				}
			}
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.unique = function(clone,option){
	var temp = [];
	var removed = [];
	var removed2 = [];
	for(var i=0;i<this.length;i++){
		var exist = false;
		for(j=0;j<temp.length;j++){
			if(temp[j] == this[i]){
				exist = true;
				removed.push(this[i]);
				removed2.push(i);
				break;
			}
		}
		if(exist == false){
			temp.push(this[i]);
		}
	}
	if(!clone){
		this.clone(temp);
	}
	switch(option){
		case 1 : return removed;break;
		case 2 : return removed2;break;
		default : return temp;
	}
}

Array.prototype.reorder = function(from,to,clone){
	var temp = [];
	var temp2 = [];
	temp2.clone(this);
	var popped,popped2;
	if(isArray(from) && isArray(to)){
		var frompop = from.unique(false,2);
		to.pop2(frompop);
		var topop = to.unique(false,2);
		from.pop2(topop);
		popped = [];
		for(var i=0;i<from.length;i++){
			if((to[i]>=0 && to[i] < temp2.length) && (from[i]>=0 && from[i] < temp2.length)){
				popped.push({'from' : from[i], 'to' : to[i], 'value' : temp2[from[i]]});
			}
		}
		popped.sort(function(a,b){ return a.to > b.to ? 1 : -1;});
		temp2.pop2(from);
		for(var i=0;i<this.length;i++){
			if(popped[0].to == i){
				temp.push(popped[0].value);
				popped.shift();
			}else{
				temp.push(temp2[0]);
				temp2.shift();
			}
		}
	}else{
		if(isArray(from)){
			obj = obj[0];
		}
		if(isArray(to)){
			num = num[0];
		}
		if((to>=0 && to < temp2.length) && (from>=0 && from < temp2.length)){
			popped = temp[from];
			temp.pop2(from);
			temp.push2(popped,to);
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.forEach = function(func,clone){
	var temp = [];
	for(var i=0;i<this.length;i++){
		temp.push(func(this[i],i,this));
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.search = function(val,strict,option){
	var temp = false;
	if(option == 1){
		temp = [];
		for(var i=0;i<this.length;i++){
			if(strict == true){
				if(this[i] === val){
					temp.push(i);
				}
			}else{
				if(this[i] == val){
					temp.push(i);
				}
			}
		}
		if(temp.length == 0){
			temp = false;
		}
	}else{
		for(var i=0;i<this.length;i++){
			if(strict == true){
				if(this[i] === val){
					temp = i;
					break;
				}
			}else{
				if(this[i] == val){
					temp = i;
					break;
				}
			}
		}
	}
	return temp;
}

Array.prototype.slice2 = function(intArray, clone){
	var temp = [];
	var temp2 = [];
	temp2.clone(this);
	for(var i=0;i<intArray.length;i++){
		if(intArray[i] < 0){
			temp.push(this[this.length + intArray[i]]);
		}else{
			temp.push(this[intArray[i]]);
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.splice2 = function(clone){//under construction
	temp =[];
	temp.push(5);
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.countValues = function(){
	var temp = {};
	var temp2 = [];
	var temp3 = [];
	for(var i=0;i<this.length;i++){
		if(temp2.search(this[i])){
			temp3[temp2.search(this[i])]++;
		}else{
			temp2.push(this[i]);
			temp3.push(1);
		}
	}
	for(var i=0;i<temp2.length;i++){
		temp[temp2[i].toString()] = temp3[i];
	}
	return temp;
}

Array.prototype.pad = function(len,elem,clone){
	var temp = [];
	temp.clone(this);
	if(len < 0){
		for(var i=0;i<(len*(-1)) - this.length;i++){
				temp.unshift(elem);
		}
	}else{
		for(var i=0;i<len-this.length;i++){
			temp.push(elem);
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.sum = function(){
	var temp = 0;
	for(var i=0;i<this.length;i++){
		var temp2 = this[i].toString().replace(/^([0-9]*).*$/,"$1");
		if(!isNaN(temp2)){
			temp += temp2*1;
		}
	}
	return temp;
}

Array.prototype.diff = function(array,strict,option){
	var temp = [];
	var h = 0;
	for(var i=0;i<this.length;i++){
		var exist = false;
		if(option == 1){
			if((strict == true && this[i] === array[i]) || (strict != true && this[i] == array[i])){
				exist = true;
			}
		}else{
			for(var j=0;j<array.length;j++){
				if((strict == true && this[i] === array[j]) || (strict != true && this[i] == array[j])){
					exist = true;
					break;
				}
			}
		}
		if(exist == false){
			temp[h] = this[i];
			h++;
		}
	}
	return temp;
}

Array.prototype.intersect = function(array,strict,option){
	var temp = [];
	for(var i=0;i<this.length;i++){
		var exist = false;
		if(option == 1){
			if((strict === true && this[i] === array[i]) || (strict !== true && this[i] == array[i])){
				exist = true;
			}
		}else{
			for(var j=0;j<array.length;j++){
				if((strict === true && this[i] === array[j]) || (strict !== true && this[i] == array[j])){
					exist = true;
					break;
				}
			}
		}
		if(exist == true){
			temp.push(this[i]);
		}
	}
	return temp;
}

Array.prototype.merge = function(array,clone,option){
	var temp = [];
	if(option == 1){
		for(var i=j=0;i<array.length || j<this.length;i++, j++){
			if(this[j] != undefined){
				temp.push(this[j]);
			}else{
				temp.push(array[i]);	
			}
		}
	}else{
		temp.clone(this);
		for(var i=0;i<array.length;i++){
			temp.push(array[i]);
		}	
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}

Array.prototype.chunk = function(num,clone){
	var temp = [];
	if(isNaN(num) || num == 0){
		num = 1;
	}
	if(num > this.length){
		num = this.length;
	}
	var NoE = Math.ceil(this.length / num);
	var pointer = 0;
	var NoL = this.length % NoE;
	for(var i=0;i<num;i++){
		temp[i] = [];
		var NoE2 = NoE;
		if(i == num - 1){
			NoE2 = NoL;
		}
		for(var j=0;j<NoE2;j++){
			temp[i][j] = this[pointer];
			pointer++;
		}
	}
	if(!clone){
		this.clone(temp);
	}
	return temp;
}