var _Bookmarks = function(){
	this.storage = 'browser';
	this.page_id;
	
	this.set_storage = function(storage)
	{
		this.storage = storage;
	}
	
	this.bookmark = function()
	{
		var func = this.storages[this.storage];
		func(this.page_id);		
	}
	
	return this;	
}

_Bookmarks.prototype.storages = new Array();
_Bookmarks.prototype.storages['site'] = function(page_id)
{
	//Сделаем AJAX запрос
	JsHttpRequest.query(
	  '/bookmark.php?page_id=' + page_id,
	  {
	    page_id: page_id  
	  },
	  function(result, debugMessages) {}
	);
	var e = document.getElementById('bm');
	e.style.display = 'none';
	
}
_Bookmarks.prototype.storages['browser'] = function(page_id) 
{
	if (window.sidebar) //Firefox
	{
		window.sidebar.addPanel(document.title, window.location.href,"");
	}
	else if( window.external ) //IE
	{ 
		window.external.AddFavorite( window.location.href, document.title);
	}
	else if(window.opera && window.print) //Opera
	{
		
		var elem = document.createElement('a');
		elem.setAttribute('href',window.location.href);
		elem.setAttribute('title',document.title);
		elem.setAttribute('rel','sidebar');
		document.body.appendChild(elem);
		elem.click();
	}
	else
	{
		alert('Ваш браузер не поддерживается');
	}
}
_Bookmarks.prototype.storages['del.icio.us'] = function(page_id){document.location = 'http://del.icio.us/post?v=2&url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title);}
_Bookmarks.prototype.storages['digg'] = function(page_id){document.location = "http://digg.com/submit?phase=2&url=" + encodeURIComponent(document.location.href);}

var Bookmarks = new _Bookmarks();


