// jFav, JQuery plugin
// v 1.0 
// SAFARI & CHROME not Supported!
// Licensed under GPL licenses.
// Copyright (C) 2008 Nikos "DuMmWiaM" Kontis, info@dummwiam.com
// http://www.DuMmWiaM.com/EffectChain
// ----------------------------------------------------------------------------
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ----------------------------------------------------------------------------

(function($) 
{
	//alert(navigator.appName);
// plugin definition
	$.fn.jFav = function(options) 
	{
		// build main options before element iteration
		var opts = $.extend({}, $.fn.jFav.defaults, options);
		var _msg = opts.msg;
		this.each(function() 
		{
			if (!$(this).attr('href') || $(this).attr('href') == "#") { $(this).attr('href', window.location.href);}
			if (!$(this).attr('title')) { $(this).attr('title',document.title);}
			if ($.browser.opera)
			{
				$(this).attr('link',$(this).attr('href')).attr('href','').attr('href','javascript:void(0)').attr('onClick','$.fn.jFav.OperaBookmark(this,"'+$(this).attr('title')+'","'+$(this).attr('link')+'")');
			}
			else
			{
				$(this).click(addToFavorites);
			}
		});

		function addToFavorites(event) 
		{
			var url = $(this).attr('href');
			var title = $(this).attr('title');
			url = url.replace("file:///","http://file/");//change URL in case of running from local folder
			if ($.browser.msie)
			{
				window.external.AddFavorite(url, title);
			}
			else if ($.browser.mozilla) 
			{
				window.sidebar.addPanel(title, url, '');
			}
			else if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) 
			{
				alert(_msg);
			}
			else if ($.browser.safari)
			{
				alert(_msg);
			}
			event.preventDefault();	
		};
		
		return this;//return object for jQuery chained functions that might follow.
	};
	$.fn.jFav.defaults = {msg:'Faire "Ctrl + D" ou "CMD + D" sur MAC, pour ajouter cette page à vos signets.'};
	$.fn.jFav.OperaBookmark = function(e,$title,$url)
	{
		e.rel = "sidebar";
		e.title = $title;
		e.href = "";
		e.href = $url;
		
		e.click();
		return false;
	};
})(jQuery);

