jQuery.noConflict();

jQuery(document).ready(function($) {
    changeTemplate();
    

    $('.placeholder').bind('focus', function() {
        var id = $(this).attr('id'), text = $('#placeholder-'+id).html();
        if ($(this).val() == text) {
            $(this).val('');
        }
    });

    $('.placeholder').bind('blur', function() {
        var id = $(this).attr('id'), text = $('#placeholder-'+id).html();
        if ($(this).val() == '') {
            $(this).val(text);
        }
    });
});


function commentPaginationDelegate() {
    (function($) {
        $('.commentPagination').delegate('a', 'click', function(e) {
            e.preventDefault();
            getComment(($(this).text()-1)*1);
        });
    })(jQuery);
}


function changeTemplate() {
    (function($) {
        $('.template').bind('click', function() {
            var classes = $(this).attr('class') + " ";
            var startPos = classes.indexOf("template_")+9;
            var endPos = classes.indexOf(" ", startPos);
            var template = classes.substring(startPos, endPos);
            document.cookie = 'template='+template+'; expires='+Date.UTC(2020,1,1);+'; path=';
            location.reload(true);
        });
    })(jQuery);
}

function postComment() {
    (function ($) {
        $.ajax({
            type: "POST",
            url: "/comment/post/ajax",
            data: "comment="+$('#comment').val()+"&media_ID="+$('#media_ID').val(),
            success: function (msg) {
                $('#commentsList').html(msg);
            }
         });
    })(jQuery);

    return false;
}


function getComment(from) {
    (function ($) {
        $.ajax({
            type: "POST",
            url: "/comment/commentsViaAjax/"+from,
            data: "media_ID="+$('#media_ID').val(),
            success: function (msg) {
                $('#commentsList').html(msg);
            }
         });
    })(jQuery);
}



function postProfileComment() {
    (function ($) {
        $.ajax({
            type: "POST",
            url: "/profilecomment/post/ajax",
            data: "comment="+$('#profilecomment').val()+"&user_ID="+$('#user_ID').val(),
            success: function (msg) {
                $('#profileCommentsList').html(msg);
            }
         });
    })(jQuery);

    return false;
}
