// Initializes User Scripts:
$(document).ready(function() {
  var siteWidth = 1000;
  var separatorWidth = 2;
 // $('#topMenu>li').width((siteWidth - (($('#topMenu>li').size() - 1) * separatorWidth)) / $('#topMenu>li').size());
  
 $("#fbook").hide(); 
  $(".toggle").click(function () { 
   $("#fbook").slideToggle("slow");

    var latlng = new google.maps.LatLng(44.061686, -121.311035);
  var myOptions = {
    zoom: 12,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map($("#locationsMap").get(0), myOptions);
      
  // Get locations for Markers
  var markers = [];
  pixelsilk2.getListItems({
    path: "/Events/",
    fields: ["Title", "Address", "City", "State", "Zip", "ContactPhone", "LatLon"],
    filters: [],
    filterrel: "",
    sorts: [],
    pagesize: "1000",
    page: "1"
  }, function(data) {
    if ( data.length ) {
      var infoWin = new google.maps.InfoWindow();
      $.each(data, function(i, item) {
        var coords = item.LatLon.split(',');
        var ll = new google.maps.LatLng(Number(coords[0]), Number(coords[1]))
        var marker = new google.maps.Marker({
          position: ll,
          map: map,
          title: item.Title,
          icon: "/map-icon2.gif"
        });
        var html = '<div><strong>' + item.Title + '</strong></div>' +
            '<div>' + item.Address + '</div>' +
            '<div>' + item.City + ' ' + item.State + ', ' + item.Zip + '</div>' +
            '<div>' + item.Phone + '</div>';
        google.maps.event.addListener(marker, 'click', function() {
          infoWin.setContent(html);
          infoWin.open(map, marker);
        });
        markers.push(marker);
      });
    }
  }); 
 });
  
// resizeColumns();
// setInterval(resizeColumns, 1000);
groupHeaders();
  $('.slidesTxt').show();
  
  // Selects text in Search Box when focused:
  $('input.txtSearch').focus(function() {
    this.select();
  });
  $('input.txtSearch').blur(function() {
    if ( $(this).val() == '' ) $(this).val('search');
  });

  // Links - pop up in new window / tab:
  $("a.lnkBlank").click(function() {
    window.open($(this).attr("href"), 'window2', '');
    return false;
  });

  $("img").each(function() {
    var img = $(this).attr("src");
    if ( typeof(img) == 'undefined' || img == '' || img == '/' || img.substr(0, 1) == '?' || img.substr(0, 2) == '/?' ) $(this).hide();
  });
   $(".avMediaLink").each(function() {
     var disable = $(this).attr("href");
     if ( typeof(disable) == 'undefined' || disable == '' || disable == '/' || disable.substr(0, 1) == '?' || disable.substr(0, 2) == '/?' ) $(this).hide();
   });
  
   $(".avPdfLink").each(function() {
     var disable = $(this).attr("href");
     if ( typeof(disable) == 'undefined' || disable == '' || disable == '/' || disable .substr(0, 1) == '?' || disable .substr(0, 2) == '/?' ) $(this).hide();
   });

  pixelsilk2.renderSkin({skin: '[' + '[Menu1]' + ']', path: ''}, function(html) {
    $("#siteMenu").after('<div id="subNavigation" style="display:none;"></div>');
    $("#subNavigation").html(html);
    var sections = $("#subNavigation div");
    var topElements = $("#topMenu li:not(.separator)");
    for (z = 0; z < sections.length; z++) {
      var li = topElements[z];
      var lihtml = li.innerHTML;
      li.innerHTML = lihtml + sections[z].innerHTML;
    }
    $("#topMenu").navMenu({
      menuWidth: 200,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: ' &raquo;'
    });
    $("#subNavigation").remove();
   // If the menu name is about make the sub navigation appear on the left
    $("#siteMenu ul li:contains('About')").find('ul li ul').css('left', '-250px');
    addBorder();
  });
});


function groupHeaders(){
  var categoryGroup = "somethingrandom";
  $("#calendarItems #CalendarDay .groupHeading").each(function(){
    if ($(this).text() != categoryGroup)
      categoryGroup = $(this).text();
    else
      $(this).hide(0);
  });
}

function resizeColumns(){
var highestCol = Math.max($('#mainColumn').height(),$('#rightColumn').height()); $('.mainCols').height(highestCol);
}

function addBorder(){
 $('#siteMenu ul li.topLevel').hover(function(){
if ($(this).children().size() <= 1)
   $(this).css('border-bottom', '1px solid #475B5B')
},
function (){
$(this).css('border-bottom', 'none')
}
)
 };
