var BookMark = Class.create({
	initialize: function(){
		this.url = escape(location.href);
		if( typeof(Control)== 'object' && typeof(Control.Tabs) == 'function' )
		{
			var objectTabs = Control.Tabs.findByTabId('tab_1');
			if(objectTabs != null)
			{
				this.url = escape(objectTabs.activeLink.href);
			}
		}
		this.title = document.title;
		var targets = $$('a[id^=bookmark_]');
		for (var i=0; i < targets.length; i++ ) {
			var linkElement = targets[i];
  		var service = linkElement.id.replace('bookmark_','');
  		if(service == 'browser')
  		{
  			Event.observe(linkElement, 'click', this.browser.bindAsEventListener(this));
			}
			else
			{
				linkElement.href = this.getServiceUrl(service);
				Event.observe(linkElement, 'click', this.popUpWindow.bindAsEventListener(this, service));
			}
  	}
	},
	popup:function(obj){
		if(!obj.url){obj.url="";}
		if(!obj.toolbar){obj.toolbar=0;}
		if(!obj.scrollbars){obj.scrollbars=0;}
		if(!obj.location){obj.location=0;}
		if(!obj.status){obj.status=0;}
		if(!obj.menubar){obj.menubar=0;}
		if(!obj.resizable){obj.resizable=0;}
		if(!obj.top){obj.top=100;}
		if(!obj.left){obj.left=100;}
		if(!obj.width){obj.width=671;}
		if(!obj.height){obj.height=373;}
		if(!obj.name){obj.name="win"+new Date().getTime();}
		if(!obj.parameters){obj.parameters="toolbar="+obj.toolbar+",scrollbars="+obj.scrollbars+",location="+obj.location+",status="+obj.status+",menubar="+obj.menubar+",resizable="+obj.resizable+",width="+obj.width+",height="+obj.height+",top="+obj.top+",left="+obj.left;}
		return window.open(obj.url,obj.name,obj.parameters);
	},
	browser:function(){
	  if (window.sidebar) // firefox 
	  	window.sidebar.addPanel(this.title, this.url, "");
	  else if(window.opera && window.print){ // opera
	  	var elem = document.createElement('a');
	  	elem.setAttribute('href',this.url);
	  	elem.setAttribute('title',this.title);
	  	elem.setAttribute('rel','sidebar');
	  	elem.click(); alert('b');
	  }
	  else if(document.all)  // ie 
	  	window.external.AddFavorite(this.url, this.title);
	},
	popUpWindow:function(event, service){
		Event.stop(event);
		this.popup({url:this.getServiceUrl(service),resizable:1,scrollbars:1,width:700});
	},
	getServiceUrl:function(service)
	{
		switch(true){
			case service == "delicious":
				return "http://del.icio.us/post?v=4&noui&jump=close&url=" + this.url + "&title=" + this.title;
			break;
			case service == "digg":
				return "http://digg.com/remote-submit?phase=2&url=" + this.url + "&title=" + this.title;
			break;		
			case service == "reddit":
				return "http://reddit.com/submit?url=" + this.url + "&title=" + this.title;
			break;
			case service == "facebook":
				return "http://www.facebook.com/sharer.php?u=" + this.url + "&t=" + this.title;
			break;
			case service == "stumbleupon":
				return "http://www.stumbleupon.com/submit?url=" + this.url + "&title=" + this._headline;
			break;
			default:
				return '';
			break;
		};
	}
});
