﻿$(document).ready(function() {
    $('#Term').val('Search');
    $("#Term").click(function() {
	    $('#Term').val('');
    });
    $("#Term").keyup(function() {
        if (($(this).val() == null || $(this).val() == "") && $(".matchesBox").css("display") == "block") {
            $(".matchesBox").css("display", "none");
        } else {
            var term = $(this).val();
            var url = matchesUrl + term;
            $.get(url, null, function(data) {
                $("#matches").html(data);
                if ($("#matches ul li").html() != null && $("#matches ul li").html() != "") {
                    $(".matchesBox").css("display", "block");
                } else {
                    $(".matchesBox").css("display", "none");
                }
                InitializeMatches();

            });
        }
    });
    InitializeMatches();



    //    var sFocus = false;
    //    
    //    $("#Term").focus(function() {
    //        sFocus = true;
    //    });
    //    
    //    $("#Term").blur(function() {
    //        sFocus = false;
    //    });

    //    $("#Term").blur(function() {
    //        $('#matchesBox').css('display', 'block');
    //    });

});

function InitializeMatches() {
    $(".resultItemLink").click(function() {
        var href = $(this).attr("href");
        var term = $(this).attr("name");
        var url = logUrl + term;
        $.get(url, null, function(data) {
        });
        location.href = href;
        return false;
    });
}