﻿/* /////////////////////////////////////////////////////////////////////////   */
/* DECIDE WHICH ELEMENTS ARE TO SHOW BASED ON CURRENT LOG IN STATUS            */
/* /////////////////////////////////////////////////////////////////////////   */

function ShowHideAdminPanels() {

    $.ajax({
        type: "POST",
        url: "http://" + window.location.hostname + "/home/UserLoggedIn",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function loggedInReturn(loggedin) {
            if (loggedin.status == 'true') {

                //USER IS LOGGED IN (NOT ADMIN) //USER IS LOGGED IN (NOT ADMIN)
                //USER IS LOGGED IN (NOT ADMIN) //USER IS LOGGED IN (NOT ADMIN)

                $.ajax({
                    type: "POST",
                    url: "http://" + window.location.hostname + "/home/CurrentPageInSession_Ajax",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    cache: false,
                    success: function currPage(result) {

                        var curPage = result.curPage;

                        //$('#ajaxLoggedIn').html('true');
                        //$('#ajaxAdmin').html('false');
                        //$('#ajaxPage').html(curPage);

                        //$('.audioUploadWrap').css('display', 'none');
                        //$('#submitPostWrap').css('display', 'none');
                        //$('#userUploadWrap').css('display', 'none'); //jhGallery
                        //$('#submitSpeakUpPostWrap').css('display', 'none');

                        //if (curPage != 'fanPics') { $('#fanUploadWrap').css('display', 'none'); }
                        //if (curPage == 'speakUp') { $('#submitSpeakUpPostWrap').css('display', 'block'); } else { $('#submitSpeakUpPostWrap').css('display', 'none'); }

                        $('#bannerSignInWrap').css('display', 'none');
                        $('#bannerLoggedInWrap').css('display', 'block');
                        $(".deletePostBtn").css('display', 'none');

                        $.ajax({
                            type: "POST",
                            url: "http://" + window.location.hostname + "/home/RetrieveUserName_Ajax",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            cache: false,
                            success: function currPage(result) {

                                $('.display_LoggedInUserName').html(result.userName);
                                //alert(result.userName);

                                /* only show deleteBtn to admin of post */
                                $('.deleteSpeakUpPostBtn').each(function (index) {
                                    if ($(this).attr('publicAsocPosterName') != result.userName) { $(this).css('display', 'none'); } else { $(this).css('display', 'block'); }
                                });

                            },
                            error: function () {
                                $('.display_LoggedInUserName').html('No User Found');
                            }
                        });
                    }
                });

                $.ajax({
                    type: "POST",
                    url: "http://" + window.location.hostname + "/home/IsUserLoggedInAndAdmin_Ajax",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    cache: false,
                    success: function loggedInReturn(result) {

                        if (result.admin == 'true') {

                            $.ajax({
                                type: "POST",
                                url: "http://" + window.location.hostname + "/home/CurrentPageInSession_Ajax",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                cache: false,
                                success: function currPage(result) {

                                    var curPage = result.curPage;

                                    //USER IS LOGGED IN AND *IS* ADMIN) //USER IS LOGGED AND IS ADMIN)
                                    //USER IS LOGGED IN AND *IS* ADMIN) //USER IS LOGGED AND IS ADMIN)

                                    //$('#ajaxAdmin').html('true');
                                    //$('#ajaxPage').html(curPage);
                                    //$('.audioUploadWrap').css('display', 'block');
                                    $(".deletePostBtn").css('display', 'block');

                                    //if (curPage == 'default') { $('#submitPostWrap').css('display', 'block'); } else { $('#submitPostWrap').css('display', 'none'); }
                                    //if (curPage == 'jhPics') { $('#userUploadWrap').css('display', 'block'); } else { $('#userUploadWrap').css('display', 'none'); } //jhGallery
                                    //if (curPage != 'fanPics') { $('#fanUploadWrap').css('display', 'none'); }
                                    //if (curPage == 'speakUp') { $('#submitSpeakUpPostWrap').css('display', 'block'); } else { $('#submitSpeakUpPostWrap').css('display', 'none'); }
                                    //if (curPage == 'speakUp') { $('.deleteSpeakUpPostBtn').css('display', 'block'); } else { $('.deleteSpeakUpPostBtn').css('display', 'none'); }
                                }
                            });
                        }
                    }
                });

            } else {

                $.ajax({
                    type: "POST",
                    url: "http://" + window.location.hostname + "/home/CurrentPageInSession_Ajax",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    cache: false,
                    success: function currPage(result) {

                        var curPage = result.curPage;
                        //USER NOT LOGGED IN //USER NOT LOGGED IN
                        //USER NOT LOGGED IN //USER NOT LOGGED IN

                        //$('#ajaxLoggedIn').html('false');
                        //$('#ajaxAdmin').html('false');
                        //$('#ajaxPage').html('not checking page because everything is of if not logged in');
                        //$('#submitSpeakUpPostWrap').css('display', 'none');
                        //$(".deletePostBtn").css('display', 'none');
                        // /////////////
                        //$('.audioUploadWrap').css('display', 'none');
                        //$('#submitPostWrap').css('display', 'none');
                        //$('#userUploadWrap').css('display', 'none'); //jhGallery
                        //$('#fanUploadWrap').css('display', 'none');

                        $('#bannerSignInWrap').css('display', 'block');
                        $('#bannerLoggedInWrap').css('display', 'none');

                        $('.deleteSpeakUpPostBtn').css('display', 'none');

                    }
                });

            }
        }
    });

}



