﻿

/* //////////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////////////////////////////   SHOW IMAGE UPLOAD PANEL //////////////// */
/* //////////////////////////////////////////////////////////////////////////////////////////////// */

function PromptLogin() {
    displayError(""); //This pops up the login window
}

function ShowFanUploadPanel() {
    $('#fanUploadWrap').show('slow');
}
function close_FanUploadPanel() {
    $('#fanUploadWrap').hide('slow');
}

function FanGalleryREBIND() {
    $('a[rel*=facebox]').facebox();

    /* STRIP NON-ALPHANUMERIC CHARACTORS */
    $('#facebox .content .stripHtml').alphanumeric({ ichars: '<>' });
    $('#facebox .content .stripHtmlTags').alphanumeric({ ichars: '<>' });

    /* THIS WILL VERTICALLY CENTER ALL THE THUMBNAILS */
    $('.imageContainer').each(function (index) {
        var imgContainHeight = $(this).height();
        var imgInnerHeight = $(this).children('.highslide').children('img').height();

        var imageOffset = (imgInnerHeight - imgContainHeight) / 2;
        var imageOffsetString = '-' + imageOffset + 'px';
        $(this).children('.highslide').children('img').css('margin-top', imageOffsetString);
    }); 
}

function SubmitUserGalleryComment(a, asocUserImageID, c, textAreaGalleryCommentID, commentRePopTargetID) {

    var textAreaID = '#facebox #' + textAreaGalleryCommentID;

    //var userCommentTemp = $(textAreaID).val();
    var userCommentTemp = $("#facebox textarea[name='commentTextArea']").val();
    var userComment = "";

    for (var i = 0; i < userCommentTemp.length; i++) {
        if (userCommentTemp.charAt(i) == "'") {
            userComment = userComment + "ˈ";
        } else {
            userComment = userComment + userCommentTemp.charAt(i);
        }
    }

    $.ajax({
        url: 'http://' + window.location.hostname + '/FanGallery/FanGalleryComentsAJAX_SQL',
        type: 'POST',
        data: 'imageComment=' + userComment + '&postersName=' + 'fakeName' + '&asocUserImageID=' + asocUserImageID,
        dataType: 'json',
        cache: false,
        success: function loggedInReturn(result) {
            if (result.success == true) {

                var commentWrap = "#facebox #" + commentRePopTargetID;
                $(commentWrap).html(result.rePopedComments);

                //$(textAreaID).val(''); /* clear comment box */
                $("#facebox textarea[name='commentTextArea']").val('');

            } else {
                displayError(''); //Before you post, we need to know who you are?
            }
        },
        error: function () {
            alert('Sorry there was an AJAX error.')
        }
    });
}

/* ///////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////////// DELETE PHOTO //////////////////////////////////////////// */
/* ///////////////////////////////////////////////////////////////////////////////////////////// */

//string userImageID, string userImageName, string postersName

function DeleteFanPic(userImageID, userImageName, postersName) {
    //alert("userImageID : " + userImageID + " userImageName : " + userImageName + " postersName : " + postersName);

    $.ajax({
        url: 'http://' + window.location.hostname + '/FanGallery/DeleteUserImageAjax',
        type: 'POST',
        data: 'userImageID=' + userImageID + '&userImageName=' + 'userImageName' + '&postersName=' + postersName,
        dataType: 'json',
        cache: false,
        success: function (result) {
            if (result.success == true) {

                //redirect after upload
                jQuery.facebox.close();
                window.navigateToFanGallery();
                

            } else {
                alert(result.message);
            }
        },
        error: function () {
            alert(result.message);
        }
    });

}

function RecentFanGalleryPosts() {

    $.ajax({
        type: "POST",
        url: "http://" + window.location.hostname + "/FanGallery/RecentFanGalleryPosts",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function () {

            //SUCCESS updating seesion ..
            //RELOAD THE BLOG PAGE ..

            $("#ajaxContainer").load("http://" + window.location.hostname + "/FanGallery .ajaxContent", function (response, status, xhr) {
                if (status == "error") {
                    alert("Sorry but there was an error: ");
                } else {
                    FanGalleryREBIND();
                }
            });
        }
    });
}

function OlderFanGalleryPosts() {

    $.ajax({
        type: "POST",
        url: "http://" + window.location.hostname + "/FanGallery/OlderFanGalleryPosts",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function () {

            //SUCCESS updating seesion ..
            //RELOAD THE BLOG PAGE ..

            $("#ajaxContainer").load("http://" + window.location.hostname + "/FanGallery .ajaxContent", function (response, status, xhr) {
                if (status == "error") {
                    alert("Sorry but there was an error: ");
                } else {
                    FanGalleryREBIND();
                }
            });
        }
    });
}

/* //////////////////////////////////////////////////////////////////   GALLERY VIRAL ////////////////////////////////////////////////////////////// */

function ShareFanImageOnFacebook(postTitle, picture) {

    FB.ui({

        method: 'stream.publish',
        message: 'just seen this pic on johnnyhollow.com ...',
        attachment: {
            name: postTitle,
            description: (postTitle),
            media: [{ type: 'image',
                src: 'http://www.johnnyhollow.com/userImages/' + picture,
                href: 'http://www.johnnyhollow.com/'
            }],
            href: 'http://www.johnnyhollow.com/'
        }
    },

    function (response) {
        if (response && response.post_id) {
            //success action

        } else {
            //failure action
        }

    });
}


