(function ($) {
    jQuery.fn.aurl = function (options) { 
	
        var opts = $.extend({},
        $.fn.aurl.defaults, options);
        return this.each(function (i, e) {
            var $t = jQuery(this);
			//alert($t);
            if (!$t.is('a')) return;
            //IMPORTANT !!!
            //Prevent MULTIPLE Binding !!
            //IN case when they was already Binded!
            jQuery(e).unbind('click.aurl'); 
			//Bind Click 
            jQuery(e).bind('click.aurl', function (event) {
                event.preventDefault();
                $rel = $(this).attr('rel');
				
                $href = $t.attr('href');
				//alert($href.match(/#/));
				//return;
                //if ($href.match(/^#/) && $href.length > 1) {
				if ($href.match(/#/) && $href.length > 1) {				
                    //$id = $href.substr(1);
					$_id=$href.split('#');
					$id=$_id[1];				
					
                    $obj = jQuery('#' + $id);
                    $obj.empty();
                    _bussy_box($obj);
                    _ajax_action($obj, 'parts.php');
                } else {
                    //console.log('BAD HREF : EXITING');
					alert('BAD HREF : EXITING');
                    return;
                }
            });
        });
    } //

    function _ajax_action($obj, file_to_use) {
//alert('_ajax_action');
        $.ajax({
            async: true,
            type: "POST",
            url: file_to_use,
            data: "adata=" + $rel,
            success: function (msg) {
                $obj.html(msg);
                $obj.show();                
            },
            error: function (msg) {
                //alert(" Error  : " + msg.responseText);
                $obj.html(msg.responseText);
                $obj.show();                
            }
        });
    }
    function _bussy_box($obj) {
        $obj.html('<h2 style="color:green;text-align:center;">Processing<img src="../images/indicator.gif" alt="" border="0"></h2>');
    }
    function _load_missing_js($file_name) {
        $.getScript($file_name, function () {
            return true;
        });
    }
    function debug($obj) {
        if (window.console && window.console.log) {
            window.console.log('powertoggle debug: Start');
            window.console.log($obj);
            window.console.log('powertoggle debug: End');
        } else alert($obj);
    };
})(jQuery);
