// JavaScript Document
(function($){
	
	function ToolBar()
	{
		this.options = null;
		
		this.minshare = function(){
		  $('#socializethis').animate({height:'35px', width: '200px', opacity: 1}, 300); 
		  $('#socializethis img').css('display', 'none');
		  return false;
		}		
		
		this.setup = function()
		{
			var url = window.location.href;
			var host =  window.location.hostname;
			var title = $('title').text();
			title = escape(title); //clean up unusual characters
		 
		 
			var tbar = '<div id="socializethis"><div id="sicons">';
			options = this.options;
			for (i=0; i<options.buttons.length; i++) {
				tbar += '<a href="'+options.buttons[i].href	+'" onclick="javascript: '+options.buttons[i].onclick+'" id="'+options.buttons[i].id+'" title="'+options.buttons[i].title+'"><img src="'+options.buttons[i].image+'"  alt="'+options.buttons[i].alt+'" border=0; /></a>';
			}
			
			tbar += '</div></div>';
		 
			// Add the share tool bar.
			$('body').append(tbar); 
			$('#socializethis').css({opacity: .7}); 
			// hover.
			
			/*$('#socializethis').bind('mouseenter',function(){
			  $(this).animate({height:'35px', width:'300px', opacity: 1}, 300);
			  $('#socializethis img').css('display', 'inline');
			  $.cookie('minshare', '0');  
			});
			//leave
			$('#socializethis').bind('mouseleave',function(){
			  //$(this).animate({height:'15px', width:'260px', opacity: 1}, 300);
			  $(this).animate({ opacity: .7}, 300);
			});*/ 
			 
			// Click minimize
			$('#socializethis #minimize').click( function() { 
			  $.toolbar.minshare(); 
			  //alert('min');
			  $.cookie('minshare', '1');  
			}); 
		 	
			if($.cookie('minshare') == 1){
			  $.toolbar.minshare();
			}  
			$.toolbar.initialized = true;
		}
		
		
	}
	
	$.fn.toolbar = function(options) {

		//alert(options.buttons[0].name);
		$.toolbar.options = options;
		
		if (!$.toolbar.initialized) {
			$.toolbar.setup();
		}
		
		//$.clientsearch.service = options.service;
		
		return this.each(function() {
			/*$.clientsearch.attachinput(this);*/
			
		});
	};
	
 
	$.toolbar = new ToolBar(); // singleton instance
	$.toolbar.initialized = false;
	$.toolbar.version = "1";

 
 
})(jQuery);