/* ////////////////////////////////////////*/
/* STRIP NON-ALPHANUMERIC CHARACTORS       */
/* ////////////////////////////////////////*/

$(document).ready(function () {
    $('.stripHtml').alphanumeric({ ichars: '<>' });
    $('.stripHtmlTags').alphanumeric({ ichars: '<>' });
});

/* //////////////////////////////////////// */
/* HIDE / SHOW ERROR MESSAGE                */
/* //////////////////////////////////////// */

function displayError(errorMsg) {

    if (errorMsg == 'ajaxError') {
        //display generic error message
        $('.loginPopUpWrapper').css('background-image', "url('http://www.johnnyhollow.com/imagesProduction/generalSprite.jpg')"); //errorBG.jpg
        $('.loginPopUpWrapper').css('background-position', '0 -856px'); /* there was an error loggininh in ... */

    } else {
        $('.client_id').text(errorMsg);
        $('.initialLoginOptions').fadeIn('fast');
        $('.loginPopUpWrapper').css('background-image', "url('http://www.johnnyhollow.com/imagesProduction/generalSprite.jpg')"); //loginBG.jpg
        $('.loginPopUpWrapper').css('background-position', '0 -220px'); /* you have 2 options graphic */
    }

    //$('#opacityBackground').fadeIn('slow');
    $('#opacityBackground').fadeTo('slow', 0.8);

    $('.mp_error_wrap').fadeIn('slow');

    $('.mp_error_wrap').css('height', '239px');
    $('.loginPopUpWrapper').css('height', '209px');
    $('.mp_error_wrap').CenterIt();
}

function hideError() {
    $('#opacityBackground').fadeOut('slow');
    $('.mp_error_wrap').fadeOut('slow');
    $('.errorMsg').text("");
    $('.loginQuestionWrap').fadeOut('slow');
    $('.accountLogin').hide();
    $('.accountCreate').hide();
}
$('#hideErrorBtn').click(hideError());







/* ///////////////////////////////////////////////////////////////////////// */
/* RESIZE THE RAILS     /////////////////     RESIZE THE RAILS              */
/* RESIZE THE RAILS     /////////////////     RESIZE THE RAILS              */
/* RESIZE THE RAILS     /////////////////     RESIZE THE RAILS              */
/* ///////////////////////////////////////////////////////////////////////// */

function IE7_FIXES() {


    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 8) {
            //leave document as is for IE 8 and above
        }
        else {
            $('#IEcompatiblityMessage').css('display', 'block'); //display IE 6 & 7 incompatibility warning

            $('body').css('background', 'url(\'\')'); //remove incompatible background
            $('#footer').css('display', 'none');
        }
    }
}

/* adjust height of side rails*/
/* make sure footer is on bottom*/
function ResizeRails() {

    /*alert( 'window  ' + $(window).height() + '   document   ' + $(document).height() );*/

    /*var pageHeight = $(window).height() - 302;*/
    /*
    $('.mainRailDividerLeft').height($(document).height() - $('.mainRailDividerLeft').offset().top);
    $('.mainRailDividerRight').height($(document).height() - $('.mainRailDividerRight').offset().top);
    /*$('#footer').css('margin-top', $(document).height() - 26 + 'px');*/
    /*
    $('#outerLeftBottom').height($(document).height() - $('#outerLeftBottom').offset().top);
    */

    var railHeight = 0;

    if ($('#columLeft').height() > railHeight) {
        railHeight = $('#columLeft').height() + 15;
    }
    if ($('#columCentre').height() > railHeight) {
        railHeight = $('#columCentre').height() + 15;
    }
    if ($('#columRight').height() > railHeight) {
        railHeight = $('#columRight').height() + 15;
    }

    $('.mainRailDividerLeft').height(railHeight);
    $('.mainRailDividerRight').height(railHeight);

    $('#outerLeftBottom').height(railHeight - 543);

    $('#footer').css('margin-top', (railHeight + 362) + 'px');
}

