/* ...................................................
  
  Common javascript functions.
    
................................................... */

$(document).ready(function() {
  GMCT.footerSearchDefaultText();  
  GMCT.headerSubnavs();
  GMCT.tableRowHighlight();
  GMCT.contentSize();
  
  Cufon.now();
  $("a#single_image").fancybox();
  $(document).ready(function() {
    $("a#mapcontent").fancybox({
      'frameWidth': 800, 'frameHeight': 600,
      'hideOnContentClick': false,
      'callbackOnClose': function() {
        $("#fancy_content").empty();
      }
    });
  }); 
});

Cufon.replace('.home #feature h1, #title');

var GMCT = {
  footerSearchDefaultText: function() {
    var defaultText = "Search GMCT";
    $("#footer .searchText").focus(function() {
      if ($(this).val() == defaultText) {
        $(this).val("");
      }
    }).blur(function() {
      if ($(this).val().length == 0) {
        $(this).val(defaultText);
      }
    });
  },
  
  headerSubnavs: function() {
    $("#header #mainNav ul li").hover(function() {
      $(this).addClass("show")
    }, function() {
      $(this).removeClass("show");
    });
  },
  
  tableRowHighlight: function() {
    $(".moduleContent table tr").hover(function() {
      if (!$(this).children("th").length) $(this).addClass("on");
    }, function() {
      if (!$(this).children("th").length) $(this).removeClass("on");
    });
  },
  
  contentSize: function() {
    var sizeContext = "#content .moduleContent, #content .moduleHeader, #content .landingModule";    
    var size1 = "1em";
    var size2 = "1.25em";
    var size3 = "1.4em";
    var presetFontSize = parseInt($.cookie("fontSize"));
    switch(presetFontSize) {
      case 1:
        $(sizeContext).css( { "font-size": size2 } );
        break;
      case 2:
        $(sizeContext).css( { "font-size": size3 } );
        break;
      case 3:
      default:
        $(sizeContext).css( { "font-size": size1 } );
        break;
    }
    
    $("#footer .tools li a").click(function() {
      var fontSize = parseInt($.cookie("fontSize"));
      var setSize, cookieSize;
      switch($(this).parent("li").index()) {
        case 0: // A-
          if (fontSize == 1 || fontSize == 0) {
            setSize = size1;
            cookieSize = 0;
          }
          else {
            setSize = size2;
            cookieSize = 1;
          }
          break;
        case 1: // A+
          if (fontSize == 1 || fontSize == 2) {
            setSize = size3;
            cookieSize = 2;
          }
          else {
            setSize = size2;
            cookieSize = 1;
          }
          break;
      }
      $(sizeContext).css( { "font-size": setSize } );
      $.cookie("fontSize", cookieSize);
      return false;
    });
    if (!$("body").hasClass("home")) {
      $("#footer .tools ul").css("display", "block");
    }
  }
};
