//
// File : food-rtwgmap-ui.js
//
// Description : Javascript functions for rendering components on a RTWGMap
//               implementation. Overrides several functions found in the 
//               RTWGMap's javascript lib
//
//  




   	//
	// Get the label/header for the side listings
	// @see returnFilteredMarkers
	//
	var getSideListingsLabel = function () {
        var label = "";

		var markerTypeLabel = "";//markerInfo.markerTypeLabel;
        
        if(isFiltering() && selectedFilters[0] != null) {
        	return selectedFilters[0].label + ' ' + markerTypeLabel;
        }
        
    	if(globalRegion && globalRegion.label && markerTypeLabel != globalRegion.label ) { 
        	label = globalRegion.label + " " + markerTypeLabel;
        } else {
            label = markerTypeLabel;
        }
		
		return label;         
    }
 
    //
    // Custom Rendering for Hay Listings on the sidebar
    //
    var renderMarkerForSideListing = function(marker){
        var html = "";
        if(marker != null)
        {
	        //
            // render the marker as a link that calls "myclick(marker.id)" when it's selected
            // (shows the gmap bubble - information bubble usually)
            // with the marker's icon changing colour if/when the mouse is over the link
            //
            // In this implementation the sideListing text will be : 
            //                 <marker.name> - with a href/link to call myclick() to show the info bubble
            //       <marker.additionalInfo.summary>  - number of listings per category
            //                	
            var summary = marker.additionalInfo.summary;
            var name = marker.name.entityify();
            
            // open the marker's info bubble if the sideListing link is clicked
            html += '<a class="smallText" href="javascript:myclick(' + marker.id + ')"';

            // add js to make the marker change it's icon if/when the mouse is over the link
            var highliteImage = '/app68/listings/icons/maps/green.png';
            normalImage = '/app68/listings/icons/maps/red.png';
                
            html += '  onmouseover="gmarkers['+marker.id+'].setImage(\''+ highliteImage + '\'); showTooltip(gmarkers['+marker.id+'], \''+name+'\');  "';
            html += '  onmouseout="gmarkers['+marker.id+'].setImage(\'' + normalImage + '\'); hideTooltip();"';
			
			//side listing text
            html += '  >' +marker.name + '</a><br/><span class="smallText">'  + summary  + '</span><br/><br/>';
        }
        
        return (html);
    }   
   
        
  
 
   

    //
    // Overrides showInfoTabs in rtwgmap-ui.js
    //
    // show the info tabs for a markerObj when the user clicks it's gmarker
    // see createGMarker(markerObj)
    //
    var showInfoTabs = function(gmarker, markerObj) {
              
       // Build the gmarker's window tabs - one for each category
       var tabs = [];
       var infoHtml = markerObj.infoHtml;
         
       //add zoom-in & print links
       var zoomIn = "[<a href=\"javascript:zoomIn('" + markerObj.id + "');\"><span style=\"font-size: 0.80em;\">Zoom In</span>]</a>";
       var print = "";

       if(markerObj.additionalInfo.isAnOrganization != "Y")
         print = "[<a href=\"javascript:printListing('" + markerObj.id + "');\"><span style=\"font-size: 0.80em;\">Print</span>]</a>";
         
	   var footer = "<div style='align: right'>";
 	   footer += zoomIn + "&nbsp;&nbsp;" + print;
 	   footer += "</div>";
 	   
 	   infoHtml += footer;
 	   
       //create the info tab
   	   tabs[0] = new GInfoWindowTab("Info", infoHtml);
      
       var contactHtml = markerObj.additionalInfo.contactHtml;
       if(contactHtml) {
       	 //add a zoom-in link    
       	 contactHtml += footer;
         tabs[1] = new GInfoWindowTab("Contact", contactHtml);
       }
       
       var opts = {maxWidth:340}; 
       gmarker.openInfoWindowTabs(tabs, opts);
    }

   //
    // print the specified listing
    // called from the 'print' link put on the info bubble(s)
    // in showInfoTabs()
    //
    function printListing(id) {
        var url = '/app68/foodindustrylisting?id=' + id;
	    top.consoleRef=window.open(  url,
	                                 'printconsole',
									 'width=600,height=400'
									 +',menubar=0'
									 +',toolbar=1'
									 +',status=0'
								     +',scrollbars=1'
									 +',resizable=1');
   
        top.consoleRef.focus();
        setTimeout('doPrint()',1000);			
	}
  
   	var doPrint = function() {
		top.consoleRef.print();
 	}
    
   //
   // Initialize the side listing with some simple instructions/overview
   //
   var initSideListing = function() {
	    document.getElementById("sideListing").innerHTML = "";
   }


