$(document).ready(function(){

    //top shops and news & events
    $('#features').hide();
    $('#slider_menu a.whativid').click(function(){
        $('#whativid').slideToggle();
        $('#features').slideToggle();
        $('#slider_menu').css('backgroundPosition', 'top');
        return false;
    });
    $('#slider_menu a.features').click(function(){
        $('#whativid').slideToggle();
        $('#features').slideToggle();
        $('#slider_menu').css('backgroundPosition', 'bottom');
        return false;
    });
    $.ui.autocomplete.prototype._renderItem = function( ul, item) {
        var re = new RegExp("(" + this.term + ")", "gi") ;
        var t = item.label.replace(re, '<span class="ui-item-bolded">$1</span>');
        return $( "<li "+(item.tag == 1?'class="faded"':'')+"></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>" + t + "</a>" )
        .appendTo( ul );
    };
    $("#searchTxtBox").autocomplete({
        source: "/ajax/shops.php",
        minLength: 1,
        select: function(arg, arg1){
            $("#searchTxtBox").val(arg1.item.value);
            $("#searchTxtBox").parents('form').submit();
        }
    });
    $('form.comment').ajaxForm(sendCommentForm);


    $('form textarea, form input[type=text]').focus(function(){
        if($(this).val() == $(this).attr('data-placeholder')){
            $(this).val('');
        }
    });
    $('form textarea, form input[type=text]').blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).attr('data-placeholder'));
        }
    });
       
    $('textarea.selectable').click(function(){
        this.select();
    });

    $('a.hideImages').click(function(){
        $('.allShops .shopImageShadow').toggle();
        $('.allShops ul li > div').toggleClass('shopSmallBox');
        $(this).find('span').toggleClass('hidden');
    });
    
    if($('div#help').length){
        $('div#help > div').each(function(){
            /*var newID = $(this).attr('id').replace('help', '');
            var elem = document.createElement("img");
            $(elem).attr('src', '/img/global/question_mark.png').addClass('btImage').bt($(this).html(), {
                fill: 'white'
            }); 
            $('#' + newID).after(elem);
            */
        })
    }
    
    $('#moveToTop').click(function(){
        $('html, body').animate({ scrollTop: 0 }, 'normal');
        return false;
    });
    

});

function sendCommentForm(response, status, xhr, form)
{
    errorField = form.siblings('.communicate.error');
    if($('type', response).text() == 'error'){
        errorField.html($('response', response).html());
        errorField.slideDown();
    }
    else{
        var resp = $('response', response);
        resp.hide();
        commentsList = form.parents('.commentBox').find('.commentList');
        commentsList.prepend(resp);
        resp.slideDown();
        form.parents('.commentForm').slideUp();
    }
}

var RecaptchaOptions = {
    theme : 'clean'
};