$(document).ready(function () {
    // on page load decide which admin panels are displayed;
    ShowHideAdminPanels();

    //hide background image for IE6/7
    IE7_FIXES();
});

$(window).load(function () {
    ResizeRails();
});

/* resize rail functionality */


function HideTypeKitBadge(){
    $('#typekit-badge-dwe1eqx').css('display', 'none');
}


$(document).ready(function () {

    HideTypeKitBadge();

    $(window).scroll(function () {

        HideTypeKitBadge();

        //display footer
        $('#footer').css('display', 'block');

        var railHeight = 0;

        if ($('#columLeft').height() > railHeight) {
            railHeight = $('#columLeft').height() + 15;
        }
        if ($('#columCentre').height() > railHeight) {
            railHeight = $('#columCentre').height() + 15;
        }
        if ($('#columRight').height() > railHeight) {
            railHeight = $('#columRight').height() + 15;
        }

        $('.mainRailDividerLeft').height(railHeight);
        $('.mainRailDividerRight').height(railHeight);

        $('#outerLeftBottom').height(railHeight - 543);

        $('#footer').css('margin-top', (railHeight + 362) + 'px');
    });

    $(window).resize(function () {

        HideTypeKitBadge();

        //display footer
        $('#footer').css('display', 'block');

        var railHeight = 0;

        if ($('#columLeft').height() > railHeight) {
            railHeight = $('#columLeft').height() + 15;
        }
        if ($('#columCentre').height() > railHeight) {
            railHeight = $('#columCentre').height() + 15;
        }
        if ($('#columRight').height() > railHeight) {
            railHeight = $('#columRight').height() + 15;
        }

        $('.mainRailDividerLeft').height(railHeight);
        $('.mainRailDividerRight').height(railHeight);

        $('#outerLeftBottom').height(railHeight - 543);

        $('#footer').css('margin-top', (railHeight + 362) + 'px');
    });
});


/* /////////////////////////////////////////////////////////////////////////  */
/* CENTER PAGE                                                                */
/* /////////////////////////////////////////////////////////////////////////  */

$(document).ready(function () {

    var width = $(document).width();
    $('#outerWrap').css('position', 'absolute');
    $('#outerWrap').css("left", ($(window).width() - $('#outerWrap').width()) / 2 + $(window).scrollLeft() + "px");

    $(window).resize(function (e) {
        $('#outerWrap').css('position', 'absolute');
        $('#outerWrap').css("left", ($(window).width() - $('#outerWrap').width()) / 2 + $(window).scrollLeft() + "px");
    });
});


/* /////////////////////////////////////////////////////////////////////////  */
/* SEE MORE COMMENTS                                                          */
/* /////////////////////////////////////////////////////////////////////////  */

function SeeMoreComments() { // this click begins the chain of events

    $('.commentOverflowWrapper').slideDown(2000);
    $('.seeMoreComments').hide();
    $('.hideMoreComments').show();
}

function HideMoreComments() { // this click begins the chain of events

    $('.commentOverflowWrapper').slideUp(2000);
    $('.seeMoreComments').show();
    $('.hideMoreComments').hide();
}


/* THIS IS THE FUNCTION TO HAVE TEXT IN THE INPUT DISAPEAR ONFOCUS

   1. var defaultText = 'Search this website!';
   2.  
   3. $(document).ready(function(){
   4.   $('#searchBox').attr("value", defaultText).css('color', '#bbbbbb')
   5. .focus(function(){
   6.     if (defaultText == $(this).attr("value")) {
   7.       $(this).attr("value", "").css('color', '#333333');
   8.     }
   9.   }).blur(function(){
  10.     if ($(this).attr("value") == '') {
  11.       $(this).attr("value", defaultText).css('color', '#bbbbbb');
  12.     }
  13.   });
  14. });


*/
