﻿$.fn.defaultText = function (options) {
    var defaults = {
        css: 'dimmed'
    };
    var options = $.extend({}, defaults, options);

    if (!('text' in options)) return this;

    var input = this[0],
    $input = this,
    offset = $input.offset();

    function hide() {
        $div.hide();
        $input.add($div).removeClass(options.css);
    };

    function show() {
        $div.show();
        $input.add($div).addClass(options.css);
    };

    function focus() {
        if (input.value.length) hide();
        else show();
    };
    var $div = $('<div class="holder">' + options.text + '</div>')
    .css({ position: 'absolute',
        top: offset.top + 30,
        left: offset.left + 30,
        cursor: 'text',
    })
    .click(function () {
        $input.focus();
        focus();
    })
        .addClass(options.css + ' unselectable')
        .appendTo($('.searchbox'));

    $input.addClass(options.css)
        .keyup(focus).blur(function () {
            if (!input.value.length) show();
        });

    return this;
};



$(document).bind("ready", function () {
    Menu.init();
});

//$(document).bind('click', function () {
//    Menu.hide();
//});

var Menu = {
    init: function () {
        if(document.getElementById("Query")) {
           $('#Query').defaultText({
                text: 'Search'
            });
}

        if(document.getElementById("searchicon")) {
            $('header .mainmenu #searchicon').hover(function() {
                $(this).find('.searchbox').fadeIn('fast');
            }, function () {
                $(this).find('.searchbox').fadeOut('fast');
            });
        }
        //        $('#header .topbox .mainmenu li.search_icon').bind('mouseover', MenuShowTimer);
        //        $('#header .topbox .mainmenu li.search_icon').bind('mouseout', MenuHideTimer);
    },
    hide: function () {
        
            }

    //    return {
    //        Init: function () {
    //            $('#header .topbox .mainmenu li.search_icon').bind('mouseover', MenuShowTimer);
    //            $('#header .topbox .mainmenu li.search_icon').bind('mouseout', MenuHideTimer);
    //        }
    //    }

    //    return {
    //        Hide: function () {
    //            alert("hide");
    //        }
    //    }

    //    function MenuShowTimer() {
    //    }

    //    function MenuHideTimer() { }
}
