// JavaScript Document
var button_image;
var sidebar_left;
var center;
var sidebar_right;
var sidebar_right_last;
var myDate = new Date();
var year = myDate.getFullYear();
function show_sub(element) {
    $(element).addClass("hover").children("ul.sub").show();
}
function hide_sub(element) {
    $(element).removeClass("hover").children("ul.sub").hide();
}
function adjust_heights() {
    sidebar_left_height = sidebar_left.height();
    sidebar_right_height = sidebar_right.height();
    target_height = Math.max(sidebar_left_height, center.height(), sidebar_right_height) + 20;
    if (sidebar_left_height < target_height) {
        sidebar_left.height(target_height);
    }
    /*
	if (sidebar_right_height < target_height) {
		sidebar_right_last.height(target_height - sidebar_right_height + sidebar_right_last.height() - 1);
	}*/
}
// function initmenu() {
//     $.get('/lyme-clean/inc/navigation.html', function(data){
//         $('#primary_links').html(data);
//         // show/hide of sub-links of Primary Navigation
//         $('#primary_links a').each(function() {
//             var windowObject = window.location.href;;
//             var link = $(this).attr('href');
//             $(this).attr('href',windowObject+link);
//         });
//         $("#primary_links li.has_sub").hover(function() { show_sub(this); }, function() { hide_sub(this); });
//     });    
// }

$(document).ready(function() {
    // initialize variables
    sidebar_left = $("#sidebar_left");
    center = $("#center");
    initial_center_height = center.height();
    sidebar_right = $("#sidebar_right");
    sidebar_right_last = $("#sidebar_right div.sidebar_item:last");
    // adjust heights of left and right sidebars
    adjust_heights();
    //load menu 
    //initmenu();
    //load navigaiton 
    // hover button images
    $("#primary_links li.has_sub").hover(function() { show_sub(this); }, function() { hide_sub(this); });
    $(".button_image").hover(
    function() {
        button_image = $(this).attr("src");
        $(this).attr("src", button_image.replace(".", "_hover."));
    },
    function() {
        $(this).attr("src", button_image);
    }
    );
    // highlight query text
    $("#search_query").focus(function() {
        $(this).val("");
    });
    // re-check center height for variable image heights
    $(window).load(function() {
        if ($("#center").height() != initial_center_height) {
            adjust_heights();
        }
    });
    $('em.year').text(year);
});