/*
jquery.breadcrumb.js
Rich Reuter
Sogeti
rich.reuter@us.sogeti.com
10/13/2008

This jQuery plugin is designed to style JSON data into the breadcrumb HTML that is used on the Midmark website to 
display

Usage:
var data = { 'Midmark' : 'Home.aspx', 'Contact Us': '' };
jQuery('.breadcrumb').breadcrumb(data);

This is an example of what gets outputted to the screen
<span><a title="Midmark hOME" class="ms-sitemapdirectional" href="/Pages/Home.aspx">Midmark</a></span>
<span> &gt; </span><span class="breadcrumbCurrent">Contact Us</span>
*/
(function() {  
    jQuery.fn.breadcrumb = function(data) {
        
        var breadcrumb_html = '<span id="ctl00_PlaceHolderTitleBreadcrumb_siteMapPath">';
        var isFirst = true;
        
        // Spin through each key/value pair and append the appropriate HTML
        jQuery.each(data, function(page_name, url) {
            if (isFirst)
            {
                isFirst = false;
            }
            else
            {
                // Append the separator
                breadcrumb_html += '<span> &gt; </span>';
            }
            
            if (url != null && url != '')
            {
                breadcrumb_html += '<span><a target="_self" title="' + page_name + '" class="ms-sitemapdirectional" href="' + url + 
                    '">' + page_name + '</a></span>';
            }
            else
            {
                breadcrumb_html += '<span class="breadcrumbCurrent">' + page_name + '</span>';
            }
                   
        });
        breadcrumb_html += '</span>';
        
        jQuery(this).html(breadcrumb_html);
        
        // Unbind all of the click events for this section so that it fixes the non-IE browser bugs
        // There was a weird issue when the text would jump to the left when clicked.
        jQuery(this).unbind('click');
        
        return jQuery;
    };
})(jQuery);  