var ACTUAL_CATEGORY_ID = 0;

$(document).ready(function(){
    if($("#shop_list_quick_search").length > 0)
    {
        $("#shop_list_quick_search").blur(function(){
            $(this).val($(this).attr("title"));
        });

        $("#shop_list_quick_search").click(function(){
            $(this).val('');
        });

        $("#shop_list_quick_search").keyup(function(){

            $("#uzlet-lista").scrollTop(0);

            if($("#shop_list_quick_search").val() == '')
            {
                $("#uzlet-lista ul li").show();
            }
            else
            {
                var filter_text = $("#shop_list_quick_search").val().toLowerCase();
                $("#uzlet-lista ul li").each(function(){
                    //alert($(this).text());
                    
                    if($(this).text().toLowerCase().indexOf(filter_text)!=-1)
                    {
                        $(this).show();
                    }
                    else
                    {
                        $(this).hide();
                    }
                });
            }
            //$(uzlet-lista)
        });
    }

    if($(".quick_search_box").length > 0)
    {
        $(".quick_search_box .search_field").blur(function(){
            $(this).val($(this).attr("title"));
        });

        $(".quick_search_box .search_field").click(function(){
            $(this).val('');
        });

        $(".quick_search_box .search_field").keyup(function(){

            $(this).parent().prev().scrollTop(0);

            if($(this).val() == '')
            {
                $(this).parent().prev().children().children("li").show();
            }
            else
            {
                var filter_text = $(this).val().toLowerCase();
                $(this).parent().prev().children().children("li").each(function(){
                    //alert($(this).text());

                    if($(this).text().toLowerCase().indexOf(filter_text)!=-1)
                    {
                        $(this).show();
                    }
                    else
                    {
                        $(this).hide();
                    }
                });
            }
            //$(uzlet-lista)
        });
    }

    $("#search_field").click(function(){
        $(this).val('');
    });

    $("#search_field").blur(function(){
        if($(this).val() == '')
        {
            $(this).val($(this).attr("title"));
        }
    });

    $("#search a.submit").click(function(e){
       e.preventDefault();
       $('form[name='+$(this).attr("rel")+']').submit();
    });

    if($("ul.categories li a").length > 0)
    {
        $("ul.categories li a").click(function(e){
            $("ul.categories li a").removeClass('active');
            $(this).addClass('active');
            if($(".subcategory_groups_wrapper ul#subcategory_group_of_"+$(this).attr('rel')+" li").length > 0)
            {
                ACTUAL_CATEGORY_ID = $(this).attr('rel');
                e.preventDefault();
                if($("#subcategories").css('display') != 'none')
                {
                    var id = $(this).attr('rel');
                    $("#subcategories").slideUp('fast', function(){
                        $(".subcategory_groups_wrapper ul").hide();
                        $(".subcategory_groups_wrapper ul#subcategory_group_of_"+id).show();
                        $(".menu-rightside-banner").hide();
                        $("#banner-for-menuitem-"+id).show();
                        $("#subcategories").slideDown('fast');
                    });
                }
                else
                {
                    $(".subcategory_groups_wrapper ul").hide();
                    $(".subcategory_groups_wrapper ul#subcategory_group_of_"+$(this).attr('rel')).show();
                    $(".menu-rightside-banner").hide();
                    $("#banner-for-menuitem-"+$(this).attr('rel')).show();
                    $("#subcategories").slideDown('fast');
                }
            }
        });
    }

    if($("#terkep").length > 0)
    {
        $("#terkep #terkep-mo img").maphilight();

        $("#terkep-mo a#teljes-lista").click(function(e){
            e.preventDefault();
            $("#uzlet-lista ul li").addClass('colored');
            $("#uzlet-lista ul li.empty").removeClass('colored');
        });

        $("#terkep-bp a#budapest").click(function(e){
            e.preventDefault();

            var href = $(this).attr("href");
            href = href.split('/');
            href = href[href.length-1];

            $("#uzlet-lista ul li").removeClass('colored');
            $("#uzlet-lista ul li."+href).addClass('colored');
        });

        $("#terkep-bp a#vissza").click(function(e){
            e.preventDefault();
            $("#terkep-bp").fadeOut('slow', function(){
                    $("#terkep-mo").fadeIn('slow');});
            $("#uzlet-lista ul li").removeClass('colored');
        });

        $("#terkep map area").click(function(e)
        {
            e.preventDefault();
            var href = $(this).attr("href");
            href = href.split('/');
            href = href[href.length-1];

            if(href=='budapest')
            {
                $("#terkep-mo").fadeOut('slow', function(){
                    $("#terkep-bp").fadeIn('slow');

                    if(!$("#terkep #terkep-bp img").hasClass('maphilighted'))
                    {
                        $("#terkep #terkep-bp img").maphilight();
                    }
                });
            }

            $("#uzlet-lista ul li").removeClass('colored');
            
            $.fn.reverse = [].reverse;
            var selected = $("#uzlet-lista ul li."+href).reverse();
            $("#uzlet-lista ul li."+href).remove();

            $.each(selected, function(i, value){
                $("#uzlet-lista ul").prepend(value);
            });


            $("#uzlet-lista ul li."+href).addClass('colored');

            $("#uzlet-lista").scrollTop(0);
        });
    }

    if($(".product-box select").length > 0){
        $(".product-box select").change(function(){
            window.location = $(this).val();
        });
    }
});



