﻿// 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($)
{
  $.fn.jFav = function(d)
  {
    var e = $.extend({},
        $.fn.jFav.defaults, d);
    var f = e.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(a)
    {
      var b = $(this).attr("href");
      var c = $(this).attr("title");
      b = b.replace("file:///", "http://file/");
      if ($.browser.msie)
      {
        window.external.AddFavorite(b, c);
      } else if ($.browser.mozilla)
      {
        window.sidebar.addPanel(c, b, "");
      } else if (navigator.userAgent.toLowerCase().indexOf("chrome") > -1)
      {
        alert(f);
      } else if ($.browser.safari)
      {
        alert(f);
      }
      a.preventDefault();
    }

    return this;
  };
  $.fn.jFav.defaults = {
    msg: "Press \"Ctrl + D\" or \"CMD + D\" for MAC, to add this page to your bookmarks."
  };
  $.fn.jFav.OperaBookmark = function(e, a, b)
  {
    e.rel = "sidebar";
    e.title = a;
    e.href = "";
    e.href = b;
    e.click();
    return false;
  };
} (jQuery));