$.expr[':'].focus = function(a){ return (a == document.activeElement); }


    $(function () {
       $('#password-hint').attr('value', 'hasło');
       $('#password-hint').show();
       $('#password').hide();
       
       $('#login-hint').attr('value', 'e-mail');
       $('#login-hint').show();
       $('#login').hide();
       
       $('#search-hint').attr('value', 'wyszukaj produkt');
       $('#search-hint').show();
       $('#search').hide();

        $('#name').inputHint({
            css:{'color':'grey'},
            attr:{'id':'', 'name':'', 'value':'Imię i nazwisko'}
        });
       
        $('#email').inputHint({
            css:{'color':'grey'},
            attr:{'id':'', 'name':'', 'value':'Adres email'}
        });
       
        $('#message').inputHint({
            css:{'color':'grey'},
            attr:{'id':'', 'name':'', 'value':'Wiadomość...'}
        });
        
        $('#search-form').attr('autocomplete', 'off');
       
        $('#search-button').click(function(){
            $('#search-form').submit();
        })
        
       
        $("#search").autocomplete({
            url: '?mode=ajax&action=search',
            paramName: 'search',
            maxItemsToShow: 10,
            useCache: false,
            onFinish: function() {
                if ($('#search').is(":focus")) {
                    $('#search-form').submit();
                }
            },
            noResult: function() {
                return '<li style="font-size:11px; padding:10px; text-align:left;">Brak wyników wyszukiwania</li>';
            },
            showResult: function(value, data) {
                    if (data[1] == 1)
                        return '<div style="height:63px; border-bottom:1px solid #d7d7d7; border-top:1px solid #f7f7f7; font-size:10px;"><div style="padding:5px; text-align:left;"><div style="border:1px solid #d7d7d7; padding:5px; float:left; background-color:#fff; width:40px; height:40px; text-align:center; margin-right:5px;"><img style="margin-left:auto; margin-right:auto;" src="image.php/'+value+' (gemat.pl).jpg?width=40&amp;height=40&amp;image=data/product/' + data[0] + '.jpg&amp;color=#000000" alt="" /></div><div style="max-height:32px; margin-bottom:4px; overflow:hidden">' + value + '</div><div style="color:grey;">'+ data[3]+' zł<br />cena netto:'+ data[2]+' zł</div></div></div>';
                    else 
                        return '<div style="height:63px; border-bottom:1px solid #d7d7d7; border-top:1px solid #f7f7f7; font-size:10px;"><div style="padding:5px; text-align:left;"><div style="border:1px solid #d7d7d7; padding:5px; float:left; background-color:#fff; width:40px; height:40px; text-align:center; margin-right:5px;"><img style="float:left;" src="image.php/'+value+' (gemat.pl).jpg?width=40&amp;height=40&amp;image=data/product/nopicture.jpg&amp;color=#000000" alt="" /></div><div style="max-height:32px; margin-bottom:4px; overflow:hidden">' + value + '</div><div style=" color:grey;">'+ data[3]+' zł<br />cena netto:'+ data[2]+' zł</div></div></div>';
            }
        });
       
       
      
       $('#password-hint').focus(function() {
            $('#password-hint').hide();
            $('#password').show();
            $('#password').focus();
        });
        $('#password').blur(function() {
            if($('#password').val() == '') {
                $('#password-hint').show();
                $('#password').hide();
            }
        });
        
        $('#login-hint').focus(function() {
            $('#login-hint').hide();
            $('#login').show();
            $('#login').focus();
        });
        $('#login').blur(function() {
            if($('#login').val() == '') {
                $('#login-hint').show();
                $('#login').hide();
            }
        });
        
        $('#search-hint').focus(function() {
            $('#search-hint').hide();
            $('#search').show();
            $('#search').focus();
        });
        $('#search').blur(function() {
            if($('#search').val() == '') {
                $('#search-hint').show();
                $('#search').hide();
            }
        });
                    
            
        $('.mitem').hoverIntent({
            over: showMenu, 
	    timeout: 500, 
	    out: hideMenu
	    });
        
        $('#category-menu').hoverIntent({over:function(){}, out:function(){
            $('.smitem').hide();
            $('#overlay').hide();
        }, timeout:500})
        
        


    })
    
    function showMenu(){
        id = parseInt($(this).attr('id').substr(6));
        $(this).parent('ul').find('.smitem').hide();
            $('#container_'+id).show();
            $('#overlay').show();
        }
    function hideMenu(
        
    ){ }
    
    $(document).ready(function() {
              var options = {
                newsList: "#ticker",
                startDelay: 2000,
                placeHolder1: "_",
                tickerRate: 140,
                resumeOffHover: false,
                stopOnHover: false
              }
              $().newsTicker(options);
              $('#ticker').show();
            });
    
    
    $(document).ready(function() {	
        $('#login-submit').click(function(){$('#login-form').submit()});
        
        $('.more').click(function(){
            var id = $(this).attr('id').split('-');
            id = id[1];
            $('#'+id).slideDown(0);
            $(this).hide();
            $('#less-'+id).show();
        })
        
        $('.less').click(function(){
            var id = $(this).attr('id').split('-');
            id = id[1];
            $('#'+id).slideUp(0);
            $(this).hide();
            $('#more-'+id).show();
        })

	
});//Close Function
