(function() {
	
	// console.log("Starting...");
	
	var springURL = Class.create({
		initialize: function(element) {
			
			if (element.href) {
				target = element.href;
			} else if (element.src) {
				target = element.src;
			} else {
				return;
			}
		
			//create the array starting after the domain name
			this.urlarray = $A(target.split('/')).slice(3);			
			this.name = this.urlarray.shift();

			this._urlhash = $H();
		
			//lets populate the hash
			this.hashed = this.asHash();
			this.json = this.asHash().toJSON();
			this.url = this.asString();

		},
		set: function(key,value){
			this._urlhash.set(key,value);
			this.hashed = this._urlhash;
			this.json = this._urlhash.toJSON();
			this.url = this.asString();
		},
		asHash: function(){
			urlarray = this.urlarray;
			_urlhash = this._urlhash;
			
			urlarray.each(function(item,index){
				if (0 == index % 2) {
					_urlhash.set(item,urlarray[index+1]);
				}
			});
			
			return _urlhash;
		},
		asString: function() {			
			
			urlstring = "/"+this.name;
			_urlhash = this._urlhash;
			
			_urlhash.each(function(pair){
				urlstring += "/"+pair.key+"/"+pair.value;
			});
			
			return urlstring;
		},

	});
	
		
	$$('div.loadimage img').each(function(element){
		
		// console.log("In...");
		
		var test = new springURL(element);
		test.set("quality","85");
		test.set("gray","0");
		newurl = test.url;

		// console.log(element.localName);

		element.src = newurl;
		
		
		// $$(target).each(function(element){
		// 	console.log(element.localName);
		// 	element.setStyle({backgroundImage: 'url('+newurl+')'});
		// })		
		
	});
	
	
	function nodeDetails(selectednode,marker){
		marker = selectednode.href.indexOf(marker)+1;
		urlarray = selectednode.href.substring(marker).split('/').slice(1);
		var nodedetails = new Hash();
		urlarray.each(function(item,index){
			if (0 == index % 2) {
				nodedetails.set(item,urlarray[index+1]);				
			}
		});
		return nodedetails;
	}
	
	

})();
