//new collection operations
//adapted from http://phrogz.net/js/classes/ExtendingJavaScriptObjectsAndClasses.html#example5
Array.prototype.subtract = function(array){ 
	if (!array) return this;
	var copy = this.clone();
	var arrayLength = array.length; 
	for (var i = 0; i < copy.length; i++){ 
		var found = false;
		for (var j = 0; j < arrayLength; j++){
			if (copy[i] == array[j]) {
				found = true;
				break; 
			} 
		}
		if (found){
		 	copy.splice(i--, 1);
		}
	} 
	  return copy;
};

//new instance vars for Element
Element.prototype.isCategoryVisible = true;
Element.prototype.newPosition = 0;

//new functions for Element	
Element.prototype.isLastCategory = function(atLeft) {
    if (atLeft) {
        return this.previous() == undefined;
    } else {
        return this.next() == undefined;
    }
};

Element.prototype.boundaryReached = function(atLeft) {
	if(atLeft){
		return this.previous() && !this.previous().isCategoryVisible;
	}else{
		return this.next() && !this.next().isCategoryVisible;
	}
};

Element.prototype.showCategory = function() {
	this.isCategoryVisible = true;
}

Element.prototype.hideCategory = function() {
	this.isCategoryVisible = false;
};

Element.prototype.getOffsetLeft = function(){
	if(this.offsetLeft != 0){
		return this.offsetLeft;
	}else{
		return parseInt(this.style.left);
	}
};
