//This function is used in Office Reference component and Office page
function displayMap(id) {
    var geocoder = new google.maps.Geocoder();
    var mapZoom = document.getElementById(id + "_zoom").innerHTML;
    var myOptions = {
      zoom: parseInt(mapZoom),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById(id + "_map_canvas"), myOptions);
    
    var address = document.getElementById(id + "_officeAddress").innerHTML;

    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location,
            title: 'Newedge Office'
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }

//The displayTime function for the TimeZone Component
function displayTime(divID) {
    //Set the time out to 1 min, so it refreshes every min
    setTimeout("displayTime('" + divID + "')", 60000);
    var dateTimeElement = $("#" + divID).text();
    var currentDateTime = new Date(dateTimeElement);

    //get hours
    var hours = currentDateTime.getHours();
    if (hours <= 9)
        hours = "0" + hours;

    //get mins
    var minutes = currentDateTime.getMinutes();
    if (minutes <= 9)
        minutes = "0" + minutes;

    //set hours/mins in its respective span
    $("#" + divID + "_hours").text(hours);
    $("#" + divID + "_minutes").text(minutes);
    //set back the time + 1 min for next iteration
    currentDateTime.setMinutes(currentDateTime.getMinutes() + 1);
    $("#" + divID).text(currentDateTime.toString());
}


$.ajaxSetup({
    cache:false
});


$(document).ready(function(){

/*** HELP
  how to:
  <a class="help" rel="[target]"></a>
  <div id="[target]">text</div>

  automatically hides the #id (preserving it's display attribute)
  click ? opens the id in the rel attribute and changes the ? to x
  clicking x closes the id and switches back to ?

  on ajaxed content, call the fnct on the page directly
  $('.help').toggleHelp();

***/
$(".help").each(function(){
  $(this).text("[ ? ]");
  var openTarget = $(this).attr('rel');
  $('#'+openTarget).hide();
});

 $.fn.toggleHelp = function(){
  var openTarget = $(this).attr('rel');
  $('#'+openTarget).hide();

  $(".help").toggle(function(){
    $(this).text('[ x ]').addClass('helpOn');
    $('#'+openTarget).show();
  },
  function(){
    $(this).text('[ ? ]').removeClass('helpOn');
    $('#'+openTarget).hide();
  });
}
$('.help').toggleHelp();




//$(".showHide").each(function(){
//  $(this).text("[ view more ]");
 // var openTarget = $(this).attr('rel');
  //$('#'+openTarget).hide();
//});

 $.fn.showHide = function(){
  var openTarget = $(this).attr('rel');
  $(this).text("[ view more ]");
  //$('#'+openTarget).show();
  $(".showHide").toggle(function(){
    $(this).text('[ view less ]')
    $('#'+openTarget).show('med');
    //$('#'+openTarget).hide();
  },
  function(){
    $(this).text('[ view more ]');
    $('#'+openTarget).hide("med");
  });
}
$('.showHide').showHide();





 //for alternating list items
 $('.altList > li:even').addClass('altItem');
 //for alternating rows
 $('.altRows > tr:even').addClass('altRow');

 //add icons to filetype links
 var $filelinks = $('a[href]').not('[href$="html"]');
 $filelinks.each(function(){
     if($(this).children($("img")).length > 0){
         return;
     }
 
     var $link = $(this).attr('href');
     var filetype = $link.split('.').pop().toLowerCase();
     switch(filetype){
         case'pdf':
         case'doc':
         case'dot':
         case'docx':
         case'xls':
         case'xlsx':
         case'doc':
         case'csv':        
         case'ppt':
         $(this).addClass("icon type_"+filetype);
         break;
         
         default:
           return;     
     }
    
});
 
}); //end of $(document).ready function




