/* This file contains helper functions for the file: s_code.js file*/

/* TODO: This file has dependency on the css of the page. this dependency need to removed when Search & Detail pages are re-done*/

function countLinks()
{
        // Get the number of links in the Left Nav for Search Results pages
        var re = new RegExp("Search Results");
        if (re.test(s.pageName)) { s.prop25 = jQuery('#lMenu a').length -1; }
        re = new RegExp("Embedded Search");
        if (re.test(s.channel)) { s.prop25 = jQuery('#lMenu a').length-1; }

        s.prop32 = '';
        var widgetNames = new Array();
        // Count the number of views of HUC page in a visit
        re = new RegExp("HUC");
        if (re.test(s.channel)) {
                s.eVar31="+1"; 
                // Get the widgets displayed on the HUC Page
                var hucWidgets = jQuery('#widgetsTable h4');
                for (key in hucWidgets) {
                  if (hucWidgets[key].id) {
                    widgetNames.push(hucWidgets[key].id);
                  }
                }
        }
        // Get the widgets displayed in the leftnav
        if (jQuery('#lMenu') != null && jQuery('#lMenu h4').length > 0) {
        	var leftNavWidgets = jQuery('#lMenu h4');
        	for (key in leftNavWidgets) {
        		if (leftNavWidgets[key].id) {
        			widgetNames.push(leftNavWidgets[key].id);
        		}
        	}
        }
        
        // populate s.prop37 if you-may-also-like widget is displayed
        if ( jQuery('#dpAcc') != null && jQuery('#dpAcc').length > 0 ) { widgetNames.push('ymal'); s.prop37=jQuery('#dpAcc img').length; }
        // populate s.prop37 if complete-the-look widget is displayed
        if ( jQuery('#ctl') != null && jQuery('#ctl').length > 0 ) { widgetNames.push('ctl'); s.prop37=jQuery('#ctl img').length;}
        // populate s.prop37 if Add-a-little-extra widget is displayed
        if ( jQuery('#flowersTable') != null && jQuery('#flowersTable').length > 0 ) { widgetNames.push('ale'); s.prop37=jQuery('#flowersTable img.pImg').length; }
        // populate s.prop37 if complete-the-set widget is displayed
        if ( jQuery('table.pDetail') != null && jQuery('table.pDetail').length > 0 ) { widgetNames.push('cts'); s.prop37=jQuery('table.pDetail').length; }

        // populate s.prop32 with the widget acronyms displayed on the page
        s.prop32 = widgetNames.join('|');
        // populate s.prop38 with the number of swatches displayed on the page. tableFabrics is for Furniture pages.
        s.prop38 = ( jQuery('#swatchImageTable a')!=null && jQuery('#swatchImageTable a').length ) ? jQuery('#swatchImageTable a').length : (jQuery('#tableFabrics a')!=null?jQuery('#tableFabrics a').length:0);

}

