﻿$(document).ready(function()
{
    // logic for the show more links
    $('#search input[type=text]').watermark();
    $(".expandable").expandableList(6);
    $(document).btnClass();

    // Save recent searches to cookie
    $("#search form").submit(function()
    {
        var searches = $.cookieJSON("latestSearches") || [];
        var keywords = $("#keywords").value();
        var location = $("#location").value();

        // only add a search if it's not already in the list
        for (var x = 0; x < searches.length; x++)
        {
            var search = searches[x];
            if (search.keywords.toLowerCase() == keywords.toLowerCase() &&
                search.location.toLowerCase() == location.toLowerCase())
                return;
        }
        searches.unshift({ keywords: keywords, location: location });
        if (searches.length > 5)
            searches.pop();
        $.cookieJSON("latestSearches", searches, { expires: 90 });
    });
});
