<!-- 
/* 
    Document - A jQuery plugin
    ==================================================================
    ©2011 JasonLau.biz - Version 1.0.0
    ==================================================================
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/

(function($){
 	$.fn.extend({ 
 		doc: function(options) {
			var defaults = {
			    key : 'value'    
			}
            var option =  $.extend(defaults, options);
            var obj = $(this)
            id = $(this).attr('id');
            
            obj.before('<div id="load"><div id="progress" style="background-color:#3366FF"></div></div>');
            $("#progress").progressbar({
			value: 1
            });
            
            $(".ui-dialog-titlebar").remove();
            $('.ui-dialog-content').css({
                'height':'34px',
                'min-height':'34px',
                'max-height':'34px'
            });
            
            var page_content = '',
            page_index = '<span class="list-top"></span>\n<h3>Index</h3>\n<ol>\n',
            a = 0;           
            $("#"+id+" ul").not("#"+id+" ul ul, #"+id+" ul ul ul").each(function(){
                var o = $(this);
                
                var title = o.find('li[class=title]').html();
                page_index += '<li><a href="javascript:void(0)" class="jump-to" rel="'+title+'">'+title+'</a></li>'
                page_content += '<div class="item-container" rel="process">\n<a name="'+title+'"></a>\n<table class="options" cellpadding="4">\n<tbody>\n<tr class="option"><th><h3>'+title+'</h3></th></tr>\n<tr class="coption">\n<td>\n';
                
                var description = o.find('li[class=description]').html();
                page_content += '<p>'+description+'</p>\n';
                
                var t = o.find('li[class=type]').html();
                if(t && t != ''){
                    var type = t.charAt(0).toUpperCase() + t.slice(1);
                    page_content += '<label>Type:</label> <a href="http://docs.jquery.com//Types#'+type+'" target="_blank">'+type+'</a>\n';  
                }
                
                var values = o.find('li[class=values]').html();
                if(values){
                    page_content += '<br /><label>Possible Values:</label> '+values+'\n';  
                }
                               
                var default_value = o.find('li[class=default]').html();
                if(default_value){
                   page_content += '<br /><label>Default:</label> '+default_value+'\n'; 
                }
                
                o.find('li[class=example]').each(function(){
                    var example = $(this).html();
                    if(example){
                      page_content += '<br /><label>Example:</label> '+ example +'\n';  
                    }                    
                });
                
                o.find('li[class=demo]').each(function(){
                    var demo = $(this).html();
                    if(demo){
                      page_content += '<br /><label>Demo:</label> '+ demo +'\n';  
                    }                    
                });
                
                page_content += '<br /><small><a href="javascript:void(0)" class="listtop">Index</a></small>\n</td>\n</tr>\n</table>\n</div>\n';
                a++;
                $(this).remove();
                
            });
            
            page_index += '</ol>\n';
            
            obj.html(page_index + '\n' + page_content); 
                  
            var t = 100/a,
            i = 1;
            showDiv(id);
            
            function showDiv(id){
                var pl = Math.ceil(t*i);               
                if(i <= a){               
                //$("#progress").html(pl + '%');
                $(".ui-progressbar-value").animate({'width':pl+'%'},200,function(){
                    i++;
                    showDiv(id);   
                });  
                } else {
                    $("#load").hide('slow');
                    $('#'+id).show('slow');
                    return true;
                }
                
            }
            
            $(window).scroll(function(){
                var pos = $("th[class=ui-state-highlight]").position();
                var h = $("th[class=ui-state-highlight]").height();
                var st = $(window).scrollTop();
                var wh = $(window).height();                
                try{
                    var bottom = (wh+st)-pos.top;
                    if(bottom <= 0){
                        $("th").removeClass('ui-state-highlight');
                    }
                    if(st >= pos.top+h){
                        $("th").removeClass('ui-state-highlight');
                    }
                }catch(e){}               
            });

            
            $(".jump-to").click(function(){
                $("th").removeClass('ui-state-highlight');
                var pos = $("a[name='"+$(this).attr('rel')+"']").offset();
                var ob = $("a[name='"+$(this).attr('rel')+"']").parent().find('th');  
                $('html').animate({
                    scrollTop: pos.top-10
                    }, 2000, function() {
                        ob.addClass('ui-state-highlight');
                });
            });
            
            $(".listtop").click(function(){
                $("th").removeClass('ui-state-highlight');
                var pos = jQuery(".list-top").offset();
                $('html').animate({
                    scrollTop: pos.top
                    }, 2000, function() {});
            });
            
           jQuery.fn.sort = (function(){
    var sort = [].sort;
    return function(comparator, getSortable) {
        getSortable = getSortable || function(){return this;};
        var placements = this.map(function(){
            var sortElement = getSortable.call(this),
                parentNode = sortElement.parentNode,
                nextSibling = parentNode.insertBefore(
                    document.createTextNode(''),
                    sortElement.nextSibling
                );
 
            return function() {
 
                if (parentNode === this) {
                    throw new Error(
                        "You can't sort elements if any one is a descendant of another."
                    );
                }
                
                parentNode.insertBefore(this, nextSibling);
                parentNode.removeChild(nextSibling);
                };
                });
 
        return sort.call(this, comparator).each(function(i){
            placements[i].call(getSortable.call(this));
        });
 
    };
 
})();
        
 		} // doc
   }); // extend
	
})(jQuery);
 -->
