/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/
google.load("jquery", "1.3.1");
google.setOnLoadCallback(function () {
    // Safely inject CSS3 and give the search results a shadow
    //	var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
    //		'-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
    //		'-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
    //	$("#suggestions").css(cssObj);

    // Fade out the suggestions box when not active



    $("input").blur(function () {

        if (!$.browser.msie) {


            $('#suggestions, #arrow').fadeOut();
        }
        else {

            $('#suggestions').fadeOut();
        }

    });
});

var intervalid = null;
var thesearch

function lookupkeydown() {
    if (intervalid != null)
    {
        clearTimeout(intervalid);
    }
    intervalid = null;
}



function lookup(inputString) {


    if (intervalid != null) {
        clearTimeout(intervalid);
    }
    intervalid = null;

    thesearch = inputString;
    intervalid = setTimeout("lookat()",400);
}



function lookat() {

    if (thesearch.length == 0) {

        $('#suggestions, #arrow').fadeOut(); // Hide the suggestions box
    }
    else {



        if (!$.browser.msie) {
            $.post("/rpc.aspx", { queryString: "" + thesearch + "" }, function (data) { // Do an AJAX call

                $('#suggestions').html(data); // Fill the suggestions box



                if (!jQuery.browser.msie) {

                    $('#suggestions, #arrow').fadeIn(); // Show the suggestions box

                }
                else {

                    $('#suggestions').fadeIn(); // Show the suggestions box

                }
                var divh = document.getElementById('suggestions').offsetHeight;

                var res = 400 - divh / 2;
                if (res < 40) {

                    res = 40;
                }


                if (!$.browser.msie) {

                    document.getElementById('suggestions').setAttribute('style', 'top:' + res + 'px; width:380px;');
                    $('#suggestions, #arrow').fadeIn(); // Show the suggestions box
                }
                else {

                    document.getElementById('suggestions').style.cssText = 'top:' + res + 'px; width:320px;';
                    $('#suggestions').fadeIn(); // Show the suggestions box

                }


            });





        }
        else {

            $.post("/rpc2.aspx", { queryString: "" + thesearch + "" }, function (data) { // Do an AJAX call

                $('#suggestions').html(data); // Fill the suggestions box



                if (!jQuery.browser.msie) {

                    //$('#suggestions, #arrow').fadeIn(); // Show the suggestions box

                }
                else {

                    $('#suggestions').fadeIn(); // Show the suggestions box

                }

                var divh = document.getElementById('suggestions').offsetHeight;

                var res = 400 - divh / 2;
                if (res < 40) {

                    res = 40;
                }


                if (!$.browser.msie) {

                    document.getElementById('suggestions').setAttribute('style', 'top:' + res + 'px; width:380px;');
                    $('#suggestions, #arrow').fadeIn(); // Show the suggestions box
                }
                else {

                    document.getElementById('suggestions').style.cssText = 'top:' + res + 'px; width:320px; border:1px solid BLACK; background-color:White;';
                    $('#suggestions').fadeIn(); // Show the suggestions box

                }


            });





        }

//        $.post("rpc.aspx", { queryString: "" + thesearch + "" }, function (data) { // Do an AJAX call

//            $('#suggestions').html(data); // Fill the suggestions box



//            if (!jQuery.browser.msie) {

//                $('#suggestions, #arrow').fadeIn(); // Show the suggestions box

//            }
//            else {

//                $('#suggestions').fadeIn(); // Show the suggestions box

//            }
//            var divh = document.getElementById('suggestions').offsetHeight;

//            var res = 400 - divh / 2;
//            if (res < 40) {

//                res = 40;
//            }
//            

//            if (!$.browser.msie) {

//                document.getElementById('suggestions').setAttribute('style', 'top:' + res + 'px; width:380px;');
//                $('#suggestions, #arrow').fadeIn(); // Show the suggestions box
//            }
//            else {

//                document.getElementById('suggestions').style.cssText = 'top:' + res + 'px; width:320px;';
//                $('#suggestions').fadeIn(); // Show the suggestions box

//            }


//        });
    }
    
}




