/**
 * Plugin: jQuery Address Manager
 * @author Steve Sinnwell
 * v. 0.2
 */   
     
(function($) {                     
	$.addressmanager = (function() {       
		var _init = function() { 		
			$.address.init(function(event) {
	        }).change(function(event) {
				// Sets the page title 
				if(event.value == "" || event.value == "/") {  
					$.address.title( $('.filter-results a:first').text() + ' - ' + $.address.title().split(' - ')[($.address.title().split(' - ').length-1)] );   	
				}else {
					$.address.title( $('.filter-results a').filter('[href=work'+ event.value +']').text() + ' - ' + $.address.title().split(' - ')[($.address.title().split(' - ').length-1)] );     
	          	}   
			}).externalChange(function(event) {                
				var index = $('.filter-results a').index( $('.filter-results a').filter('[href=work/'+ event.pathNames[0] +']') );                                                  
				$($.addressmanager).trigger('change', [index]);
			}); 
		}, 
        _bind = function(value, data, fn) {
            $($.addressmanager).bind(value, data, fn);
            return $.addressmanager;
        },
		INIT = 'init';     

            
		return {  
            bind: function(type, data, fn) {
                return _bind(type, data, fn);
            },
            init: function() {
	        	return _init();
				//return _bind(INIT, fn);
            }
		};  

	})();                                        
	
})(jQuery);                  

