﻿function SearchKey(e)
{
    var characterCode;
    if(e && e.which)
        characterCode = e.which; //character code is contained in NN4's which property
    else
        characterCode = event.keyCode //character code is contained in IE's keyCode property

    if(characterCode == 13) // enter key
    { 
        return RunSearch();
    }

    return true;
}

function RunSearch() 
{
    var term = escape($("#searchTB").val());
    if (term.length > 0)
        document.location = "/psearch/searchallcommunities.aspx?q=" + term;
    return false;
}

$(document).ready(function () {

    var off = parseInt(0 - $("#HappeningNowDiv").height());
    $("#HappeningNowTable").css("top",off);

   setTimeout (ScrollHappeningNow, 2000);
});

function ScrollHappeningNow()
{
    $("#HappeningNowTable").animate({ "top": "+=60px" }, "200", "linear",
        function() {
            
            var moreHidden = false;
            var visibleTop = $("#HappeningNowDiv").offset().top;
            $("tr[WHRow='1']").each(function(index){
                if (($(this).offset().top+30 > visibleTop) && ($(this).css("visibility") != "visible"))
                    $(this).css("visibility","visible");   
                else if ($(this).css("visibility") != "visible")
                    moreHidden = true;
            });
            
            //var posstr = $("#HappeningNowTable").css("top");
            //var pos = parseInt(posstr.substr(0, posstr.length - 2));
            //if (pos < -30)
            if (moreHidden)
                setTimeout(ScrollHappeningNow, 3000);
        }
    );
}

