 (function($){
	 
	 $.fn.readtopmenu=function(xmlpath){
		 //alert('test'+xmlpath);
       $.get(xmlpath, function(d){
    	   /**bug fix provide by Whelan - start
    	    * When getting xml string from an url, the variable d will be treated as String rather than XML Object.
    	    * The code doesn't work with String object so that the menu fail to show up.
    	    * Below code parse the String into XML Object to make the code work.
    	    * It is just the fix tested for Firefox and IE 7 only. To "hardcode" the fix here should not be encouraged,
    	    * also, the code didn't check for the objec type.
    	    * please find a better way to solve it.
    	   **/
    	   //alert(d);
           if( window.DOMParser ){
		       // added by Wing Tse to trim the space before parsing
			   d = d.replace( /^\s+|\s+$/g, "" );
			   //console.log(d);
        	   d = (new DOMParser()).parseFromString(d, 'text/xml');
           }else if( window.ActiveXObject && window.GetObject ) {
        	   var dom = new ActiveXObject( 'Microsoft.XMLDOM' );
               dom.loadXML( d );
               d = dom;
           }
           
           /**bug fix provide by Whelan - end**/
		  $(d).find('nav > url').each(function(){

            var $obj = $(this); 
            var label = $obj.attr("label");
            var id = $obj.attr("id");
            var url = $obj.attr('url');
		    var imgurl = $obj.attr('imgurl');
		    
            var html = '<li><a href="'+url+'" id="'+id+'" style="background-image:url('+imgurl+') repeat-x" ></a>';
		
			if($obj.children().size()>0)
			{
             	html+='<ul><div><img src="/resources/Common/images/right_top.gif" alt="" border="0" /></div>';
             	$obj.children().each(function()
			    {
                    var $subobj = $(this); 
				    var sublabel = $subobj.attr("label");
                    var suburl = $subobj.attr('url');
                    var css="";
                    if(sublabel.length>24)  
                       css="LefyesChildtall";
			        html += '<li class="'+css +'"><a href="'+suburl+'" >'+sublabel+'</a></li>';
			       
			    });

			    html+='<div><img src="/resources/Common/images/left_bottom.gif" alt="" border="0"  /></div></ul>';
            }

			html += '</li>';

            $('ul.top_navi').append($(html));
     
        });


         $('body').append($("<script type='text/javascript' src='/resources/Common/script/jquery.menu.js' />"));
     });
};


 })(jQuery);

