$(function() {
//    mh = 0;
//
//    $('div#content').children().each(function() {
//        if($(this).height() > mh) {
//            mh = $(this).height();
//        }
//    });
//
//    mh = mh - 18;
//
//    $('.main-column').height(mh);

    $('#blogContent img').zoom('50%','50%');
    
    $('div#comment').hide();
    $('a#addComment').click(function(){$('#comment').show()});
    $.fn.qtip.styles.forms = { // Last part is the name of the style
        color: 'black',
        textAlign: 'center',
        border:{
            width: 10,
            radius: 10,
            color:'#FFCE2D'
        },
        tip: true,
        background: '#FFFFDE'
    }

    options = {
            style:'forms',
            show: 'focus',
            hide: 'blur',
            position: {
            corner: {
                 target: 'topMiddle',
                 tooltip: 'bottomMiddle'
              }
            }
    };

    $('form input,form textarea,form select').each(function() {
       nO = options;
       hint = $(this).next('p.formHint');
       if(this.name == 'recaptcha_response_field' && $('#captchaHint').length) {
           nO.content = $('#captchaHint').text();
           nO.show = {when: {target:$(this),event:'focus'}};
           nO.hide = {when: {target:$(this),event:'blur'}};
           $('#captchaHint').remove();
           $('#recaptcha_response_field').parents('div.ctrlHolder').qtip(nO);
       }else if(true == hint.length) {
           nO.content = hint.text();
           hint.remove();
           $(this).qtip(nO);
       }else{
           title = $(this).attr('title');

           if(title !== '') {
               nO.content = title;
               $(this).attr('title','');
               $(this).qtip(nO);
           }
       }
    })

    $('.rating').bind('mouseover',(function() {
        el = $(this);
        clo = el.clone().insertBefore($(this));
        $(this).hide();
        $(clo).children('span.full').removeClass('full');
        $(clo).children('span').mouseover(function() {
            $(this).addClass('full').prevAll().addClass("full");
        }).click(function(){
            var id = $(el).attr('id').replace('rating','');
            $.getJSON('/blog/rating',{
                id:id,
                rating:this.id
                },function(data) {
                if(! data.error) {
                    $('strong#votes'+id).text(data.votes);
                    $(el).children('span').removeClass('full');
                    $(el).children('span#'+data.rating).addClass('full').prevAll().addClass('full');
                    $(clo).remove();
                    $(el).unbind('mouseover');
                }   $(el).show();
            })
        })

        $(clo).mouseout(function() {
            el.show();
            $(this).remove();
        })
    }))
});