﻿
        $(function () {
            
            $('#frm_search input[name=q]').keyup(function () {
                var $txt = $(this);
                var $panel = $('#frm_search .subResults');
                var val = $txt.val();

                var url = '/Products/QuickSearch?q=' + val;

                $panel.hide().find('.subResults-item').remove();

                $.getJSON(url, function (data) {
                    if (data.length > 0) {
                        $panel.show().find('.subResults-item').remove();
                    }

                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        $(quickSearchResultItem(item.DefaultPhoto, item.ProductName, item.SKU, '/Products/View/' + item.ProductId)).prependTo($panel);
                    }

                });




            }).blur(function () {
                setTimeout("$('#frm_search .subResults').hide();", 5000);
            });



            $('.em_pop').click(function () {
                var id = $(this).attr('href');

                //centerThis($(id).find('.popup-container'));

                $(id).fadeIn('fast');
                //return false;
            });
        });

        function centerThis(centerDiv) {
            var winH = $(window).height();
            var winW = $(window).width();

            centerDiv.css('top', winH / 2 - centerDiv.height() / 2);
            centerDiv.css('left', winW / 2 - centerDiv.width() / 2);
        } 

        function quickSearchResultItem(thumb, name, sku, url) {
            var html = '<div class="subResults-item clearfix">';
            html += '<div class="_photo"><img src="/Files/Items/85_85/' + thumb + '" alt="" /></div>';
            html += '<div class="_details">';
            html += '<div class="_title"><a href="' + url + '">' + name + '</a></div>';

            if (sku!=null && sku != '')
                html += '<div class="_sku">' + sku + '</div>';

            html += '</div>';
            html += '</div>';


            return html;
        }

        $(function () {

            $('.cb_filter').click(function () {
                $(this).parents('form').submit();
            });

            $('.subCategories').each(function () {
                var $li = $(this).parents('li');
                var $menu = $(this);

                $li.hover(
                    function () {
                        $menu.show();
                    }, 
                    function () { $menu.hide(); }
                );
            });
            });


            
