var SmallMenuItems = 0;

function LoadSmallMenu() {

        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>CLENGSmallMenu</listName> \
                            <query> \
                               <Query> \
                                  <OrderBy> \
                                     <FieldRef Name='Orden' /> \
                                  </OrderBy> \
                               </Query> \
                            </query> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                               <FieldRef Name='Url' /> \
                               <FieldRef Name='Orden' /> \
                               <FieldRef Name='ID' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";


        jQuery.ajax({

            url: "/eng/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResultSmallMenu,
            contentType: "text/xml; charset=\"utf-8\""
        });

    }


function processResultSmallMenu(xData, status) {

          var itemCount = 0;

		  SmallMenuResultCount(xData, status);

          $(xData.responseXML).find("z\\:row").each(function() {
            var title = $(this).attr("ows_Title");
            var IdItem = $(this).attr("ows_ID");
            var urlSite = $(this).attr("ows_Url");
            
            if (title == undefined)
               title = "";
               
            if (title != ""){ 
               //alert("Menu " + title + " - " + IdItem);
               itemCount++;
               if (itemCount < SmallMenuItems) {
               	
               	   // alert("itemCount: " + itemCount + " - SmallMenuItems: " + SmallMenuItems);
	               var divHtml = "<a href='" + urlSite + "' class='raya'>" + title + "</a>";
	               $("#menu_superior").append(divHtml);
	           }
	           else {
	               // alert(itemCount + " = " + SmallMenuItems);
	               var divHtml = "<a href='" + urlSite + "' class='rayaidioma'>" + title + "</a>";
	               $("#menu_superior").append(divHtml);
	           }
            }

        });

    }
    
    
function SmallMenuResultCount(xData, status) {

          $(xData.responseXML).find("z\\:row").each(function() {

            var title = $(this).attr("ows_Title");
            
            if (title == undefined)
               title = "";
               
            if (title != "")
            	SmallMenuItems++;

        });

    }
    

