/*** COPYRIGHT 2011  BY FDM4 INTERNATIONAL INC. - ALL RIGHTS RESERVED       **/
/*** global.js -- Global Functions for Web Sites                            **/
/*****************************************************************************/
/* C010002 02/09/12 JZ - Assigned in C010000 to remove the view all links.   */
/*         02/09/12 MLF- custom vc-signature styling                         */
/* C010001 09/01/11 JJD - Added view all links.                              */
/* C010000 07/22/11 JJD - Created.                                           */
/*****************************************************************************/

function buildDropDown() {
  var vXMLPath = webPath + '/catalog.xml';
  var catDropDown='';
  var catId='';
  var mode=''; /* dynamic/static */
  $.ajax({
    type: 'GET',
    url: vXMLPath,
    dataType: 'xml',
    complete: function(data) {

      var catalog = $.xmlToJSON(data.responseXML);

      if (!catalog.division) return;

      catalog.division.sort(function(a,b){ return a.sortOrder - b.sortOrder });

      $(catalog.division).each(function(){

        mode = this.mode;

        $(this.category).each(function() {

          catDropDown='';
          catId=this.id;

          if (this.prb) {
            if ($('#'+catId).hasClass('hdrNavLinkSignature')) /* C010002 */
            {
               catDropDown='<ul class="catDropDownSignature hdrNavLinkSignature" data-cat-id="'+catId+'" id="dd_'+catId+'" style="display:none;">'; /* C010002 */
            }
			else
               catDropDown='<ul class="catDropDown hdrNavLink" data-cat-id="'+catId+'" id="dd_'+catId+'" style="display:none;">';
            this.prb.sort(function(a,b){ return a.sortOrder - b.sortOrder });

            $(this.prb).each(function() {

              if (this.srb) {
                this.srb.sort(function(a,b){ return a.sortOrder - b.sortOrder });
                $(this.srb).each(function() {
                  catDropDown+=getCatLink(this.dLink,this.sLink,this.description,mode);
                }); 
              }
              else // new arrivals
                catDropDown+=getCatLink(this.dLink,this.sLink,this.description,mode);
            });

            catDropDown+='</ul>';

          } // this.prb

          if (catDropDown!='') {
            $('#'+catId).after(catDropDown);
          }

        }); // each category
      }); // each division

      $('.hdrNavLink, .hdrNavLinkSelected').hover(
        function() { // enter
          var catId = $(this).attr('data-cat-id');
          if (catId) // maintain the hover color for the main category link                                   
            $('#'+catId).addClass('hdrNavLinkHover'); 		  
          $('#'+getDropDownId($(this).attr('id'))).show();
        },
        function() { // leave
          var catId = $(this).attr('data-cat-id');
          if (catId) // remove the hover color for the main category link                                   
            $('#'+catId).removeClass('hdrNavLinkHover');   
         $('#'+getDropDownId($(this).attr('id'))).hide();
        }
      );  
	  /*************************v C010002 v*****************************/
      $('.hdrNavLinkSignature, .hdrNavLinkSignatureSelected').hover(
        function() { // enter
          var catId = $(this).attr('data-cat-id');
          if (catId) // maintain the hover color for the main category link                                   
            $('#'+catId).addClass('hdrNavLinkSignatureHover'); 		  
          $('#'+getDropDownId($(this).attr('id'))).show();
        },
        function() { // leave
          var catId = $(this).attr('data-cat-id');
          if (catId) // remove the hover color for the main category link                                   
            $('#'+catId).removeClass('hdrNavLinkSignatureHover');   
         $('#'+getDropDownId($(this).attr('id'))).hide();
        }
      );  
	  /*************************^ C010002 ^*****************************/
    } // ajax complete
  });

} // buildDropDown()

function getDropDownId(id) {
  if (id.indexOf('dd_')==-1)
    id='dd_'+id;
  return id;
}

function getCatLink(dLink,sLink,desc,mode) {
  var link = '';
  if (mode=="dynamic") link = dLink;
  else link = sLink;
  return '<li onclick="document.location.href=\''+link+'\';"><a href="'+link+'">'+desc+'</a></li>';
}



