jQuery(function(){
  if(document.getElementById('insertYear')) document.getElementById('insertYear').innerHTML = new Date().getFullYear();
});

function tabClick(selectedTab) {
  $('.searchToolTab.current').removeClass('current');

  $('#' + selectedTab).addClass('current');
  
  if($('#miniButtons.minimized').length > 0){
    toggleMiniClick(true);
  }
  
  return false;
}

function toggleMiniClick(fromTabClick){
  if($('#miniButtons.minimized').length > 0){
    $('#miniButtons').removeClass('minimized');
    $('#searchMini').removeClass('minimized');
    if(!fromTabClick){
      tabClick('propertyTab');
    }
  }
  else{
    $('#miniButtons').addClass('minimized');
    $('#searchMini').addClass('minimized');
    $('.searchToolTab.current').removeClass('current');
  }
}

function mapClick(province) {
  if($('#propertyTab.current').length > 0){
     window.location = '/rsearch/property/'+province;
     //$('#edit-property-location').val(province);
     //$('#edit-property-location')[0].focus();
     //$('#edit-property-location').keyup();
  }
  else if ($('#agentTab.current').length > 0){
    $('#edit-agent-location').val(province);
        $('#edit-agent-location')[0].focus();
        $('#edit-agent-location').keyup();
  }
  else if ($('#officeTab.current').length > 0){
    $('#edit-office-location').val(province);
    $('#edit-office-location')[0].focus();
    $('#edit-office-location').keyup();
  }
}

jQuery(function() {
  $("input:submit").mouseover(function() {$(this).addClass("hovered");}).mouseout(function() {$(this).removeClass("hovered");})
});


var externalLinks = {
  init: function(){
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
      if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
    }
  }
}

function siteOnload(){
  if(typeof Drupal != "undefined"){
    if(typeof Drupal.makeCollapse == "function"){
      Drupal.makeCollapse();
    }
  }
  externalLinks.init();
}

function addLoadEvent(func){
  var oldOnLoad = window.onload;
  if(typeof window.onload != 'function'){
    window.onload = func;
  }
  else{
    window.onload = function(){
      oldOnLoad();
      func();
    }
  }
}

addLoadEvent(siteOnload);