/**
 * $Id: jquery_site.js 19 2009-10-27 10:13:26Z Ian.H $
 *
 * jQuery core code
 */
var alertTimeout;

Array.prototype.has = function(val) {
    var i;

    for (i = 0; i < this.length; i++) {
        if (this[i] === val) {
            return true;
        }
    }

    return false;
}

$(function() {
    // Hide new alert box by default
    $('#new-alert-box').hide();
    $('div#cat-path-viewer').hide();

    // Google search box
    if ($('#google-search-query') != null) {
        $('#google-search-query').focus(function() {
            $(this).removeClass('google-search-field');
        });

        $('#google-search-query').keyup(function() {
            if ($(this).val() != '') {
                $(this).removeClass('google-search-field');
            } else {
    //            $(this).addClass('google-search-field');
            }
        });

        $('#google-search-query').blur(function() {
            if ($(this).val() == '') {
                $(this).addClass('google-search-field');
            }
        });

        if ($('#google-search-query').val() != '') {
            $('#google-search-query').removeClass('google-search-field');
        } else {
            $('#google-search-query').addClass('google-search-field');
        }
    }

    // Keywords quick search box
    if ($('keyword-search-field') != null) {
        $('#keyword-search-field').focus(function() {
            $(this).removeClass('quick-search-field');
        });

        $('#keyword-search-field').keyup(function() {
            if ($(this).val() != '') {
                $(this).removeClass('quick-search-field');
            } else {
    //            $(this).addClass('quick-search-field');
            }
        });

        $('#keyword-search-field').blur(function() {
            if ($(this).val() == '') {
                $(this).addClass('quick-search-field');
            }
        });

        if ($('#keyword-search-field').val() != '') {
            $('#keyword-search-field').removeClass('quick-search-field');
        } else {
            $('#keyword-search-field').addClass('quick-search-field');
        }
    }

    // Search tab selector
    if ($('ul#search-tabs') != null) {
        $('ul#search-tabs > li > a').click(function() {
            var selectedTabId = '#' + $(this).attr('id');

            // Remove "selected" style from all tabs
            $('ul#search-tabs > li > a').each(function() {
                $(this).removeClass('selected-tab');
            });

            // Add "selected" style to selected tab
            var actSpeed = '';
            $(selectedTabId).addClass('selected-tab');

            if (selectedTabId == '#search-tab-location') {
                $('div#tab3').hide(actSpeed);
                $('div#tab2').fadeIn('slow');
            }
            if (selectedTabId == '#search-tab-postcode') {
                $('div#tab2').hide(actSpeed);
                $('div#tab3').fadeIn('slow');
            }

            return false;
        });

        // Auto select 'location' search tab as default
        $('ul#search-tabs > li > a#search-tab-location').addClass('selected-tab');
    }

    // Member logout
    if ($('a#member-menu-logout') != null) {
        $('a#member-menu-logout').click(function() {
            return confirm('Are you sure you want to logout?');
        });
    }

    // Member home button
    if ($('button.goto-member-home') != null) {
        $('button.goto-member-home').click(function() {
            window.location.href='/members/';
            return false;
        });
    }

    // Preview member listing
    if ($('a.member-preview-listing') != null) {
        $('a.member-preview-listing').click(function() {
            var listingId = $(this).attr('id').substr(23);
            window.open('/members/listing/preview.php?id=' + listingId);
            return false;
        });
    }

    // Member listing home button
    if ($('button.goto-member-listing-home') != null) {
        $('button.goto-member-listing-home').click(function() {
            window.location.href='/members/listing/';
            return false;
        });
    }

    // Listing title auto-friendly URL
    $('input#listing-title').blur(function() {
        var listingTitle = $('input#listing-title').val();
        var relBits = $(this).attr('rel').split('|');

        $('input#' + relBits[0]).val(makeFriendlyUrl(listingTitle, relBits[1], relBits[2]));
        return false;
    });

    // New city auto-friendly URL
    $('input#newcity').blur(function() {
        var newCity = $(this).val();
        var relBits = $(this).attr('rel').split('|');

        $('input#' + relBits[0]).val(makeFriendlyUrl(newCity, relBits[1], relBits[2]));
        return false;
    });

    // Dynamically list cities within counties
    $('select#state-id').change(function() {
        var html = '';
        var target = $('select#state-id').attr('rel');
        var id = $('select#state-id option:selected').val();

        if ($('select#state-id option:selected').text() == 'Select a County...') {
            $('select#region-id').html('<option value="">Select a City...</option>');
            return false;
        }

        $('select#region-id').attr('disabled', 'disabled');
        $('select#region-id').html('<option value="">Loading. Please wait...</option>');

        $.get('/location.php?state_id=' + id, function(xmlObj) {
            $('city', xmlObj).each(function(i) {
                html = html + '<option value="' + $(this).find('id').text() + '">' + $(this).find('name').text() + '</option>';
            });

            $('select#region-id').html(html);
            $('select#region-id').attr('disabled', '');
        });
    });

    $('input#newcity').hide();
    $('span#manually-add-city').click(function() {
        $('input#newcity').show();
    });
    $('select#region-id').focus(function() {
        $('input#newcity').hide();
    });

    $('textarea#summary-desc').keydown(function(e) {
        var maxLen = $(this).attr('rel');
        var text = $(this).val();
        var textLen = text.length;
        var key = e.charCode || e.keyCode || 0;

        if (textLen >= maxLen) {
            if ((key == 8) || (key == 46) || ((key >= 37) && (key <= 40))) {
                return true;
            } else {
                return false;
            }
        }
    });
    $('textarea#summary-desc').keyup(function(e) {
        var maxLen = $(this).attr('rel');
        limitChars($(this), maxLen, '#summary-desc-chars-remaining');
    });

    // Determine chars used in textarea
    $('textarea').keydown(function(e) {
        var data = $(this).attr('rel').split('|');
        var element = data[0];
        var maxLen = data[1];
        var text = $(this).val();
        var textLen = text.length;
        var key = e.charCode || e.keyCode || 0;
        var exemptKeys = new Array(8, 16, 17, 18, 19, 20, 33, 34, 35, 36, 37, 38, 39, 40, 46, 144);

        if (textLen >= maxLen) {
            if (exemptKeys.has(key)) {
                return true;
            } else {
                return false;
            }
        }
    });
    $('textarea').keyup(function(e) {
        var data = $(this).attr('rel').split('|');
        var element = data[0];
        var maxLen = data[1];

        limitChars($(this), maxLen, '#' + element + '-chars-remaining');
    });

    if ($('textarea#conditions').length > 0) {
        // Calculate conditions pre-populated field char limit
        var textLen = $('textarea#conditions').val().length;
        var data = $('textarea#conditions').attr('rel').split('|');
        var element = data[0];
        var maxLen = data[1];

        limitChars($('textarea#conditions'), maxLen, '#' + element + '-chars-remaining');
    }

    // Increase / Decrease textareas
    $('span#summary-desc-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span#summary-desc-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });

    $('span#long-desc-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span#long-desc-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });
    $('span#keywords-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span#keywords-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });
    $('span#work-hours-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span#work-hours-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });
    $('span#locations-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span#locations-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });

    // Textarea increase / decrease
    $('span.textarea-increase').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('increase', data);
    });
    $('span.textarea-decrease').click(function() {
        var data = $(this).attr('rel');
        resizeTextarea('decrease', data);
    });

    // Inline help
    $('img.inline-help').click(function() {
        var str = $(this).attr('title');
        var rel = $(this).attr('rel');

        if (rel != 'showing') {
            $(this).parent().append('<div class="inline-help-container">' + str + '</div>');
            $(this).attr('rel', 'showing');
        } else {
            $('div.inline-help-container').fadeOut(500, function() { $(this).remove(); });
            $(this).attr('rel', '');
        }
    });

    $('div.inline-help-container').live('click', function() {
        $(this).fadeOut(500, function() { $(this).remove(); });
        $('img.inline-help').attr('rel', '');
    });

    // Member attachments
    $('div#member-attachment-container').hide();
    //$('div#member-attachment-summary-desc-container').hide();
    //$('div#member-attachment-long-desc-container').hide();

/*    $('div#member-attachment-info').click(function() {
    //$('img#member-attachment-ctrl').click(function() {
        var rel = $(this).attr('rel');
        var id = $(this).attr('id');

        if (rel == 'hidden') {
            $('div#member-attachment-container').fadeIn(500);
            //$('div#member-attachment-summary-desc-container').fadeIn(500);
            //$('div#member-attachment-long-desc-container').fadeIn(500);
            $('div#' + id + ' > img').attr({
                src     : '/images/icons/icon_collapse.png',
                title   : 'Collapse this section',
                alt     : '[-]'
            });
            $(this).attr({
                rel     : '',
                title   : 'Collapse this section'
            });
        } else {
            $('div#member-attachment-container').fadeOut(500);
            //$('div#member-attachment-summary-desc-container').fadeOut(500);
            //$('div#member-attachment-long-desc-container').fadeOut(500);
            $('div#' + id + ' > img').attr({
                src     : '/images/icons/icon_expand.png',
                title   : 'Expand this section',
                alt     : '[+]'
            });
            $(this).attr({
                rel     : 'hidden',
                title   : 'Expand this section'
            });
        }
    });*/

//    $('div#signup-member-attachment-info').click(function() {
    //$('img#member-attachment-ctrl').click(function() {
//        var rel = $(this).attr('rel');
//        var id = $(this).attr('id');

//        if (rel == 'hidden') {
//            $('div#signup-member-attachment-container').fadeIn(500);
            //$('div#member-attachment-summary-desc-container').fadeIn(500);
            //$('div#member-attachment-long-desc-container').fadeIn(500);
//            $('div#' + id + ' > img').attr({
//                src     : '/images/icons/icon_collapse.png',
//                title   : 'Collapse this section',
//                alt     : '[-]'
//            });
//            $(this).attr({
//                rel     : '',
//                title   : 'Collapse this section'
//            });
//        } else {
//            $('div#signup-member-attachment-container').fadeOut(500);
            //$('div#member-attachment-summary-desc-container').fadeOut(500);
            //$('div#member-attachment-long-desc-container').fadeOut(500);
//            $('div#' + id + ' > img').attr({
//                src     : '/images/icons/icon_expand.png',
//                title   : 'Expand this section',
//                alt     : '[+]'
//            });
//            $(this).attr({
//                rel     : 'hidden',
//                title   : 'Expand this section'
//            });
//        }
//    });

    // Close "window" icon
    $('img.win-close-icon').live('click', function() {
        var divId = $(this).parent().parent().attr('id');
        $('div#' + divId).fadeOut(500);
    });

    // Hide error msg
    $('div#new-alert-box').click(function() {
        $(this).fadeOut(300);
    });

    // Listing add form
    $('form#form-submit-buttons').click(function() {
        if (($('input#listing-title').val() == '') || ($('input#friendly-url').val() == '')) {
            var missingFields = new Array();
            var msg = 'Please complete all required fields.';

            if ($('input#listing-title').val() == '') {
                missingFields[0] = 'Listing Title';
            }
            if ($('input#friendly-url').val() == '') {
                missingFields[1] = 'Page Title';
            }

            if (missingFields.length > 0) {
                msg = msg + '<ul>';
            }

            for (i = 0; i < missingFields.length; i++) {
                msg = msg + '<li>' + missingFields[i] + '</li>';
            }

            if (missingFields.length > 0) {
                msg = msg + '</ul>';
            }

            displayNewAlert(msg);

            return false;
        } else {
            //JS_submit();
            //$('form#frm-listing').submit();
            JS_submit();
        }
    });

    $('button#btn-listing').click(function() {
        JS_submit();
    });

    // Register form
    $('input.btn-register').click(function() {
        var reqFields = new Array(
            'usrname',
            'passwd',
            'confirm-passwd',
            'first-name',
            'last-name',
            'company',
            'phone',
            'email'
        );

        var errorMsg = '';

        for (var i = 0; i < reqFields.length; i++) {
            if ($('input#' + reqFields[i]).val() == '') {
                if (errorMsg == '') {
                    errorMsg = 'Please complete all required fields.';
                }
            }
        }

        // Check for agree to terms checkbox
        if ($('input#agree-tou').attr('checked') == false) {
            errorMsg = 'Please complete all required fields.';
        }

        if (errorMsg != '') {
            displayNewAlert(errorMsg);
            return false;
        }
    });

    // Focus reg form username
    if ($('input.reg-username').length > 0) {
        $('input.reg-username').focus();
    }

    // Ticketmaster Events (pagination change)
    $('a.tm-pagination-link').live('click', function(e) {
        var pageNum = $(this).attr('rel').replace(/page-/, '');
        var tab = $(this).attr('class').replace(/tm-pagination-link tm-tab-/, '');

        var sy;

        if (typeof(window.pageYOffset) == 'number') {
            sy = window.pageYOffset;
        } else if (document.body.scrollTop) {
            sy = document.body.scrollTop;
        } else if (document.documentElement.scrollTop) {
            sy = document.documentElement.scrollTop;
        }

        if (sy > 408) {
            window.scroll(0, 408);
        }

        if (tab == 'music') {
            $('.tm-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-music.ajax.php?pg=' + pageNum + '&type=page',
                function(data) {
                    $('.tm-results').html(data);
                    $('div.tm-pagenum').html('Current Page: ' + pageNum);
                }
            );
        } else if (tab == 'arts-theatre') {
            $('.tm-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-arts-theatre.ajax.php?pg=' + pageNum + '&type=page',
                function(data) {
                    $('.tm-results').html(data);
                    $('div.tm-pagenum').html('Current Page: ' + pageNum);
                }
            );
        } else if (tab == 'family') {
            $('.tm-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-family.ajax.php?pg=' + pageNum + '&type=page',
                function(data) {
                    $('.tm-results').html(data);
                    $('div.tm-pagenum').html('Current Page: ' + pageNum);
                }
            );
        }

        e.preventDefault();
    });

    // Ticketmaster tab (tab change)
    $('a.tm-tab').live('click', function(e) {
        var tab = $(this).attr('rel');
        tab = tab.replace(/tm-/, '');

        if (tab == 'music') {
            tmTabsAllInactive();

            $('#signupMenuListing').removeClass('advertiseMenuInactive').addClass('advertiseMenuActiveListing');
            $('.tm-event-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-music.ajax.php?pg=1&type=tab',
                function(data) {
                    $('.tm-event-results').html(data);
                    $('div.tm-pagenum').html('Current Page: 1');
                }
            );
        } else if (tab == 'arts-theatre') {
            tmTabsAllInactive();

            $('#signupMenuEvent').removeClass('advertiseMenuInactive').addClass('advertiseMenuActiveListing');
            $('.tm-event-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-arts-theatre.ajax.php?pg=1&type=tab',
                function(data) {
                    $('.tm-event-results').html(data);
                    $('div.tm-pagenum').html('Current Page: 1');
                }
            );
        } else if (tab == 'family') {
            tmTabsAllInactive();

            $('#signupMenuBanner').removeClass('advertiseMenuInactive').addClass('advertiseMenuActiveListing');
            $('.tm-event-results').html('<div class="tm-events-loading">Loading. Please wait...</div>');

            $.get(
                './get-events-family.ajax.php?pg=1&type=tab',
                function(data) {
                    $('.tm-event-results').html(data);
                    $('div.tm-pagenum').html('Current Page: 1');
                }
            );
        }

        e.preventDefault();
    });

    // Signup listing level selector
    $('#listing-level').change(function() {
        var level = $(this).val();

        if ((level == '') || (level == 10)) {
            level = 0;
        }

        showListingLevelFields(true, level);
    });

    // Registration billing address same as listing address
    $('input#address-duplication').click(function() {
        var checked = $(this).attr('checked');

        if (checked) {
            $('#billing-address').val($('#address').val());
            $('#billing-address2').val($('#address2').val());

            if ($('#state-id option:selected').val() != '') {
                $('#county').val($('#state-id option:selected').text());
            }

            if ($('#newcity').val() != '') {
                $('#city').val($('#newcity').val());
            } else {
                if ($('#region-id option:selected').val() != '') {
                    $('#city').val($('#region-id option:selected').text());
                }
            }

            $('#postcode').val($('#zip').val());

            // Get country from code
            $.get(
                './getcountry.php?c_id=' + $('#country-id').val(),
                function(data) {
                    $('#country').val(data);
                }
            );

            //$('#country').val($('#country-id').val());
            $('#billing-phone').val($('#phone').val());

            if ($('#listing-level').val() >= 30) {
                $('#billing-email').val($('#email').val());
            } else {
                $('#billing-email').val('');
            }
        } else {
            $('#billing-address').val('');
            $('#billing-address2').val('');
            $('#county').val('');
            $('#city').val('');
            $('#postcode').val('');
            $('#country').val('');
            $('#billing-phone').val('');
            $('#billing-email').val('');
        }
    });

    // Validate registration form
    $('.btn-new-register').click(function(e) {
        var reqFields = new Array(
            'usrname',
            'passwd',
            'confirm-passwd',
            'email',
            'phone',
            'first-name',
            'last-name',
            'company',
            'billing-phone',
            'billing-email'
        );

        // Check for required fields
        var formError = false;
        var errorMsg = '';
        var errorField = '';
        var firstErrorField = '';
        var usrnameExists = false;

        // Check if username already exists
        if ($('#usrname').val() != '') {
            var usrname = $('#usrname').val();

            $.ajax({
                url:        '/check-username.php?u=' + usrname,
                success:    function(data) {
                                if (data == '1') {
                                    usrnameExists = true;
                                }
                            },
                async:      false
            });

            if (usrnameExists) {
                for (var i = 0; i < reqFields.length; i++) {
                    var field = reqFields[i];

                    $('#' + field).removeClass('error-field');
                }

                $('#usrname').val('');
                $('#usrname').focus();

                displayNewAlert('Username already exists. Please choose another username.');

                e.preventDefault();
                return false;
            }
        }

        for (var i = 0; i < reqFields.length; i++) {
            var field = reqFields[i];

            $('#' + field).removeClass('error-field');

            if ($('#' + field).val() == '') {
                errorMsg = 'Please complete all required fields.';
                formError = true;
                errorField = field;
                $('#' + field).addClass('error-field');

                if (firstErrorField == '') {
                    firstErrorField = field;
                }
            }
        }

        if (formError) {
            $('#' + firstErrorField).focus();
//            $('#' + errorField).focus();
//            $('#' + errorField).addClass('error-field');
            displayNewAlert(errorMsg);
            $('#' + firstErrorField).focus();
            e.preventDefault();
            return false;
        }

        // Check for no listing
//        if ($('#listing-level').val() < 30) {
//            return !confirm("You haven't entered any data for a listing.\nDo you wish to enter this data at this time?");
//        }
    });
});

function makeFriendlyUrl(value, validChars, separator) {
    var i;
    var regexp = new RegExp('[' + validChars + separator + ']');
    var friendlyUrl = '';

    for (i = 0; i < value.length; i++) {
        if (regexp.test(value.charAt(i))) {
            friendlyUrl = friendlyUrl + value.charAt(i);
        } else {
            if (value.charAt(i) == ' ') {
                if (friendlyUrl.charAt(friendlyUrl.length - 1) != separator) {
                    friendlyUrl = friendlyUrl + separator;
                }
            }
        }
    }

    // Trim separator from end of string if last char
    if (friendlyUrl.charAt(friendlyUrl.length - 1) == separator) {
        friendlyUrl = friendlyUrl.substr(0, friendlyUrl.length - 1);
    }

    // Return new value
    return friendlyUrl.toLowerCase();
}

function limitChars(element, maxLen, counterElement) {
    $(function() {
        var text = $(element).val();
        var textLen = text.length;

        if (textLen > maxLen) {
            $(element).val(text.substr(0, maxLen));
            return false;
        } else {
            $(counterElement).html(maxLen - textLen);
        }
    });
}

function resizeTextarea(type, data) {
    $(function() {
        var dataBits = data.split('|');
        var maxWidth;
        var minWidth;
        var target;
        var taWidth;
        var taHeight;

        target = dataBits[0];
        target = 'textarea#' + target;
        maxWidth = dataBits[1];
        minWidth = dataBits[2];

        taWidth = $(target).width();
        taHeight = $(target).height();

        switch (type) {
            case 'increase':
                if ((taWidth + 40) <= (maxWidth - 40)) {
                    taWidth += 40;
                    taHeight += 20;
                    $(target).width(taWidth + 'px');
                    $(target).height(taHeight + 'px');
                }

                break;
            case 'decrease':
                if ((taWidth - 40) >= minWidth) {
                    taWidth -= 40;
                    taHeight -= 20;
                    $(target).width(taWidth + 'px');
                    $(target).height(taHeight + 'px');
                }

                break;
        }
    });
}

function displayNewAlert(msg) {
    $(function() {
        // Calculate display position
        // Width == 440px;
        var left = ($('html').width() / 2) - ($('div#new-alert-box').width() / 2);
        var h = $('div#new-alert-box').height();
        var wh = window.innerHeight;
        var st = document.documentElement.scrollTop;
        //var top = ((wh / 2) - (h / 2)) + st - (h / 4);

        // Position alert box
        $('div#new-alert-box').css({
            'position':'absolute',
            'z-index':'999',
            'top':st + 'px',
            'left':left + 'px'
        });
        $('#new-alert-box').addClass('alert-box-error');

        // Add message
        $('#new-alert-box').html(msg);

        // Display message
        $('#new-alert-box').fadeIn();

        // Hide error message after n seconds
        alertTimeout = setTimeout(function() {
            $('#new-alert-box').fadeOut(1000);
            $('#new-alert-box').removeClass('alert-box-error');
        }, 5000);
    });
}

function hideNewAlert() {
    $(function() {
        $('#new-alert-box').fadeOut();
        $('#new-alert-box').removeClass('alert-box-error');
    });
}

function resetAlertTimeout() {
    clearTimeout(alertTimeout);
}

function tmTabsAllInactive() {
    $(function() {
        $('#signupMenuListing').removeClass('advertiseMenuActiveListing').addClass('advertiseMenuInactive');
        $('#signupMenuEvent').removeClass('advertiseMenuActiveListing').addClass('advertiseMenuInactive');
        $('#signupMenuBanner').removeClass('advertiseMenuActiveListing').addClass('advertiseMenuInactive');
    });
}

function showListingLevelFields(show, level) {
    var delay = 500;

    if (show) {
        switch (level) {
            case '10':
                // Show elements
                $('.level-10').fadeIn(delay);

                // Hide elements
                $('.level-70').fadeOut(delay);
                $('.level-50').fadeOut(delay);
                $('.level-30').fadeOut(delay);

                break;

            case '30':
                // Show elements
                $('.level-10').fadeIn(delay);
                $('.level-30').fadeIn(delay);

                // Hide elements
                $('.level-70').fadeOut(delay);
                $('.level-50').fadeOut(delay);

                break;

            case '50':
                // Show elements
                $('.level-10').fadeIn(delay);
                $('.level-30').fadeIn(delay);
                $('.level-50').fadeIn(delay);

                // Hide elements
                $('.level-70').fadeOut(delay);

                // Update free categories
                $('#free-categories').html('4');

                break;

            case '70':
                // Show elements
                $('.level-10').fadeIn(delay);
                $('.level-30').fadeIn(delay);
                $('.level-50').fadeIn(delay);
                $('.level-70').fadeIn(delay);

                // Update free categories
                $('#free-categories').html('5');
                break;

            case '0':
            default:
                $('.level-70').fadeOut(delay);
                $('.level-50').fadeOut(delay);
                $('.level-30').fadeOut(delay);
                $('.level-10').fadeOut(delay);

                break;
        }
    }
}
