/**
 * @author ferenz
 * @usage
 *    $('a[@rel="bookmark"]').bookmarks(
 *        function() {
            $(this).parent().hide();
 *        }
 *    );
 */
jQuery.fn.bookmarks = function(callback) {
    
    var isMac=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
    
    // callback will be executed when browser is not supported
    if (!window.sidebar && !window.external && !jQuery.browser.opera && !jQuery.browser.safari) {
    
        return this.each( function(event){
            
            if(callback) {
                callback.call();
            }
            
            jQuery(this).click(function() {
               return false; 
            });
        });
        
    } else {
    
        return this.each(function(event){
        
            jQuery(this).click(function(event){
            
                //title and href are optional, if they are not set the window titel and the window location are used.
                var title = document.title;
                var url = window.location.href
/* This is not wise to do. We want the document title and the document URL.                
                if(jQuery(this).attr('title').length > 0) {
                    title = jQuery(this).attr('title');
                }
                if(jQuery(this).attr('href') != '#') {
                     url = jQuery(this).attr('href'); 
                }
*/                
                if (jQuery.browser.opera) { // opera uses a rel so add it and click again.
                    jQuery(this).attr('rel', 'sidebar')
                    jQuery(this).click();
                    
                } else if(jQuery.browser.safari) { //safari does not support it, so show message.
                    if(isMac) {
                         alert('You need to press Command/Cmd  + D to bookmark our site.');
                    } else {
                         alert('You need to press CRTL + D to bookmark our site.');
                    }
                } else  if (window.sidebar) { //IE
                    window.sidebar.addPanel(title, url, "");
                    
                } else if (window.external) { //FF 
                    window.external.AddFavorite(url, title);                    
                } 
                
                return false;
            });
            
        });
    }
};
