historyB = new Class({
	getHash: function(){
		if (window.last_hash !=window.location.hash){  
			window.last_hash = window.location.hash
			this.change(window.location.hash);
		} 
	},
	change: function(hash){
		if (document.location.href.indexOf('#') == -1) url  = document.location.href;
		else url  = document.location.href.substring(0,document.location.href.indexOf('#'))
	
		var ajax_href = url + '?'+Cookie.get(hash.substring(1));
		$('items').empty();
		this.request(ajax_href);
	},
	request: function(link){
		new Request.HTML({
			url: 		link,
			update: 	"items",
			evalScripts: true
		}).send();
	},
	initialize: function(){
		this.timer = this.getHash.periodical(2000,this);		
		$$('.pagination_link').addEvent('click', (function(e){
			var event = new Event(e);
			target = event.target;
			var ajax_href = target.getProperty('href');
			
			if (document.location.href.indexOf('#') == -1){
				href_basic = document.location.href;
			} else {
				href_basic = document.location.href.substring(0,document.location.href.indexOf('#'))
			}
			
			this.url = href_basic;
			
			hash_time = $time();
			Cookie.set(hash_time, ajax_href.substring(ajax_href.indexOf('?')+1));

			window.last_hash = '#' + hash_time;
			target.setProperty('href',href_basic + '#' + hash_time) ;
			this.request(ajax_href);
		}).bind(this));
	},
	refresh: function(){
		if (window.location.hash != ''){
			if (document.location.href.indexOf('#') == -1){
				this.url  = document.location.href;
			} else {
				this.url  = document.location.href.substring(0,document.location.href.indexOf('#'))
			}
			this.change(window.location.hash);
		}
	}
});

