﻿
$(document).ready(function () {

    $("#go").click(function () {
        if ($("#query").val() != "")
            window.location = "default.aspx?q=" + encodeURIComponent($("#query").val());
    });

    $("#query").keyup(function (e) {
        alertkey(e);
    });

    $("#taexpand").click(function () {
        if ($(this).attr("class") == "plus") {
            $(this).attr("class", "minus");
            $("#tagraphic").slideDown();
            $("#handle_speed span").text("pause");
        }
        else {
            $(this).attr("class", "plus");
            $("#tagraphic").slideUp();
            $("#handle_speed span").text("medium");
        }
    });

    $("#tagraphic").hide();

    $("#tryitclose").click(function () {
        $("#tagraphic").slideUp();
        $("#taexpand").attr("class", "plus");
        setCookie("twendzad", "true", 30);
        $("#handle_speed span").text("medium");
    });

    $("#tryitnow").click(function () {
        setCookie("twendzad", "true", 30);
    });
    
    if (getCookie("twendzad") == null) {
        $("#taexpand").click();
        $("#handle_speed span").text("pause");
    }

    animateBar();

});

var isOff = true;
function animateBar() {
    if (isOff) {
        isOff = false;
        $("#topcontentsearch").css({ backgroundPosition: "0 0" }).animate({ backgroundPosition: "(-460px 0)" }, 2500, function () {
            setTimeout(animateBar, 2500);
        });
    }
    else {
        isOff = true;
        $("#topcontentsearch").animate({ backgroundPosition: "(0 0)" }, 2500, function () {
            setTimeout(animateBar, 2500);
        });
    }
}

function alertkey(e) {
    if (!e) {
        if (window.event) {
            //Internet Explorer
            e = window.event;
        } else {
            return;
        }
    }
    if (typeof (e.keyCode) == 'number') {
        //DOM
        e = e.keyCode;
    } else if (typeof (e.which) == 'number') {
        //NS 4 compatible
        e = e.which;
    } else if (typeof (e.charCode) == 'number') {
        //also NS 6+, Mozilla 0.9+
        e = e.charCode;
    } else {
        //total failure, we have no way of obtaining the key code
        return;
    }
    if (e == 13) {
        window.location = "default.aspx?q=" + encodeURIComponent($("#query").val());
        return false;
    }
}

