/* ---------------------------------------------------------------------
Global JavaScript & jQuery

Target Browsers: All
Authors: Ken Sykora
------------------------------------------------------------------------ */

var NERD = NERD || {};

$(function () {

    var container = $('#rl_specials_video_player');
    if ((typeof jwplayer != "undefined") && container.length) {

        var player = jwplayer('video_player');
        if (!player) return;

        var options = {
                flashplayer: '/assets/scripts/mediaplayer-5.7-licensed/player.swf',
                file: container.data('video'),
                image: container.data('thumb'),
                skin: '/assets/scripts/mediaplayer-5.7-licensed/glow.zip',
                controlbar: {
                    idlehide: true
                }
            };

        if (container.data('width')) options.width = container.data('width');
        if (container.data('height')) options.height = container.data('height');

        player.setup(options);
    }
});



/* ---------------------------------------------------------------------
AutoReplace
Author: Nerdery Boilerplate

Mimics HTML5 placeholder behavior

Additionally, adds and removes 'placeholder-text' class, used as a styling
hook for when placeholder text is visible or not visible

Additionally, prevents forms from being
submitted if the default text remains in input field - which we may
or may not want to leave in place, depending on usage in site
------------------------------------------------------------------------ */
NERD.AutoReplace = {
    $fields: undefined,

    init: function () {
        var $fields = $('[placeholder]');

        if ($fields.length !== 0) {
            var self = this;
            self.$fields = $fields.addClass('placeholder-text');
            self.bind();
        }
    },

    bind: function () {
        var self = this;

        self.$fields.each(
            function () {
                var me = $(this);
                var defaultText = me.attr('placeholder');
                me.attr('placeholder', '').val(defaultText);

                me.focus(
                    function () {
                        if (me.val() === defaultText) {
                            me.val('').removeClass('placeholder-text');
                        }
                    }
                );

                me.blur(
                    function () {
                        if (me.val() === '') {
                            me.val(defaultText).addClass('placeholder-text');
                        }
                    }
                );

//                me.parents('form').submit(
//                    function () {
//                        if (me.val() === defaultText || me.val() === "") {
//                            return false;
//                        }
//                    }
//                );
            }
        );
    }
};



function updateShadowLocations() {
    $("#body_shadow_left").css({
        'height': $(".body_shadow_content").height(),
        'left': $(".body_shadow_content").offset().left - 33 + 'px',
        'width' : '33px'
    });
    $("#body_shadow_right").css({
        'height': $(".body_shadow_content").height(),
        'left': $(".body_shadow_content").offset().left + $(".body_shadow_content").width() + 'px',
        'width' : ($(".body_shadow_content").offset().left < 33) ? $(".body_shadow_content").offset().left-1 + 'px' : '33px'
    });
}
