$(document).ready(function() {

    $('.shop_search_input[value=""]').attr('value', trn['search_text']);

    $('.shop_search_input').attr('autocomplete', 'off');

    $('.shop_search_input').focus(function() {

        $(this).select();

        if ($(this).attr('value') == trn['search_text']) {
            $(this).attr('value', '');
        }

        $('.shop_search_field').toggleClass('shop_search_field_selected');


    }).blur(function() {

        if ((typeof($(this).attr('value')) == 'undefined') || $(this).attr('value') == '') {
            $(this).attr('value', trn['search_text']);
        }

        $('.shop_search_field').toggleClass('shop_search_field_selected');
    });
    
    $('#shop_search_input').autocomplete('/shop/ajax.php?type=search', {
        minChars : 3,
        cacheLength : 1,
        max : 10,
        scroll : false,
        selectFirst : false,
        autoFill : false,
        formatItem: function(json_data) {
                        
            json_str = json_data.toString();
            
            data_item = JSON.parse(json_str);
            
            return data_item[0];
                        
        },
        formatResult: function(json_data) {
            
            json_str = json_data.toString();
            
            data_item = JSON.parse(json_str);
                        
            return data_item[0];
            
        }
    }).result(function(event, json_data) {

            json_str = json_data.toString();
            
            data_item = JSON.parse(json_str);
            
            window.location = data_item[1];
        
    });
        
});